[rep-gtk: 10/12] Added simple GtkUIManager example from Foundations of GTK+ Development ported to rep-gtk



commit 6996d142e8f2fe9c11836df03b346ff311d755e8
Author: Juergen Hoetzel <juergen archlinux org>
Date:   Sun Aug 30 17:55:35 2009 +0200

    Added simple GtkUIManager example from Foundations of GTK+ Development ported to rep-gtk

 examples/uimanager/menu.ui      |   22 ++++++++++++++
 examples/uimanager/toolbar.ui   |   15 +++++++++
 examples/uimanager/uimanager.jl |   61 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 98 insertions(+), 0 deletions(-)
---
diff --git a/examples/uimanager/menu.ui b/examples/uimanager/menu.ui
new file mode 100644
index 0000000..63cf64b
--- /dev/null
+++ b/examples/uimanager/menu.ui
@@ -0,0 +1,22 @@
+<ui>
+  <menubar name="MenuBar">
+    <menu name="FileMenu" action="File">
+      <menuitem name="FileOpen" action="Open"/>
+      <menuitem name="FileSave" action="Save"/>
+      <separator/>
+      <menuitem name="FileQuit" action="Quit"/>
+    </menu>
+    <menu name="EditMenu" action="Edit">
+      <menuitem name="EditCut" action="Cut"/>
+      <menuitem name="EditCopy" action="Copy"/>
+      <menuitem name="EditPaste" action="Paste"/>
+      <separator/>
+      <menuitem name="EditSelectAll" action="SelectAll"/>
+      <menuitem name="EditDeselect" action="Deselect"/>
+    </menu>
+    <menu name="HelpMenu" action="Help">
+      <menuitem name="HelpContents" action="Contents"/>
+      <menuitem name="HelpAbout" action="About"/>
+    </menu>
+  </menubar>
+</ui>
diff --git a/examples/uimanager/toolbar.ui b/examples/uimanager/toolbar.ui
new file mode 100644
index 0000000..37dbf6c
--- /dev/null
+++ b/examples/uimanager/toolbar.ui
@@ -0,0 +1,15 @@
+<ui>
+  <toolbar name="Toolbar">
+    <toolitem name="FileOpen" action="Open"/>
+    <toolitem name="FileSave" action="Save"/>
+    <separator/>
+    <toolitem name="EditCut" action="Cut"/>
+    <toolitem name="EditCopy" action="Copy"/>
+    <toolitem name="EditPaste" action="Paste"/>
+    <separator/>
+    <toolitem name="EditSelectAll" action="SelectAll"/>
+    <separator/>
+    <toolitem name="HelpContents" action="Contents"/>
+    <toolitem name="HelpAbout" action="About"/>
+  </toolbar>
+</ui>
diff --git a/examples/uimanager/uimanager.jl b/examples/uimanager/uimanager.jl
new file mode 100644
index 0000000..3140e28
--- /dev/null
+++ b/examples/uimanager/uimanager.jl
@@ -0,0 +1,61 @@
+;; Example from Foundations of GTK+ Development ported to rep-gtk
+
+(require 'gui.gtk-2.gtk)
+
+ 
+(defun main()
+  (setq uimanager (gtk-ui-manager-new))
+  (setq window (gtk-window-new 'toplevel))
+  (gtk-window-set-title window "UI Manager")
+  (gtk-widget-set-size-request window 250 -1)
+
+  ;; Create a new action group and add all of the actions to it.
+  (setq group (gtk-action-group-new "MainActionGroup"))
+  ; FIXME: unimplemented  gtk-action-group-add-actions group entries NUM_ENTRIES, NULL)
+  
+  (let loop ((actions '(("File" "_File" nil nil)
+			("Open" "Open" "Open an existing file" "gtk-open")
+			("Save" "Save" "Save the document to a file" "gtk-save")
+			("Quit" "Quit" "Quit the application" "gtk-quit")
+			("Edit" "_Edit")			
+			("Cut" "Cut" "Cut the selection to the clipboard" "gtk-cut")
+			("Copy" "Copy" "Copy the selection to the clipboard" "gtk-copy")			
+			("Paste" "Paste" "Paste text from the clipboard", "gtk-paste")
+			("SelectAll" "SelectAll" "Select all of the text" "gtk-select-all" )
+			("Deselect" "_Deselect", "Deselect all of the text" nil "<control>d")
+			("Help" "_Help")
+			("Contents"  "Get help on using the application" "gtk-help")
+			( "About" "Acout" "More information about the application"))))
+       (let* ((action-params (car actions))
+	      (accel-param (nth 4 action-params)))
+	 (when action-params
+	   (if accel-param 
+	       (gtk-action-group-add-action-with-accel group (apply gtk-action-new action-params) accel-param)
+	     (gtk-action-group-add-action group (apply gtk-action-new action-params)))
+	   (loop (cdr actions)))))
+    
+
+  (setq uimanager (gtk-ui-manager-new))
+  (gtk-ui-manager-insert-action-group uimanager group 0)
+  
+  (gtk-ui-manager-add-ui-from-file uimanager "menu.ui")
+  (gtk-ui-manager-add-ui-from-file uimanager "toolbar.ui")
+  
+  ; Retrieve the necessary widgets and associate accelerators. 
+  (setq menubar (gtk-ui-manager-get-widget uimanager "/MenuBar"))
+  (setq toolbar (gtk-ui-manager-get-widget uimanager "/Toolbar"))
+
+  (gtk-toolbar-set-style toolbar  'icons)
+  (gtk-window-add-accel-group window (gtk-ui-manager-get-accel-group uimanager))
+  
+  (setq vbox (gtk-vbox-new t 0))
+  (gtk-box-pack-start-defaults vbox menubar)
+  (gtk-box-pack-start-defaults vbox toolbar)
+
+  (gtk-container-add window vbox)
+  (gtk-widget-show-all window)
+  (setq interrupt-mode 'exit)
+  (recursive-edit))
+
+
+(main)
\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]