5 Commits 9745755ba7 ... 63e2f804cb

Author SHA1 Message Date
  jordyn 63e2f804cb photogal's data has evolved! 2 years ago
  jordyn c1150f3119 where am i ? 2 years ago
  jordyn 9e81b38f7c unit tests!? 2 years ago
  jordyn e5259b8544 space space space space space space space space 2 years ago
  jordyn df623c68f9 docs 2 years ago
2 changed files with 118 additions and 26 deletions
  1. 66 26
      photogal.el
  2. 52 0
      test-photogal.el

+ 66 - 26
photogal.el

@@ -1,13 +1,14 @@
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;;;;;;;;;;;;;;;;;;;;    PHOTOGAL    ;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;    PHOTOGAL    ;;;;;;;;;;;;;;;;;;;;;`;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; v1.0 ;;;;;;
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*;;;
 ;;                                                         ;;
 ;;  author: jordyn                          ,   -    *     ;;
 ;;  authored: spokane valley, summer '22      .          ` ;;
-;;                                                 ^ ~     ';
-;;    PHOTO                *    ,    '  . `   `  *      ,  ;;
-;;    , Grouper         '    `     .   ,* -   .            ;;
+;;                                           *     ^ ~     ';
+;;    PHOTO                *    ,    '  .     `  *      ,  ;;
+;;    , Grouper         '    `     .    * -   .            ;;
 ;; .      And        ,    ^ '  .  '  .   `  `      '       ;;
 ;;    `     Labeler    '   ,     * '      *                ;;
 ;;  ,     .   ,     `        '        .                    ;;
@@ -68,21 +69,29 @@
   (photogal--set-name (photogal--lookup-photo photo-filepath) name))
 
 ;; //             internal           \\ ;;
-(defun photogal--get-filepath (photo)
-  (car photo))
 (defun photogal--lookup-photo (photo-filepath)
   (assoc photo-filepath *photogal/operating-table*))
