git.fiddlerwoaroof.com
Browse code

Seems to work, abandoned (?)

fiddlerwoaroof authored on 23/05/2016 23:01:39
Showing 1 changed files
... ...
@@ -34,25 +34,33 @@
34 34
 (ql:quickload :cl-fad)
35 35
 (ql:quickload :x.let-star)
36 36
 
37
-(defpackage :gtk-tutorial
37
+(defpackage :notes-app
38 38
   (:use :gtk :gdk :gdk-pixbuf :gobject
39 39
         :glib :gio :pango :cairo :common-lisp
40 40
         :cl-fad :x.let-star)
41 41
   (:shadowing-import-from x.let-star let*)
42 42
   (:export main))
43 43
 
44
-(in-package :gtk-tutorial)
44
+(in-package :notes-app)
45 45
 
46 46
 ;(macroexpand-1 '(on (clicked button) (__)
47 47
 ;                    (declare (ignore __))
48 48
 ;                    (format t "Button 1 was pressed")))
49 49
 
50 50
 (defmacro on ((sig target) bind &body body)
51
-  "Bind a signal handler: note that this intentionally shadows whatever the 'bind' argument is"
51
+  "Bind a signal handler: note that this intentionally shadows whatever
52
+   the 'bind' argument is"
52 53
   `(g-signal-connect ,target ,(string-downcase (symbol-name sig))
53 54
                      (lambda ,bind
54 55
                        ,@body)))
55 56
 
57
+
58
+
59
+(defmacro thread-signal ((sig target) bind callback)
60
+  "Bind a signal handler: note that this intentionally shadows whatever
61
+   the 'bind' argument is"
62
+  `(g-signal-connect ,target ,(string-downcase (symbol-name sig)) ,callback))
63
+
56 64
 (defmacro mainloop (fname winvar title width height &body body)
57 65
   `(defun ,fname ()
58 66
      (within-main-loop
... ...
@@ -68,7 +76,8 @@
68 76
 
69 77
          ,@body
70 78
 
71
-         (gtk-widget-show-all ,winvar)))))
79
+         (gtk-widget-show-all ,winvar)))
80
+     (join-gtk-main)))
72 81
 
73 82
 ;(macroexpand-1
74 83
 ;  (quote
... ...
@@ -94,7 +103,35 @@
94 103
        (gtk-paned-add1 ,paned-sym ,child1)
95 104
        (gtk-paned-add2 ,paned-sym ,child2)
96 105
        ,paned-sym)))
97
-
106
+(labels ((process-child (child box-sym)
107
+           (if (listp child)
108
+             (let* ((_initializers
109
+                      (if (< 2 (length child)) (cddr child) ()))
110
+                    (initializers (apply #'append _initializers))
111
+                    (widget (second child)))
112
+               (ecase  (first child)
113
+                 (:start `(gtk-box-pack-start ,box-sym
114
+                                              ,widget
115
+                                              ,@initializers))
116
+
117
+                 (:end   `(gtk-box-pack-end   ,box-sym
118
+                                              ,widget
119
+                                              ,@initializers)))))))
120
+
121
+  (defmacro declare-box (initializers &body children)
122
+    (let ((box-sym (gensym)))
123
+      `(let ((,box-sym (make-instance 'gtk-box ,@initializers)))
124
+         ,@(loop for child in children collect (process-child child box-sym))
125
+         ,box-sym))))
126
+
127
+(defmacro declare-toolbar (initializers &body children)
128
+  (let ((toolbar-sym (gensym)))
129
+    `(let ((,toolbar-sym (gtk-toolbar-new)))
130
+       ,@(loop for button in children collect
131
+               `(gtk-toolbar-insert ,toolbar-sym
132
+                                    (make-instance 'gtk-tool-button ,@button)
133
+                                    -1))
134
+       ,toolbar-sym)))
98 135
 
99 136
 (defun make-list-view (display-list)
100 137
   (let ((store (make-instance 'gtk-list-store :column-types '("gchararray")))
... ...
@@ -119,40 +156,59 @@
119 156
     (gtk-text-buffer-set-text buffer text)
120 157
     (values buffer text-view)))
121 158
 
122
-(defvar *note-directory* "/home/edwlan/Dropbox/Notes/")
159
+(defun get-list-at-path (list-model path)
160
+  (let* ((iter (gtk-tree-model-get-iter list-model path)))
161
+    (selected (gtk-tree-model-get-value list-model iter 0))) )
162
+
163
+(defvar *note-dir* "/home/edwlan/Dropbox/Notes/")
123 164
 (mainloop main window "test" 200 200
124
-  (let* (((:mval list-model list-view) (make-list-view (cl-fad:list-directory *note-directory*)))
165
+  (let* (((:mval list-model list-view) (make-list-view
166
+                                         (cl-fad:list-directory *note-dir*)))
125 167
          ((:mval text-buffer text-view) (make-text-view "")))
126 168
 
169
+
127 170
     (on (row-activated list-view) (tree-view path column)
128
-      (let* ((iter (gtk-tree-model-get-iter list-model path))
129
-             (selected (gtk-tree-model-get-value list-model iter 0))
171
+      (let* ((selected (get-list-at-path list-model path))
130 172
              (file-contents
131
-               (with-open-file (fd (merge-pathnames-as-file *note-directory* selected))
173
+               (with-open-file (fd (merge-pathnames-as-file *note-dir* selected))
132 174
                  (let ((seq (make-string (file-length fd))))
133 175
                    (read-sequence seq fd)
134 176
                    seq))))
135
-        (format t "~a ~a ~a~%" tree-view path column)
136
-        (format t "~a~%" iter)
137
-        (format t "~a~%" selected)
138
-        
139 177
         (gtk-text-buffer-set-text text-buffer file-contents)))
140 178
 
141 179
     (gtk-container-add window
142 180
                        (declare-paned-widget (:orientation :vertical)
143
-                                             (declare-scroll-window (:height-request 400) list-view)
144
-                                             (declare-scroll-window (:wrap-mode :word) text-view)))))
181
+                                             (declare-box
182
+                                               (:orientation :vertical)
183
+                                               (:end
184
+                                                 (declare-box
185
+                                                   (:orientation :horizontal)
186
+                                                   (:start (gtk-entry-new) (:fill t))
187
+                                                   (:end
188
+                                                     (make-instance 'gtk-button 
189
+                                                                    :use-stock t
190
+                                                                    :label "gtk-add")
191
+                                                     (:expand nil)))
192
+                                                 (:expand nil))
193
+                                               (:start
194
+                                                 (declare-scroll-window
195
+                                                       (:height-request 400)
196
+                                                       list-view)
197
+                                                 (:fill t)))
198
+                                             (declare-scroll-window
199
+                                               (:wrap-mode :word)
200
+                                               text-view)))))
145 201
 
146 202
 ;(main)
147 203
 
148
-(labels 
204
+(labels
149 205
   ((slot-function (descriptor)
150 206
      (ecase descriptor
151 207
        (:start 'gtk-box-pack-start)
152 208
        (:end   'gtk-box-pack-end)))
153 209
    (proc-slot (box from-object slot)
154 210
      (if (equal (first slot) 'QUOTE)
155
-       `(gtk-box-pack-start ,box (slot-value ,from-object ,slot))   
211
+       `(gtk-box-pack-start ,box (slot-value ,from-object ,slot))
156 212
        (ecase (length slot)
157 213
          (1 `(gtk-box-pack-start ,box (slot-value ,from-object ,(first slot))))
158 214
          (2 `(,(slot-function (second slot)) ,box (slot-value ,from-object ,(first slot))))))))