From pdenno at common-lisp.net Sat Oct 1 19:03:17 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 1 Oct 2005 21:03:17 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: public_html/cgtk-primer.html public_html/faq.html Message-ID: <20051001190317.942CF8855D@common-lisp.net> Update of /project/cells-gtk/cvsroot/public_html In directory common-lisp.net:/tmp/cvs-serv12344 Modified Files: cgtk-primer.html faq.html Log Message: a few more FAQ answers. Date: Sat Oct 1 21:03:16 2005 Author: pdenno Index: public_html/cgtk-primer.html diff -u public_html/cgtk-primer.html:1.3 public_html/cgtk-primer.html:1.4 --- public_html/cgtk-primer.html:1.3 Mon Mar 7 00:37:35 2005 +++ public_html/cgtk-primer.html Sat Oct 1 21:03:15 2005 @@ -147,7 +147,7 @@ propagation to formula-valued cell dependencies has to happen before any output SETF (and why Cells has a mechanism to defer SETFs of inputs). -

Family: Referencing slots throughout the defmodel hierarchy.

+

Family: Referencing cells throughout the defmodel hierarchy.

The defmodel macro defines a part-subpart relationship among components of the interface. The relationship is made by the @@ -160,7 +160,7 @@
Peter Denno
-Last modified: Sun Mar 6 18:36:16 EST 2005 +Last modified: Sun Mar 6 18:43:09 EST 2005 Index: public_html/faq.html diff -u public_html/faq.html:1.7 public_html/faq.html:1.8 --- public_html/faq.html:1.7 Mon Mar 7 00:38:22 2005 +++ public_html/faq.html Sat Oct 1 21:03:15 2005 @@ -36,18 +36,22 @@
  • What GTK Widgets are implemented in cells-gtk?
  • Do I have to use cells?
  • What is libcellsgtk.so about?
  • +
  • What is the difference between using c-in and c? in a slot's :initform?
  • Why do I need :owner here? It looks like c? would bind self to the mk-whatever enclosing the c?
  • How do I do xyz?
  • -
  • Q: What does this error mean? : "cellular slot FOO of #<BAR 21B555A4> cannot be setf - unless initialized as inputp.
  • -
  • Q: Changing a cell value causes dependencies to fire, but what is considered a change?
  • +
  • What does this error mean? : "cellular slot FOO of #<BAR 21B555A4> cannot be setf + unless initialized as inputp."
  • +
  • Changing a cell value causes dependencies to fire, but what is considered a change?
  • +
  • Can I keep a window around for redisplay after using the window border + 'delete' button to delete it?
  • +

    Q: What is Cells-GTK?

    -A: Cells-GTK is a GTK binding to lisp written by Vasilis Margioulas. It uses the +A: Cells-GTK is a lisp binding of GTK written by Vasilis Margioulas. It uses the Cells system, a sort of constraint propagation system written by kenny tilton. (see "What is Cells?"). As of this writing Cells-GTK runs under Allegro, Lispworks and CMUCL. A separate distribution (not quite up to date with the former) runs @@ -56,7 +60,39 @@ Q: What is Cells?

    A: From the Cells website: "Cells is a mature, stable extension to CLOS that allows you to create classes, the instances of which have slots whose values are determined by - a formula." + a formula." +

    Here is an explanation from the viewpoint of a Cells-GTK programmer: + Cells provides Cells-GTK with two essential features: (1) a part-subpart relationship, + as is typically found in GUIs -- it allows the user to express that, e.g., this window contains these + buttons and subwindows etc.; (2) the expression of a program's state machine, as viewed from the + context of the user's interaction through the GUI. This last point is especially noteworthy, and + needs more explanation. If you are at all familiar with developing moderately complex software + that is operated through a GUI, then you have probably learned this: Keeping what is presented through + the GUI in-sync with what the user is allowed to do, and in-sync with the computational state of + the program is often tedious, complicated work. Specifically, there are the issues of what menu items + ought to be made sensitive when, what items should be presented in list, what text should appear in + entries, etc. Cells-GTK helps with these tasks by providing an abstraction over the details; each + of the tasks just listed can be controlled by (a) rules that specify the value of attributes of graphic + features in the part-subpart declaration (that declaration is called 'defpart' in cells-gtk); + and, (b) rules that specify the value of CLOS slots. [Footnote, In the details of the implementation, + (a) is just a usage of (b). But it helps to think of the ability to set a GUI feature with a + rule as something different than setting the value of slot with a rule.]. An example of (a) + is setting the :sensitive feature of a GTK menu item. For this, I might use the rule (c? (user-file *my-gui*)). + Here user-file is the accessor of some object *my-gui*. :sensitive is a boolean, so whenever there + is a non-nil value in the slot user-file, the menu item is sensitive. That doesn't look a whole lot + different than giving :sensitive whatever value (user-file *my-gui*) evaluates to. + The difference is that in Cells-GTK, the Cells codes watches over 'instrumented' slots such as user-file + and automatically updates those attributes of a Cell-GTK object (such as a menu item's :sensitive feature) + that are governed by a Cells rule. Thus, I don't have to explicitly update the value of + :sensitive -- it happens automatically. +

    + So what is this talk about 'expression of a program's state machine?' Well, the idea is that + in a GUI operated by Cells-GTK, transition into a state is governed by cells-rules on + GUI features and cells-instrumented slots. E.g. when the user loads a file, (c? (user-file *my-gui*)) + becomes true and the program enters the state where some menu item that wasn't sensitive now is + -- the cells rules are rules on the arcs out of states. Is that stretching it too much? + I don't know, it makes sense to me. +

    See also:

    + Q: Why is the Clisp distribution separate?

    A: Because as of this writing, UFFI, which Cells-GTK uses, doesn't support CLISP.

    @@ -82,7 +119,22 @@

    Q: What GTK Widgets are implemented in cells-gtk?

    A: [hmm, Better to ask what isn't. Most of the useful widgets are implemented, but - among those, many non-essential methods are not.] + among those, many non-essential methods are not.] A quick look at the +widget gallery. These +are not implemented: +

    +

    There are quite a few other widgets not listed in the Gallery that aren't implmented. +But BTW, it isn't difficult to implement most of these. If you need one, implemented +it and drop us a note! +

    Q: Do I have to use cells?

    A: Probably not. But the demo uses them, so it might still be (despite the lack of @@ -143,6 +195,14 @@ the libgtk.so you are using.

    + +

    +Q: What is the difference between using c-in and c? in a slot's :initform ?

    +A: The usual semantics of :initform do not apply when :initform is given a c? rule. +Instead of just setting the value at initialization, when c? is used, the value of the slot is +checked and updated using the rule throughout program execution. +

    + Q: Why do I need :owner here? It looks like c? would bind self to the mk-whatever enclosing the c?

    @@ -179,7 +239,7 @@

    -A: If you macroexpand callback, you will see that ith binds self again, this time to the +A: If you macroexpand callback, you will see that it binds self again, this time to the menu-item.
    (owner self) gets you into the :kids hierarchy.

    Q: How do I do xyz?

    @@ -200,6 +260,25 @@ dependencies to fire again (in order to save substantial useless recalculations). So how is "equivalence" defined? EQL is used unless overridden by providing a function of two arguments to :unchanged-if in the slot definition of the defmodel. + + +

    +Q: Can I keep a window around for redisplay after using the window border + 'delete' button to delete it?

    + A:Yes. Do something like this: + + +

    +(defmodel pseudo-dialog (window)
    +  ()
    +  (:default-initargs
    +   :on-delete-event (callback (w e d) (gtk-widget-hide-on-delete w))))
    +
    + +

    +... and, of course, store the widget somewhere so you can later display it with + (gtk-widget-show-all (widget-id my-pseudo-dialog)). +


    Peter Denno
    From pdenno at common-lisp.net Sun Oct 2 19:04:40 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sun, 2 Oct 2005 21:04:40 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: public_html/faq.html Message-ID: <20051002190440.2BF7F880E6@common-lisp.net> Update of /project/cells-gtk/cvsroot/public_html In directory common-lisp.net:/tmp/cvs-serv15592 Modified Files: faq.html Log Message: reflects some suggestions from kt Date: Sun Oct 2 21:04:39 2005 Author: pdenno Index: public_html/faq.html diff -u public_html/faq.html:1.8 public_html/faq.html:1.9 --- public_html/faq.html:1.8 Sat Oct 1 21:03:15 2005 +++ public_html/faq.html Sun Oct 2 21:04:39 2005 @@ -36,7 +36,8 @@
  • What GTK Widgets are implemented in cells-gtk?
  • Do I have to use cells?
  • What is libcellsgtk.so about?
  • -
  • What is the difference between using c-in and c? in a slot's :initform?
  • +
  • What is the difference between using c-input (AKA c-in) and c-formula (AKA c?) in a + slot's :initform?
  • Why do I need :owner here? It looks like c? would bind self to the mk-whatever enclosing the c?
  • How do I do xyz?
  • @@ -61,46 +62,55 @@ A: From the Cells website: "Cells is a mature, stable extension to CLOS that allows you to create classes, the instances of which have slots whose values are determined by a formula." -

    Here is an explanation from the viewpoint of a Cells-GTK programmer: +

    +From Bill Clementson's Blog: + "...Cells allows you to define classes whose slots can be dynamically + (and automatically) updated and for which standard 'observers' can be defined that react to changes + in those slots." +

    + Here is an explanation from the viewpoint of a Cells-GTK programmer: Cells provides Cells-GTK with two essential features: (1) a part-subpart relationship, as is typically found in GUIs -- it allows the user to express that, e.g., this window contains these buttons and subwindows etc.; (2) the expression of a program's state machine, as viewed from the context of the user's interaction through the GUI. This last point is especially noteworthy, and needs more explanation. If you are at all familiar with developing moderately complex software - that is operated through a GUI, then you have probably learned this: Keeping what is presented through + that is operated through a GUI, then you have probably learned this lesson: Keeping what is presented through the GUI in-sync with what the user is allowed to do, and in-sync with the computational state of the program is often tedious, complicated work. Specifically, there are the issues of what menu items ought to be made sensitive when, what items should be presented in list, what text should appear in entries, etc. Cells-GTK helps with these tasks by providing an abstraction over the details; each - of the tasks just listed can be controlled by (a) rules that specify the value of attributes of graphic - features in the part-subpart declaration (that declaration is called 'defpart' in cells-gtk); - and, (b) rules that specify the value of CLOS slots. [Footnote, In the details of the implementation, + of the tasks just listed can be controlled by (a) formula that specify the value of attributes of graphic + features in the part-subpart declaration (that declaration is called 'defpart' in cells-gtk); + and, (b) formula that specify the value of CLOS slots. [Footnote, In the details of the implementation, (a) is just a usage of (b). But it helps to think of the ability to set a GUI feature with a - rule as something different than setting the value of slot with a rule.]. An example of (a) - is setting the :sensitive feature of a GTK menu item. For this, I might use the rule (c? (user-file *my-gui*)). + formula as something different than setting the value of slot with a formula.]. (c) 'observers' (to + use Bill Clementson's term) that watch over GUI features and react to changes. +

    + An example of (a) + is setting the :sensitive feature of a GTK menu item. For this, I might use the formula (c? (user-file *my-gui*)). Here user-file is the accessor of some object *my-gui*. :sensitive is a boolean, so whenever there is a non-nil value in the slot user-file, the menu item is sensitive. That doesn't look a whole lot different than giving :sensitive whatever value (user-file *my-gui*) evaluates to. The difference is that in Cells-GTK, the Cells codes watches over 'instrumented' slots such as user-file and automatically updates those attributes of a Cell-GTK object (such as a menu item's :sensitive feature) - that are governed by a Cells rule. Thus, I don't have to explicitly update the value of + that are governed by a Cells formula. Thus, I don't have to explicitly update the value of :sensitive -- it happens automatically.

    So what is this talk about 'expression of a program's state machine?' Well, the idea is that - in a GUI operated by Cells-GTK, transition into a state is governed by cells-rules on + in a GUI operated by Cells-GTK, transition into a state is governed by cells-formulae on GUI features and cells-instrumented slots. E.g. when the user loads a file, (c? (user-file *my-gui*)) becomes true and the program enters the state where some menu item that wasn't sensitive now is - -- the cells rules are rules on the arcs out of states. Is that stretching it too much? + -- the cells formulae are formulae on the arcs out of states. Is that stretching it too much? I don't know, it makes sense to me.

    See also:

    @@ -197,10 +207,16 @@

    -Q: What is the difference between using c-in and c? in a slot's :initform ?

    -A: The usual semantics of :initform do not apply when :initform is given a c? rule. -Instead of just setting the value at initialization, when c? is used, the value of the slot is -checked and updated using the rule throughout program execution. +Q: What is the difference between using c-input (AKA c-in) and c-formula (AKA c?) in a slot's +:initform ?

    +A:The two define different kinds of cells:
    +A c-input cell is a cell whose value may be set through explicit declarative code, such as by using setf on the slot. +
    +A c-formula cell is a cell whose value is obtained through evaluation of a formula. +
    +Note that the usual semantics of :initform do not apply when :initform is given by c-formula. +Instead of just setting the value at initialization, the c-formula (an arbitrary lisp form) +specifies the dynamic relationship between the slot's value and other aspects of the program state.

    Q: Why do I need :owner here? It looks like c? would bind self to the mk-whatever From pdenno at common-lisp.net Mon Oct 3 14:43:48 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Mon, 3 Oct 2005 16:43:48 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: public_html/faq.html Message-ID: <20051003144348.9C9D888576@common-lisp.net> Update of /project/cells-gtk/cvsroot/public_html In directory common-lisp.net:/tmp/cvs-serv869 Modified Files: faq.html Log Message: minor Date: Mon Oct 3 16:43:47 2005 Author: pdenno Index: public_html/faq.html diff -u public_html/faq.html:1.9 public_html/faq.html:1.10 --- public_html/faq.html:1.9 Sun Oct 2 21:04:39 2005 +++ public_html/faq.html Mon Oct 3 16:43:46 2005 @@ -210,7 +210,7 @@ Q: What is the difference between using c-input (AKA c-in) and c-formula (AKA c?) in a slot's :initform ?

    A:The two define different kinds of cells:
    -A c-input cell is a cell whose value may be set through explicit declarative code, such as by using setf on the slot. +A c-input cell is a cell whose value may be set through explicit procedural code, using setf on the slot.
    A c-formula cell is a cell whose value is obtained through evaluation of a formula.
    From pdenno at common-lisp.net Sat Oct 8 14:26:43 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:26:43 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/cells-gtk/drawing.lisp Message-ID: <20051008142643.26BB388562@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/cells-gtk In directory common-lisp.net:/tmp/cvs-serv14010/root/cells-gtk Added Files: drawing.lisp Log Message: New file implementing DrawingArea -- needs work, but getting there. Date: Sat Oct 8 16:26:42 2005 Author: pdenno From pdenno at common-lisp.net Sat Oct 8 14:28:50 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:28:50 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/cells-gtk/menus.lisp Message-ID: <20051008142850.99FC088562@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/cells-gtk In directory common-lisp.net:/tmp/cvs-serv14035/root/cells-gtk Modified Files: menus.lisp Log Message: New method cgtk-set-active-item-by-path (on combo-box) Date: Sat Oct 8 16:28:49 2005 Author: pdenno Index: root/cells-gtk/menus.lisp diff -u root/cells-gtk/menus.lisp:1.10 root/cells-gtk/menus.lisp:1.11 --- root/cells-gtk/menus.lisp:1.10 Sun May 29 23:09:40 2005 +++ root/cells-gtk/menus.lisp Sat Oct 8 16:28:49 2005 @@ -18,6 +18,8 @@ (in-package :cgtk) +(export '(cgtk-set-active-item-by-path)) + (defmacro with-tree-iters (vars &body body) `(let (,@(loop for var in vars collect `(,var (gtk-adds-tree-iter-new)))) (unwind-protect @@ -40,7 +42,7 @@ :new-tail '-text :on-changed (callback (widget event data) - (trc nil "combo-box onchanged cb" widget event data (id self)) + ;(trc nil "combo-box onchanged cb" widget event data (id self)) (if (items self) ;; flat model (:items specified) (let ((pos (gtk-combo-box-get-active (id self)))) @@ -74,12 +76,19 @@ for index from 0 do (gtk-tree-store-set-kids (id (tree-model self)) root c-null index '(:string :string) pfunc (children-fn self))) - ;; Spec says iter must correspond to a path of depth one. Hence no point in set-active-iter. - ;; init should just be the index of the depth one item you want displayed. - (bwhen (item-index (init self)) - (gtk-combo-box-set-active (id self) item-index) - (let ((item (item-from-path (children-fn self) (roots self) (list item-index)))) - (setf (md-value self) item)))))) + ;; Spec says iter must correspond to a path of depth one. But then there would be no point + ;; in set-active-iter. Well, the spec seems to be wrong (or poorly worded). + (bwhen (path (init self)) + (cgtk-set-active-item-by-path self path))))) + +(defmethod cgtk-set-active-item-by-path ((self combo-box) path) + "Sets the value of the tree-model type combo-box to the item at the path. Path is a list of integers." + (bwhen (tree (tree-model self)) + (with-tree-iters (it) + (when (gtk-tree-model-get-iter-from-string (id tree) it (format nil "~{~A~^:~}" path)) + (gtk-combo-box-set-active-iter (id self) it) + ;(break "in cgtk setting path = ~A" path) + (setf (md-value self) (item-from-path (children-fn self) (roots self) path)))))) (def-c-output items ((self combo-box)) (when old-value @@ -88,11 +97,11 @@ (when new-value (dolist (item (items self)) (gtk-combo-box-append-text (id self) (funcall (print-fn self) item))) - (when (init self) - (let ((index (position (init self) (items self)))) - (when index - (gtk-combo-box-set-active (id self) index) - (setf (md-value self) (init self))))))) + (bif (index (position (init self) (items self))) + (progn (gtk-combo-box-set-active (id self) index) + (setf (md-value self) (init self))) + (progn (gtk-combo-box-set-active (id self) 0) + (setf (md-value self) (car (items self))))))) ;;; ============= Toolbar/Toolbutton ============================ (def-object tooltips () @@ -295,3 +304,4 @@ (def-widget tearoff-menu-item (menu-item) () () ()) +(export '(gtk-combo-box-set-active)) \ No newline at end of file From pdenno at common-lisp.net Sat Oct 8 14:29:29 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:29:29 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/cells-gtk/cells-gtk.asd Message-ID: <20051008142929.37CD78853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/cells-gtk In directory common-lisp.net:/tmp/cvs-serv14066/root/cells-gtk Modified Files: cells-gtk.asd Log Message: Added load of drawing.lisp Date: Sat Oct 8 16:29:28 2005 Author: pdenno Index: root/cells-gtk/cells-gtk.asd diff -u root/cells-gtk/cells-gtk.asd:1.4 root/cells-gtk/cells-gtk.asd:1.5 --- root/cells-gtk/cells-gtk.asd:1.4 Sun May 29 23:03:43 2005 +++ root/cells-gtk/cells-gtk.asd Sat Oct 8 16:29:28 2005 @@ -11,6 +11,7 @@ (:file "widgets" :depends-on ("conditions")) (:file "layout" :depends-on ("widgets")) (:file "display" :depends-on ("widgets")) + (:file "drawing" :depends-on ("widgets")) (:file "buttons" :depends-on ("widgets")) (:file "entry" :depends-on ("widgets")) (:file "tree-view" :depends-on ("widgets")) From pdenno at common-lisp.net Sat Oct 8 14:31:25 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:31:25 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/cells-gtk/textview.lisp Message-ID: <20051008143125.59F848853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/cells-gtk In directory common-lisp.net:/tmp/cvs-serv15045/root/cells-gtk Modified Files: textview.lisp Log Message: Added textview-scroll-to-position (but see discussion in FAQ about connecting a stream to textview for a better approach). Date: Sat Oct 8 16:31:24 2005 Author: pdenno Index: root/cells-gtk/textview.lisp diff -u root/cells-gtk/textview.lisp:1.4 root/cells-gtk/textview.lisp:1.5 --- root/cells-gtk/textview.lisp:1.4 Sun Mar 6 17:58:51 2005 +++ root/cells-gtk/textview.lisp Sat Oct 8 16:31:24 2005 @@ -130,6 +130,16 @@ (gtk-text-buffer-get-iter-at-offset buf e-iter end) (gtk-text-buffer-delete buf s-iter e-iter)))) +;;; This isn't working perfectly. Might be better to use gtk-text-view-scroll-mark-onscreen +;;; I do just that in one of my applications, but since it requires a mark, I didn't write +;;; an exported function for it. +(defun text-view-scroll-to-position (textview pos) + (let* ((view (id textview)) + (buf (gtk-text-view-get-buffer view))) + (with-text-iters (s-iter) + (gtk-text-buffer-get-iter-at-offset buf s-iter pos) + (gtk-text-view-scroll-to-iter view s-iter 0.0 nil 0.0 0.0)))) + ;;; The next two can be used to check and clear the the modified flag. ;;; The event is registered when you use :on-modified-changed on a text-buffer. ;;; The def-c-output text ((text-buffer)) clears the flag so as to distinguish @@ -143,7 +153,10 @@ (eval-when (:compile-toplevel :load-toplevel :execute) (export '(def-populate-adds populate-adds with-text-iters text-buffer-get-text - text-buffer-delete-text text-buffer-insert-text text-buffer-modified-p))) + text-buffer-delete-text text-buffer-insert-text text-buffer-modified-p + text-view-scroll-to-position gtk-text-buffer-get-iter-at-offset + gtk-text-buffer-create-mark gtk-text-view-set-wrap-mode gtk-text-view-set-editable + gtk-text-buffer-move-mark gtk-text-view-scroll-mark-onscreen))) From pdenno at common-lisp.net Sat Oct 8 14:33:19 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:33:19 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/cells-gtk/widgets.lisp Message-ID: <20051008143319.CC4408853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/cells-gtk In directory common-lisp.net:/tmp/cvs-serv15074/root/cells-gtk Modified Files: widgets.lisp Log Message: Export method widget-id. Same as cgtk::id, (but without the potential package problems of exporting that). Date: Sat Oct 8 16:33:19 2005 Author: pdenno Index: root/cells-gtk/widgets.lisp diff -u root/cells-gtk/widgets.lisp:1.13 root/cells-gtk/widgets.lisp:1.14 --- root/cells-gtk/widgets.lisp:1.13 Sun May 29 23:15:51 2005 +++ root/cells-gtk/widgets.lisp Sat Oct 8 16:33:19 2005 @@ -298,12 +298,10 @@ (not-to-be old-value)) (when new-value (gtk-widget-set-popup (id self) (id (to-be new-value))))) - + (def-c-output visible ((self widget)) - (when *gtk-debug* - (trc nil "VISIBLE" (md-name self) new-value) (force-output)) - (if new-value - (gtk-widget-show (id self)) + (if new-value + (gtk-widget-show (id self)) (gtk-widget-hide (id self)))) (def-c-output tooltip ((self widget)) @@ -353,7 +351,7 @@ (def-c-output title ((self window)) (when new-value - (gtk-window-set-title (id self) new-value))) + (gtk-window-set-title (id self) new-value))) (def-c-output icon ((self window)) (when new-value @@ -394,5 +392,9 @@ (when new-value (gtk-container-add (id self) (id (first new-value)))) #+clisp (call-next-method)) + +(defun widget-id (widget) + (id widget)) + (eval-when (compile load eval) - (export '(callback callback-if timeout-add focus))) + (export '(callback callback-if timeout-add focus widget-id))) From pdenno at common-lisp.net Sat Oct 8 14:34:16 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:34:16 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/gtk-ffi/Makefile Message-ID: <20051008143416.03AE08853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/gtk-ffi In directory common-lisp.net:/tmp/cvs-serv15105/root/gtk-ffi Modified Files: Makefile Log Message: Better comments. Date: Sat Oct 8 16:34:15 2005 Author: pdenno Index: root/gtk-ffi/Makefile diff -u root/gtk-ffi/Makefile:1.1 root/gtk-ffi/Makefile:1.2 --- root/gtk-ffi/Makefile:1.1 Sat Feb 26 23:17:52 2005 +++ root/gtk-ffi/Makefile Sat Oct 8 16:34:15 2005 @@ -1,21 +1,21 @@ # # Purpose: build libcellsgtk.so # -# You don't need libCellsGtk.so to run the demo, but you will to add an entry -# text widget to a dialog, or add menu items using populate-popup (see GTK textview). +# You don't need libCellsGtk.so to run the demo, but you will to +# - add an entry text widget to a dialog +# - add menu items using populate-popup (see GTK textview). +# - Use a TreeModel (hierarchical arrangment of items) in a ComboBox. +# # As of this writing, those are the only situations where it is needed. See FAQ.txt # for more of the motivation. # # In order to compile the library you will need to have on hand the C header files # corresponding the libgtk.so you are using. # See http://developer.gnome.org/doc/API/2.4/gtk/gtk-building.html -# On linux, it is a matter of installing 4 or 5 .rpms and typing "make", -# or at least that is how it worked for me. +# On linux, it is a matter of installing 4 or 5 .rpms and typing "make" +# Or at least that is how it worked for me. # # Once built, place the library in the directory containing libgtk. -# #-mswindows ../load.lisp will push :libcellsgtk onto *features* -# #+mswindows you will have to push :libcellsgtk onto *features* yourself. -# all: gcc -c gtk-adds.c `pkg-config --cflags --libs gtk+-2.0` From pdenno at common-lisp.net Sat Oct 8 14:43:38 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:43:38 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/gtk-ffi/gtk-adds.c Message-ID: <20051008144338.61B878853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/gtk-ffi In directory common-lisp.net:/tmp/cvs-serv15143/root/gtk-ffi Modified Files: gtk-adds.c Log Message: Added stuff for DrawingArea and GdkColor Date: Sat Oct 8 16:43:37 2005 Author: pdenno Index: root/gtk-ffi/gtk-adds.c diff -u root/gtk-ffi/gtk-adds.c:1.3 root/gtk-ffi/gtk-adds.c:1.4 --- root/gtk-ffi/gtk-adds.c:1.3 Sun May 29 23:16:56 2005 +++ root/gtk-ffi/gtk-adds.c Sat Oct 8 16:43:37 2005 @@ -39,4 +39,36 @@ return gtk_tree_iter_copy(&example); } +int gtk_adds_widget_mapped_p (GtkWidget *wid) +{ + return ((GTK_WIDGET_FLAGS (wid) & GTK_MAPPED) != 0) ? 1 : 0; +} + +int gtk_adds_widget_visible_p (GtkWidget *wid) +{ + return ((GTK_WIDGET_FLAGS (wid) & GTK_VISIBLE) != 0) ? 1 : 0; +} + +GdkWindow * +gtk_adds_widget_window (GtkWidget *wid) +{ + return wid->window; +} + +GdkColor * +gtk_adds_color_new () +{ + return ((GdkColor *)malloc(sizeof(GdkColor))); +} + +void +gtk_adds_color_set_rgb (GdkColor* color, guint r, guint g, guint b) +{ + color->red = r; + color->green = g; + color->blue = b; +} + + + From pdenno at common-lisp.net Sat Oct 8 14:44:41 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:44:41 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/gtk-ffi/gtk-core.lisp Message-ID: <20051008144441.851148853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/gtk-ffi In directory common-lisp.net:/tmp/cvs-serv15166/root/gtk-ffi Modified Files: gtk-core.lisp Log Message: Start of work to get SBCL port working. Unfinished (but it doesn't look too hard!). Date: Sat Oct 8 16:44:41 2005 Author: pdenno Index: root/gtk-ffi/gtk-core.lisp diff -u root/gtk-ffi/gtk-core.lisp:1.3 root/gtk-ffi/gtk-core.lisp:1.4 --- root/gtk-ffi/gtk-core.lisp:1.3 Fri Dec 24 03:04:00 2004 +++ root/gtk-ffi/gtk-core.lisp Sat Oct 8 16:44:40 2005 @@ -72,10 +72,16 @@ (* (alien:struct gtk-ffi::g-value (gtk-ffi::g-type (array (alien:signed 32) 16))))) +#+sbcl +(ffx:def-type g-value-type + (* (sb-alien:struct gtk-ffi::g-value + (gtk-ffi::g-type (array (sb-alien:signed 32) 16))))) + + (defun call-with-g-value (fn) (declare (optimize (speed 3) (safety 0) (space 0))) (let ((gva (ffx:fgn-alloc 'g-value 1 :with-g-value))) - #+cmu (declare (type g-value-type gva)) + #+(or cmu sbcl) (declare (type g-value-type gva)) (unwind-protect (progn (dotimes (n 16) From pdenno at common-lisp.net Sat Oct 8 14:45:40 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:45:40 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/gtk-ffi/gdk-other.lisp Message-ID: <20051008144540.24E6F8853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/gtk-ffi In directory common-lisp.net:/tmp/cvs-serv15723/root/gtk-ffi Added Files: gdk-other.lisp Log Message: New file: Gdk FFI declarations Date: Sat Oct 8 16:45:39 2005 Author: pdenno From pdenno at common-lisp.net Sat Oct 8 14:46:43 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:46:43 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/gtk-ffi/gtk-ffi.asd Message-ID: <20051008144643.D007C8853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/gtk-ffi In directory common-lisp.net:/tmp/cvs-serv16164/root/gtk-ffi Modified Files: gtk-ffi.asd Log Message: Start of work to get SBCL port working. Unfinished (but it doesn't look too hard!). Add load of gdk-other.lisp Date: Sat Oct 8 16:46:43 2005 Author: pdenno Index: root/gtk-ffi/gtk-ffi.asd diff -u root/gtk-ffi/gtk-ffi.asd:1.6 root/gtk-ffi/gtk-ffi.asd:1.7 --- root/gtk-ffi/gtk-ffi.asd:1.6 Sun May 29 23:18:24 2005 +++ root/gtk-ffi/gtk-ffi.asd Sat Oct 8 16:46:42 2005 @@ -13,12 +13,12 @@ #+(or win32 mswindows) (setf *gtk-lib-path* "C:/Program Files/Common Files/GTK/2.0/bin/") ;;; This need not be specified for cmucl (leave as a null string). -#+cmu(setf *gtk-lib-path* "/usr/lib/") -;#+cmu(setf *gtk-lib-path* "/opt/gnome/lib/") ; For my Suse machine +;#+cmu(setf *gtk-lib-path* "/usr/lib/") +#+(OR cmu sbcl)(setf *gtk-lib-path* "/opt/gnome/lib/") ; For my Suse machine ;;; Specify for Lispworks. -#-(or macosx win32 mswindows cmu) (setf *gtk-lib-path* "/usr/lib/") -;#-(or macosx win32 mswindows cmu) (setf *gtk-lib-path* "/opt/gnome/lib/") ; For my Suse machine +;#-(or macosx win32 mswindows cmu) (setf *gtk-lib-path* "/usr/lib/") +#-(or macosx win32 mswindows cmu) (setf *gtk-lib-path* "/opt/gnome/lib/") ; For my Suse machine ;;; Step 2 -- If you built libcellsgtk.so, uncomment the next line. ;(pushnew :libcellsgtk *features*) @@ -30,6 +30,7 @@ ((:file "gtk-ffi") (:file "gtk-core" :depends-on ("gtk-ffi")) (:file "gtk-other" :depends-on ("gtk-ffi")) + (:file "gdk-other" :depends-on ("gtk-ffi")) (:file "gtk-button" :depends-on ("gtk-ffi")) (:file "gtk-tool" :depends-on ("gtk-ffi")) (:file "gtk-menu" :depends-on ("gtk-ffi")) From pdenno at common-lisp.net Sat Oct 8 14:48:03 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:48:03 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/gtk-ffi/gtk-ffi.lisp Message-ID: <20051008144803.ED0A28853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/gtk-ffi In directory common-lisp.net:/tmp/cvs-serv16190/root/gtk-ffi Modified Files: gtk-ffi.lisp Log Message: Added motion and expose event structures (useful for DrawingArea). A few defines for SBCL port. Date: Sat Oct 8 16:48:03 2005 Author: pdenno Index: root/gtk-ffi/gtk-ffi.lisp diff -u root/gtk-ffi/gtk-ffi.lisp:1.12 root/gtk-ffi/gtk-ffi.lisp:1.13 --- root/gtk-ffi/gtk-ffi.lisp:1.12 Sun May 29 23:19:58 2005 +++ root/gtk-ffi/gtk-ffi.lisp Sat Oct 8 16:48:03 2005 @@ -17,8 +17,7 @@ |# -(defpackage :gtk-ffi (:use :lisp #-clisp :ffx - #+clisp :ffi #-clisp :uffi)) +(defpackage :gtk-ffi (:use #-sbcl :lisp #+sbcl :cl :utils-kt #-clisp :ffx #+clisp :ffi #-clisp :uffi)) (in-package :gtk-ffi) @@ -80,7 +79,7 @@ (loadit "libgdk-x11-2.0.so" :gdk) (loadit "libgtk-x11-2.0.so" :gtk) #+libcellsgtk(loadit "libcellsgtk.so" :cgtk)))) - #+cmu(load-gtk-libs) + #+(or cmu sbcl)(load-gtk-libs) (defun ffi-to-uffi-type (clisp-type) #+clisp clisp-type #-clisp (if (consp clisp-type) @@ -256,13 +255,39 @@ (hardware-keycode uint16) (group uint8)) +(def-c-struct gdk-event-expose + (type int) + (window c-pointer) + (send-event uint8) + ;; This is probably wrong. alignment issues... + (area-x int) + (area-y int) + (area-width int) + (area-height int) + (region c-pointer) + (count int)) + +(def-c-struct gdk-event-motion + (type int) + (window c-pointer) + (send-event uint8) + (time int) + (x double-float) + (y double-float) + (axes c-pointer) + (state int) + (is-hint uint16) + (device c-pointer) + (x-root double-float) + (y-root double-float)) + (defun event-type (event) (ecase event (-1 :nothing) (0 :delete) (1 :destroy) (2 :expose) - (3 :notify) + (3 :notify) ; that is, pointer motion notify (4 :button_press) (5 :2button_press) (6 :3button_press) From pdenno at common-lisp.net Sat Oct 8 14:49:38 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:49:38 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/gtk-ffi/gtk-other.lisp Message-ID: <20051008144938.E492E8853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/gtk-ffi In directory common-lisp.net:/tmp/cvs-serv16210/root/gtk-ffi Modified Files: gtk-other.lisp Log Message: More gtk and gdk FF declarations. Date: Sat Oct 8 16:49:38 2005 Author: pdenno Index: root/gtk-ffi/gtk-other.lisp diff -u root/gtk-ffi/gtk-other.lisp:1.7 root/gtk-ffi/gtk-other.lisp:1.8 --- root/gtk-ffi/gtk-other.lisp:1.7 Tue Jun 28 18:56:23 2005 +++ root/gtk-ffi/gtk-other.lisp Sat Oct 8 16:49:38 2005 @@ -65,6 +65,9 @@ (spacing int)) c-pointer nil nil) + (gtk-drawing-area-new () + c-pointer) + ;;table (gtk-table-new ((rows uint) (columns uint) @@ -313,6 +316,8 @@ (gtk-widget-show ((widget c-pointer))) (gtk-widget-show-all ((widget c-pointer))) (gtk-widget-hide ((widget c-pointer))) + (gtk-widget-hide-all ((widget c-pointer))) + (gtk-widget-hide-on-delete ((widget c-pointer))) (gtk-widget-destroy ((widget c-pointer))) (gtk-widget-set-sensitive ((widget c-pointer) (sensitive boolean)) @@ -568,6 +573,21 @@ c-pointer) (gtk-text-view-set-buffer ((text-view c-pointer) (buffer c-pointer))) + (gtk-text-view-get-buffer ((text-view c-pointer)) + c-pointer) + (gtk-text-view-set-wrap-mode ((text-view c-pointer) + (wrap-mode int))) + (gtk-text-view-set-editable ((text-view c-pointer) + (setting boolean))) + (gtk-text-view-scroll-to-iter ((text-view c-pointer) + (iter c-pointer) + (within-margin double-float) + (use-align boolean) + (xalign double-float) + (yalign double-float)) + boolean) + (gtk-text-view-scroll-mark-onscreen ((text-view c-pointer) + (mark c-pointer))) ;;text-buffer (gtk-text-buffer-new ((table c-pointer)) @@ -629,6 +649,9 @@ boolean) (gtk-text-buffer-set-modified ((buffer c-pointer) (setting boolean))) + (gtk-text-buffer-move-mark ((buffer c-pointer) + (mark c-pointer) + (where c-pointer))) ;;text-iter (gtk-text-iter-free ((iter c-pointer))) @@ -688,7 +711,11 @@ (gtk-check-version ((required-major uint) (required-minor uint) (required-micro uint)) - c-string)) + c-string) + (gtk-widget-create-pango-layout ((widget c-pointer) + (text c-string)) + c-pointer)) + #+libcellsgtk (def-gtk-lib-functions :cgtk @@ -705,7 +732,16 @@ (gtk-adds-widget-visible-p ((widget c-pointer)) int) (gtk-adds-widget-mapped-p ((widget c-pointer)) - int)) + int) + (gtk-adds-widget-window ((widget c-pointer)) + c-pointer) + (gtk-adds-color-new () + c-pointer) + (gtk-adds-color-set-rgb ((gdkcolor c-pointer) + (red uint) + (green uint) + (blue uint)))) + #-libcellsgtk (defmacro you-need-libcellsgtk (&body names) @@ -723,7 +759,10 @@ gtk-adds-text-iter-new gtk-adds-tree-iter-new gtk-adds-widget-mapped-p - gtk-adds-widget-visible-p)) + gtk-adds-widget-visible-p + gtk-adds-widget-window + gtk-adds-color-new + gtk-adds-color-set-rgb)) From pdenno at common-lisp.net Sat Oct 8 14:50:27 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 16:50:27 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: root/gtk-ffi/gtk-utilities.lisp Message-ID: <20051008145027.2E9708853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/root/gtk-ffi In directory common-lisp.net:/tmp/cvs-serv16236/root/gtk-ffi Modified Files: gtk-utilities.lisp Log Message: SBCL porting. Date: Sat Oct 8 16:50:26 2005 Author: pdenno Index: root/gtk-ffi/gtk-utilities.lisp diff -u root/gtk-ffi/gtk-utilities.lisp:1.14 root/gtk-ffi/gtk-utilities.lisp:1.15 --- root/gtk-ffi/gtk-utilities.lisp:1.14 Sun May 29 23:24:10 2005 +++ root/gtk-ffi/gtk-utilities.lisp Sat Oct 8 16:50:26 2005 @@ -193,7 +193,7 @@ column-no = num-columns. (See gtk-tree-store-set-kids)." (with-foreign-object (item :pointer-void) (gtk-tree-model-get model iter column-no item -1) - #-(or lispworks cmu allegro) (cast item (as-gtk-type-name cell-type)) + #-(or lispworks cmu sbcl allegro) (cast item (as-gtk-type-name cell-type)) #+allegro (case cell-type (:string (uffi:convert-from-cstring (uffi:deref-pointer item :cstring))) @@ -205,7 +205,11 @@ #+cmu (case cell-type (:string (alien:cast (alien:deref item) c-call:c-string)) - (t (alien:deref item))))) + (t (alien:deref item))) + #+sbcl + (case cell-type + (:string (sb-alien:cast (sb-alien:deref item) sb-c-call:c-string)) + (t (sb-alien:deref item))))) (defun parse-cell-attrib (attribs) (loop for (attrib val) on attribs by #'cddr collect @@ -228,6 +232,19 @@ (:float single-float) (:double double-float))) +#+sbcl +(sb-alien:def-alien-type all-types + (sb-alien:struct c-struct + (:string (* t)) + (:icon (* t)) + (:boolean boolean) + (:int integer) + (:long sb-c-call:long) + (:date single-float) + (:float single-float) + (:double double-float))) + + #-cmu (progn (defun alloc-col-type-buffer (col-type) @@ -358,6 +375,37 @@ (apply #'gtk-object-set-property cell-renderer property)))) (when (eql col-type :string) (g-free (alien:slot struct :string)))))) + +#+sbcl +(defun gtk-tree-view-render-cell (col col-type cell-attrib-f) + #'(lambda (tree-column cell-renderer model iter data) + (sb-alien:with-alien ((struct all-types)) + (gtk-tree-model-get model iter col + (sb-alien:addr (sb-alien:slot struct col-type)) + -1) + (let ((item-value (if (or (eql col-type :string) (eql col-type :icon)) + (get-gtk-string (sb-alien:slot struct col-type)) + (sb-alien:slot struct col-type)))) + (with-gtk-string (str (format nil "~a" + (if (eql col-type :date) + (multiple-value-bind (sec min hour day month year) + (decode-universal-time (truncate item-value)) + (format nil "~2,'0D/~2,'0D/~D ~2,'0D:~2,'0D:~2,'0D" + day month year hour min sec)) + item-value))) + (ukt:trc nil "gtv-render-cell (callback11)> rendering value" + col col-type item-value) + (apply #'gtk-object-set-property cell-renderer + (case col-type + (:boolean (list "active" 'boolean item-value)) + (:icon (list "stock-id" 'c-string (string-downcase (format nil "gtk-~a" item-value)))) + (t (list "text" 'c-pointer str))))) + (when cell-attrib-f + (loop for property in (parse-cell-attrib (funcall cell-attrib-f item-value)) do + (apply #'gtk-object-set-property cell-renderer property)))) + (when (eql col-type :string) + (g-free (sb-alien:slot struct :string)))))) + #+clisp From pdenno at common-lisp.net Sat Oct 8 15:03:01 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 17:03:01 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: public_html/cgtk-primer.html Message-ID: <20051008150301.2E5C38853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/public_html In directory common-lisp.net:/tmp/cvs-serv17280/public_html Modified Files: cgtk-primer.html Log Message: Messy, some errors, but I'm going to use it anyway. Date: Sat Oct 8 17:03:00 2005 Author: pdenno Index: public_html/cgtk-primer.html diff -u public_html/cgtk-primer.html:1.4 public_html/cgtk-primer.html:1.5 --- public_html/cgtk-primer.html:1.4 Sat Oct 1 21:03:15 2005 +++ public_html/cgtk-primer.html Sat Oct 8 17:03:00 2005 @@ -25,18 +25,101 @@

    Introduction

    -Here we will discuss the most important parts of the cell-gtk GTK binding, and how -cells can be used in defining cells-gtk GUIs. As of this writing, we have begun -the discussion of cells. This minimal introduction might be sufficient to get you -started. We'll see. +[This is Work In Progress currently. My apologies.]

    -

    Cells slots

    +Here we will discuss the most important parts of the cells-gtk GTK binding, and how +cells can be used in defining cells-gtk GUIs. This minimal introduction might be +sufficient to get you started. We'll see. + +

    Cells, Cell slots, and all that...

    + +The example from Bill Clementson's Blog +is a nice starting point. Read it and come back here.

    + +...Welcome back. Perhaps you came back with the impression that Cells is a way to manage +the relationship among the values in the slots of a CLOS object. That would be good. +You might also imagine that if the slots describe the state of some real world object like a motor, +you could use Cells to control the object -- to orchestrate how all its parts work together +toward some goal. That also would be good. Now, if that object were a GTK-based GUI... no +I'm getting ahead of myself. Let's look at the basic idea of Cells, it is similar to +constraint satisfaction. +That is, you have values, and rules that govern the relationships among the values, +and whenever the network is pushed out of a consistent state (i.e. whenever the rules +no longer hold), the objective is to get it back to a consistent one by updating some values. +In Bill's example, status fuelpump and temp are cells -- slots in +a motor CLOS object whose values are managed by the cells constraint network. +The constraint network itself might be depicted as this: +

    +[graph] +

    +In this graph the nodes are values and edges have rules attached. The collection of edges +into a node together with the rule are the cell. + The green nodes +are values controlled by cells and the empty nodes are regular 'unmanaged' values +(such as you get by reading the value from regular CLOS slot). +

    +Cells such as temp, which have no edges leading into them, are called 'c-input cells'. +A c-input cell gives you an opportunity to push the network out of a consistent state, +so that it must find another consistent state (raise the temperature, force the motor +and fuel pump to stop). They are one way the network interacts with its environment. +(Thinking about GUI: Part of the 'environment' of your Cells-GTK application are lisp objects, +the state of which you'd like to communicate to the user.) +

    +Another way that the cells network can interact with its environment is through +c-output (or c-echo) methods. These are 'observers' of a cell that are invoked when the +value of that cell is modified. They are sort of the converse of the c-input: modify +a c-input value and the network reacts; when the network reacts, it can modify +values outside the network with a c-output. +

    +So what about the values inside the network -- the nodes with edges pointing into them? +Observing those with c-output methods and using c-input and setf to modify them would be +bad form. If you program that way, you aren't doing anything that couldn't be done without Cells. +Drop Cells-GTK and go back to programming in C-based GTK or Java. The result will be that you +hand back to the programmer the burden of keeping track of every change to the GUI. +C-input cells are intended (small apps like Bill's aside) to be used to 'instrument' +(or "put sensors on") your code. If you have a legacy code that you are building a Cells-GTK GUI for, .... +

    + + + +

    + + +

    +Now reiterating the ideas above: + +

    -The cells defmodel provides for the declaration of several kinds of "cell slots," +Cells provides for the declaration of several kinds of "cell slots," but for the purpose of talking about cells-gtk, we can limit the discussion to -just a few kinds. However, first we should point out that by specifying +just the c-input and c-formula cells. How do you recognize what kind of cell slot +is being used? Well, first we should point out that by specifying :cell nil in a defmodel slot definition, the slot defined is an ordinary CLOS -slot and none of the following pertains. +slot. The rest are specified using :initform on the slot. The following defmodel +defines a c-input cell, a c-formula cell and a regular CLOS slot. + +
    +(defmodel example ()
    +  ((control-me :initform (c-input (some-form-foo)) :accessor control-me)
    +   (im-computed :initform (c-formula (some-form-bar)) :accessor im-computed)
    +   (im-clos :cell nil :initform nil)))
    +
    @@ -62,7 +145,6 @@
     
  • A cell slot is specified by :cell t (advanced options aside) or by omitting the :cell option, since in defmodel, the default is t.
  • -
  • An invariant cell slot is a cell slot that is initialized by an ordinary lisp form, either by an :initarg in make-instance, an :initform in the slot definition, or :default-initargs in the defmodel. The value of an @@ -87,6 +169,10 @@ are consistent at some point after the values of some of them are changed.
  • +

    Cells and Cells-GTK

    + +

    Good Cells Technique

    + This all may seem abstract, but it has practical value in the design of your GUI. For example, I might set the :sensitivity of a button, the :text in a label or :fraction of a progress-bar based on @@ -150,8 +236,32 @@

    Family: Referencing cells throughout the defmodel hierarchy.

    The defmodel macro defines a part-subpart relationship -among components of the interface. The relationship is made by the -:kids :initarg or :default-initargs, of the parent model. +among components of the interface. The relationship is made by the :kids initarg. +:kids is given a list of children. In a cells-gtk defmodel some kids might be GTKContainer +(vbox, hbox, etc) -- things that in the GTK world, have kids of their own. It may be a natural coding practice +in that case for the defmodel to define a fairly deep ancestory hierarchy, laying out the arrangement of widgets. +(You're free to break things up wherever seem reasonable for your application). It might look like this: + +
    +(defmodel my-app (gtk-app)
    +  ()
    +  (:default-initargs
    +  :md-name :my-app
    +  :kids 
    +  (list 
    +    (mk-vbox
    +      :kids
    +        (list 
    +           (mk-hbox
    +	      :kids
    +                 (list (mk-combo-box :md-name :my-combo) ...))
    +           (mk-hbox
    +	       :kids
    +                (list (make-instance 'my-subpart))))))))
    +
    +The point of the Family methods is to allow things a different places in this hierarchy (e.g. :my-combo +to reference :my-app). +

    More will be written about this soon. From pdenno at common-lisp.net Sat Oct 8 15:03:30 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 17:03:30 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: public_html/faq.html Message-ID: <20051008150330.8F8E78853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/public_html In directory common-lisp.net:/tmp/cvs-serv17298/public_html Modified Files: faq.html Log Message: New questions and answers. Date: Sat Oct 8 17:03:29 2005 Author: pdenno Index: public_html/faq.html diff -u public_html/faq.html:1.10 public_html/faq.html:1.11 --- public_html/faq.html:1.10 Mon Oct 3 16:43:46 2005 +++ public_html/faq.html Sat Oct 8 17:03:29 2005 @@ -36,6 +36,7 @@

  • What GTK Widgets are implemented in cells-gtk?
  • Do I have to use cells?
  • What is libcellsgtk.so about?
  • +
  • What is in libcellsgtk.so?
  • What is the difference between using c-input (AKA c-in) and c-formula (AKA c?) in a slot's :initform?
  • Why do I need :owner here? It looks like c? would bind self to the mk-whatever @@ -46,7 +47,7 @@
  • Changing a cell value causes dependencies to fire, but what is considered a change?
  • Can I keep a window around for redisplay after using the window border 'delete' button to delete it?
  • - +
  • Can I use streams with a TextView widget?
  • @@ -205,17 +206,30 @@ the libgtk.so you are using.

    +Q: What is in libcellsgtk.so?

    +A:For details look at the source gtk-ffi/gtk-adds.c, but generally: +

      +
    • Get a dialog's vbox (so that you can add children to it).
    • +
    • Get the popup menu of a textview
    • +
    • Allocate text iters and tree iters
    • +
    • Check whether or not a widget is mapped and visible
    • +
    • Get the window of a widget (useful for DrawingArea).
    • +
    • Allocate GdkColor objects
    • +
    • Set the RGB values of GdkColor objects.
    • +

    Q: What is the difference between using c-input (AKA c-in) and c-formula (AKA c?) in a slot's :initform ?

    A:The two define different kinds of cells:
    A c-input cell is a cell whose value may be set through explicit procedural code, using setf on the slot. +Note: When the cell is referenced by other cells in a cells constraint network, setf-ing the cell +causes the values of other cells to be recomputed.
    A c-formula cell is a cell whose value is obtained through evaluation of a formula.
    Note that the usual semantics of :initform do not apply when :initform is given by c-formula. -Instead of just setting the value at initialization, the c-formula (an arbitrary lisp form) +Instead of just setting the value at initialization, the c-formula (generated from the supplied lisp form) specifies the dynamic relationship between the slot's value and other aspects of the program state.

    @@ -266,8 +280,9 @@

    Q: What does this error mean? : "cellular slot FOO of #<BAR 21B555A4> cannot be setf unless initialized as inputp."

    - A: This error is signalled because you tried to setf an invariant slot. - 'inputp' refers to c-in which should have been used to initialize the slot. + A:This error is signalled because you tried to setf a c-formula slot. + 'inputp' refers to c-input (declaration of an input cell) which should have been used + to initialize the slot. Read the cells-gtk primer for more information.

    @@ -295,12 +310,66 @@ ... and, of course, store the widget somewhere so you can later display it with (gtk-widget-show-all (widget-id my-pseudo-dialog)). +

    + +Q:Can I use streams with a TextView widget?

    + A:Sure. Do something like this: + +

    +(defmethod initialize-instance :after ((self your-gtk-app) &key)
    +  (let ((message-textview [wherever it is]))
    +    (setf *message-stream* 
    +	(make-instance 'pane-stream 
    +		       :buffer (buffer message-textview)
    +		       :view message-textview))))
    +
    +(defclass pane-stream (stream:fundamental-character-output-stream)
    +  ((view :initarg :view)
    +   (buffer :initarg :buffer)
    +   (mark :initarg :mark)
    +   (offset :initform 0 :accessor offset)))
    +
    +(defmethod initialize-instance :after ((self pane-stream) &key)
    +  (with-slots (buffer mark view) self
    +     (let ((b (widget-id buffer))
    +	   (v (widget-id view)))
    +       (with-text-iters (iter) 
    +          (cgtk:gtk-text-buffer-get-iter-at-offset b iter 0)
    +	  (setf mark (cgtk:gtk-text-buffer-create-mark b "visibility" iter t)))
    +       (cgtk:gtk-text-view-set-wrap-mode v 1)  ; optional, of course. 
    +       (cgtk:gtk-text-view-set-editable v nil)))) ; also optional. 
    +
    +; Some lisps might not need this one. Some might need other methods.
    +(defmethod stream:stream-line-column ((s pane-stream)) nil)
    +
    +(defmethod stream:stream-write-char ((s pane-stream) (c character))
    +  (with-slots (view buffer offset mark) s
    +     (cgtk:text-buffer-insert-text buffer offset (string c))
    +     (incf offset)
    +     (let ((buf (widget-id buffer)))
    +       (with-text-iters (iter) 
    +         (cgtk:gtk-text-buffer-get-iter-at-offset buf iter offset)
    +	 (cgtk:gtk-text-buffer-move-mark buf mark iter)
    +	 (cgtk:gtk-text-view-scroll-mark-onscreen (cgtk::id view) mark )))))
    +
    +(defmethod stream:stream-write-string ((s pane-stream) string &optional start end)
    +  (with-slots (view buffer offset mark) s
    +     (cgtk:text-buffer-insert-text buffer offset string)
    +     (incf offset (length string))
    +     (let ((buf (widget-id buffer)))
    +       (with-text-iters (iter) 
    +         (cgtk:gtk-text-buffer-get-iter-at-offset buf iter offset)
    +	 (cgtk:gtk-text-buffer-move-mark buf mark iter)
    +	 (cgtk:gtk-text-view-scroll-mark-onscreen (widget-id view) mark)))))
    +
    +
    +
    Peter Denno
    -Last modified: Sun Mar 6 18:32:15 EST 2005 +Last modified: 2005-10-08 From pdenno at common-lisp.net Sat Oct 8 15:03:55 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 17:03:55 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: public_html/index.html Message-ID: <20051008150355.5702A8853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/public_html In directory common-lisp.net:/tmp/cvs-serv17313/public_html Modified Files: index.html Log Message: New news. Date: Sat Oct 8 17:03:54 2005 Author: pdenno Index: public_html/index.html diff -u public_html/index.html:1.8 public_html/index.html:1.9 --- public_html/index.html:1.8 Mon May 30 16:12:05 2005 +++ public_html/index.html Sat Oct 8 17:03:54 2005 @@ -74,6 +74,10 @@

    News

      +
    • 2005-10-08Some additional discussion in FAQ. So + Work to implement DrawingArea is underway in CVS HEAD. + HEAD *should* be OK. New tarballs will be created when it is complete.
    • +
    • 2005-05-29 Allows hierarchical arrangement of items in ComboBox. (requires libcellsgtk)
    • From pdenno at common-lisp.net Sat Oct 8 15:06:37 2005 From: pdenno at common-lisp.net (Peter Denno) Date: Sat, 8 Oct 2005 17:06:37 +0200 (CEST) Subject: [cells-gtk-cvs] CVS update: public_html/index.html Message-ID: <20051008150637.9A6228853E@common-lisp.net> Update of /project/cells-gtk/cvsroot/public_html In directory common-lisp.net:/tmp/cvs-serv17351/public_html Modified Files: index.html Log Message: Trivial Date: Sat Oct 8 17:06:37 2005 Author: pdenno Index: public_html/index.html diff -u public_html/index.html:1.9 public_html/index.html:1.10 --- public_html/index.html:1.9 Sat Oct 8 17:03:54 2005 +++ public_html/index.html Sat Oct 8 17:06:36 2005 @@ -74,7 +74,7 @@

      News

        -
      • 2005-10-08Some additional discussion in FAQ. So +
      • 2005-10-08 Some additional discussion in FAQ. So Work to implement DrawingArea is underway in CVS HEAD. HEAD *should* be OK. New tarballs will be created when it is complete.
      • @@ -137,7 +137,7 @@
        Peter Denno
        -Last modified: Fri Mar 4 20:00:10 EST 2005 +Last modified: 2005-10-08