+
+(defun photogal--get-filepath (photo)
+  (plist-get photo 'filepath))
 (defun photogal--get-tags (photo)
   "What are all the tags for this file?"
-  (caadr photo))
+  (plist-get photo 'tags))
 (defun photogal--set-tags (photo tags)
-  (setcar (cadr photo)
-	  tags))
+  (plist-put photo 'tags
+	     tags))
+(defun photogal--get-folders (photo)
+  "What are all the folders for this file?"
+  (plist-get photo 'folders))
+(defun photogal--set-folders (photo folders)
+  (plist-put photo 'folders
+	     folders))
 (defun photogal--get-name (photo)
-  (cadadr photo))
+  (plist-get photo 'name))
 (defun photogal--set-name (photo name)
-  (setcar (cdadr photo)
-	  name))
+  (plist-put photo 'name
+	     name))
+
 ;; \\             internal           // ;;
 
 (defun photogal-advance-photo ()
@@ -115,11 +124,15 @@
 
 ;;;;  --  ----  --  -  INITIALIZATION   -  --  ----  --  ;;;;
 
+(defun photogal-make-photo (filepath)
+  `(filepath ,filepath
+	     tags ()
+	     name nil))
+
 (defun photogal-init-operating-table ()
   (setq *photogal/operating-table*
 	(mapcar (lambda (photo)
-		  ;; '(old-file-path (tags optional-name))
-		  (list photo (list '() nil)))
+		  (photogal-make-photo photo))
 		*photogal/all-photos*)))
 
 (defun photogal-generate-tag-commands ()
@@ -143,7 +156,8 @@ for all tags defined -- one function per tag."
     (if (or tag-code-too-long tag-code-in-use)
 	(progn (message "tag code must be a single character and can't be already in use")
 	       (call-interactively 'photogal-add-tag))
-      (photogal--add-tag new-tag new-tag-code))))
+      (photogal--add-tag new-tag new-tag-code)
+      (photogal-refresh-buffer))))
 
 (defun photogal-delete-tag (tag-code)
   "Remove a tag from the library."
@@ -159,8 +173,7 @@ for all tags defined -- one function per tag."
     (customize-save-variable
      'photogal/tags
      (cons (cons new-tag-code escaped-str-tag) photogal/tags)))
-  (photogal-generate-tag-commands)
-  (photogal-refresh-buffer))
+  (photogal-generate-tag-commands))
 
 (defun photogal-tag-code-in-use (tag-code)
   (seq-contains-p
@@ -181,13 +194,6 @@ for all tags defined -- one function per tag."
     (photogal-set-tags-for-file file
 		       (seq-sort #'string< (seq-uniq (cons tag tags))))))
 
-(defun photogal-name-the-file (name)
-  (interactive "sWhat do u want to name this file? ")
-  (photogal-set-name-for-file
-   (photogal-current-file)
-   (string-replace " " "-"  name))
-  (photogal-refresh-buffer))
-
 (defun photogal-rm-tag-from-file (file tag)
   "Dissociate tag from file."
   (defun tags-without-tag (tags tag)
@@ -205,6 +211,16 @@ for all tags defined -- one function per tag."
   (let ((tags (photogal-get-tags-for-file file)))
     (seq-contains-p tags tag)))
 
+
+;;;;  --  ----  --  -     FILE NAME     -  --  ----  --  ;;;;
+
+(defun photogal-name-the-file (name)
+  (interactive "sWhat do u want to name this file? ")
+  (photogal-set-name-for-file
+   (photogal-current-file)
+   (string-replace " " "-"  name))
+  (photogal-refresh-buffer))
+
 ;;;;  --  ----  --  -      FILE OPS     -  --  ----  --  ;;;;
 
 (defun photogal-all-photos (directory)
@@ -218,11 +234,12 @@ for all tags defined -- one function per tag."
 
 ;;;;  --  ----  --  -       U I         -  --  ----  --  ;;;;
 (defun photogal-init (photo-file-path &optional show-filepath)
-  "Set everything up in the buffer."
+    "Set everything up in the buffer."
   (let ((buf (get-buffer-create "photogal")))
     (with-current-buffer buf
       (photogal-mode)
       (erase-buffer)
+      (photogal-index-tracker)
       (insert "\n")
       (insert " ")
       (insert-image
@@ -274,7 +291,27 @@ for all tags defined -- one function per tag."
   (interactive)
   (photogal-refresh-buffer t))
 
+(defun photogal-index-tracker ()
+  ;; this is a little expensive, running photogal-all-photos
+  ;; on every paint, but i'd like to have the file count
+  ;; be very accurate.
+  (let ((current-index
+	 (+ 1 (seq-position
+	       (photogal-all-photos *photogal/photos-origin-directory*)
+	       (photogal-current-file))))
+	(total-photos
+	 (length (photogal-all-photos *photogal/photos-origin-directory*))))
+    (insert "ur lookin at photo ")
+    (photogal--insert-print-color current-index "red")
+    (insert " of ")
+    (photogal--insert-print-color total-photos "red")))
+
+
 ;;;;  --  ----  --  - LO-LEVEL DISPLAY  -  --  ----  --  ;;;;
+;; this stuff paints the words on the screen, changing     ;;
+;; color, etc, pprinting stuff at a pretty granular and    ;;
+;; tediously technical level.                              ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defun photogal-insert-tags-to-buffer (tags)
   "Pretty print the tags with their toggle key."
@@ -319,6 +356,8 @@ for all tags defined -- one function per tag."
     (put-text-property beg (point) 'font-lock-face `(:foreground ,color))))
 
 ;;;;  --  ----  --  -     META SHIT     -  --  ----  --  ;;;;
+;; this is the coolest damn thing here.                    ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defmacro photogal-generate-tagger (name)
   "Generate function to toggle a tag which is itself on the current file.
@@ -399,6 +438,7 @@ the current file."
   (define-key photogal-mode-map (kbd "G") 'photogal-refresh-buffer)
   (define-key photogal-mode-map (kbd "RET") 'photogal-next-file)
   (define-key photogal-mode-map (kbd "<right>") 'photogal-next-file)
+  (define-key photogal-mode-map (kbd "SPC") 'photogal-next-file)
   (define-key photogal-mode-map (kbd "P") 'photogal-prev-file)
   (define-key photogal-mode-map (kbd "<left>") 'photogal-prev-file)
   (define-key photogal-mode-map (kbd "A") 'photogal-add-tag)

+ 52 - 0
test-photogal.el

@@ -0,0 +1,52 @@
+
+
+(load "/Users/jwd/code/photo-gal/photogal.el")
+
+(setq photogaltest-example-operating-table
+      '(("/Photos/comp.png"
+	 (nil nil))
+	("/Photos/e06de5-5501,240622--_art_computer_good_meme_photography_politics_portrait_reaction-photo_screenshot_selfie_.png"
+	 (nil nil))
+	("/Photos/e99e1a-5501,240622-como-_art_cityscape_computer_family_meme_politics_reaction-photo_screenshot_selfie_.jpg"
+	 (nil nil))
+	("/Photos/rsf.png"
+	 (nil nil))))
+
+(ert-deftest file-properties-test ()
+
+  (let
+      ((*photogal/operating-table*
+	photogaltest-example-operating-table))
+
+    (should (eq (photogal-get-tags-for-file "/Photos/comp.png")
+		'()))
+    (should   (eq (photogal-get-name-for-file "/Photos/comp.png")
+		  nil))
+
+    ;; ADD THE TAG TO THE SYSTEM
+    (photogal--add-tag "on" "o")
+
+    ;; TOGGLE THE FLAG ON FOR A PHOTO
+    (photogal-for-file-toggle-tag "/Photos/comp.png" "on")   
+    (should (equal (photogal-get-tags-for-file "/Photos/comp.png")
+		   '("on")))
+
+    ;; TOGGLE IT BACK OFF
+    (photogal-for-file-toggle-tag "/Photos/comp.png" "on")
+    (should (eq (photogal-get-tags-for-file "/Photos/comp.png")
+		'()))))
+
+
+
+(ert-deftest folder-sorting-test ()
+
+  (let
+      ((*photogal/operating-table*
+	photogaltest-example-operating-table))
+
+    (should (eq (photogal-get-folder-for-file "/Photos/comp.png")
+		""))
+
+    ))
+
+