[dots] Add keyboard accelerators by code. Remove unused edit menu



commit 4f0fae2c3dab5c5be8056339a025a71cc58bb88d
Author: Fernando Herrera <fherrera onirica com>
Date:   Wed Dec 1 22:22:29 2010 +0100

    Add keyboard accelerators by code. Remove unused edit menu

 data/app_window.xml |  158 ++++++++++++++++++--------------------------------
 dots/app_window.py  |   25 ++++++++-
 2 files changed, 81 insertions(+), 102 deletions(-)
---
diff --git a/data/app_window.xml b/data/app_window.xml
index a79b669..551ddd3 100644
--- a/data/app_window.xml
+++ b/data/app_window.xml
@@ -2,24 +2,20 @@
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
-  <object class="GtkMessageDialog" id="table_error_dialog">
+  <object class="GtkMessageDialog" id="notext-dialog">
     <property name="border_width">5</property>
     <property name="type_hint">normal</property>
     <property name="skip_taskbar_hint">True</property>
-    <property name="message_type">error</property>
+    <property name="message_type">warning</property>
     <property name="buttons">ok</property>
-    <property name="text" translatable="yes">The selected table is not valid</property>
-    <property name="secondary_text" translatable="yes">The selected table cannot be used by
-liblouisxml. Please make sure that if you
-are using "include" directive, those files
-are placed in the same directory as the table</property>
-    <property name="secondary_use_markup">True</property>
+    <property name="text" translatable="yes">Cannot extract text from the document.</property>
+    <property name="secondary_text" translatable="yes">Make sure that the document is valid and does contain text</property>
     <child internal-child="vbox">
-      <object class="GtkVBox" id="dialog-vbox3">
+      <object class="GtkVBox" id="dialog-vbox1">
         <property name="visible">True</property>
         <property name="spacing">2</property>
         <child internal-child="action_area">
-          <object class="GtkHButtonBox" id="dialog-action_area3">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
             <property name="visible">True</property>
             <property name="layout_style">end</property>
             <child>
@@ -38,6 +34,39 @@ are placed in the same directory as the table</property>
       </object>
     </child>
   </object>
+  <object class="GtkAction" id="action_help">
+    <property name="stock_id">gtk-help</property>
+    <signal name="activate" handler="_onHelp" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_about">
+    <property name="stock_id">gtk-about</property>
+    <signal name="activate" handler="_onAbout" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_print">
+    <property name="stock_id">gtk-print</property>
+    <property name="sensitive">False</property>
+    <signal name="activate" handler="_onPrint" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_quit">
+    <property name="stock_id">gtk-quit</property>
+    <signal name="activate" handler="_onQuit" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_save_as">
+    <property name="stock_id">gtk-save-as</property>
+    <property name="sensitive">False</property>
+    <signal name="activate" handler="_onSaveAs" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_save">
+    <property name="stock_id">gtk-save</property>
+    <property name="sensitive">False</property>
+    <signal name="activate" handler="_onSave" swapped="no"/>
+  </object>
+  <object class="GtkAction" id="action_open">
+    <property name="tooltip">Open a file</property>
+    <property name="stock_id">gtk-open</property>
+    <signal name="activate" handler="_onOpen" swapped="no"/>
+  </object>
+  <object class="GtkActionGroup" id="file_actions"/>
   <object class="GtkWindow" id="window1">
     <property name="default_width">480</property>
     <property name="default_height">360</property>
@@ -57,7 +86,7 @@ are placed in the same directory as the table</property>
                   <object class="GtkMenu" id="menu1">
                     <property name="visible">True</property>
                     <child>
-                      <object class="GtkImageMenuItem" id="imagemenuitem2">
+                      <object class="GtkImageMenuItem" id="menu_open">
                         <property name="visible">True</property>
                         <property name="related_action">action_open</property>
                         <property name="use_underline">True</property>
@@ -65,7 +94,7 @@ are placed in the same directory as the table</property>
                       </object>
                     </child>
                     <child>
-                      <object class="GtkImageMenuItem" id="imagemenuitem3">
+                      <object class="GtkImageMenuItem" id="menu_save">
                         <property name="visible">True</property>
                         <property name="related_action">action_save</property>
                         <property name="use_underline">True</property>
@@ -73,7 +102,7 @@ are placed in the same directory as the table</property>
                       </object>
                     </child>
                     <child>
-                      <object class="GtkImageMenuItem" id="imagemenuitem4">
+                      <object class="GtkImageMenuItem" id="menu_save_as">
                         <property name="visible">True</property>
                         <property name="related_action">action_save_as</property>
                         <property name="use_underline">True</property>
@@ -81,7 +110,7 @@ are placed in the same directory as the table</property>
                       </object>
                     </child>
                     <child>
-                      <object class="GtkImageMenuItem" id="imagemenuitem11">
+                      <object class="GtkImageMenuItem" id="menu_print">
                         <property name="visible">True</property>
                         <property name="related_action">action_print</property>
                         <property name="use_underline">True</property>
@@ -94,7 +123,7 @@ are placed in the same directory as the table</property>
                       </object>
                     </child>
                     <child>
-                      <object class="GtkImageMenuItem" id="imagemenuitem5">
+                      <object class="GtkImageMenuItem" id="menu_quit">
                         <property name="visible">True</property>
                         <property name="related_action">action_quit</property>
                         <property name="use_underline">True</property>
@@ -106,50 +135,6 @@ are placed in the same directory as the table</property>
               </object>
             </child>
             <child>
-              <object class="GtkMenuItem" id="menuitem2">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">_Edit</property>
-                <property name="use_underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu" id="menu2">
-                    <property name="visible">True</property>
-                    <child>
-                      <object class="GtkImageMenuItem" id="imagemenuitem6">
-                        <property name="label">gtk-cut</property>
-                        <property name="visible">True</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkImageMenuItem" id="imagemenuitem7">
-                        <property name="label">gtk-copy</property>
-                        <property name="visible">True</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkImageMenuItem" id="imagemenuitem8">
-                        <property name="label">gtk-paste</property>
-                        <property name="visible">True</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkImageMenuItem" id="imagemenuitem9">
-                        <property name="label">gtk-delete</property>
-                        <property name="visible">True</property>
-                        <property name="use_underline">True</property>
-                        <property name="use_stock">True</property>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-            <child>
               <object class="GtkMenuItem" id="menuitem3">
                 <property name="visible">True</property>
                 <property name="label" translatable="yes">_View</property>
@@ -212,7 +197,7 @@ are placed in the same directory as the table</property>
                       </object>
                     </child>
                     <child>
-                      <object class="GtkMenuItem" id="menuitem7">
+                      <object class="GtkMenuItem" id="menu_format">
                         <property name="visible">True</property>
                         <property name="label" translatable="yes">_Format...</property>
                         <property name="use_underline">True</property>
@@ -232,7 +217,7 @@ are placed in the same directory as the table</property>
                   <object class="GtkMenu" id="menu3">
                     <property name="visible">True</property>
                     <child>
-                      <object class="GtkImageMenuItem" id="imagemenuitem10">
+                      <object class="GtkImageMenuItem" id="menu_about">
                         <property name="visible">True</property>
                         <property name="related_action">action_about</property>
                         <property name="use_underline">True</property>
@@ -240,7 +225,7 @@ are placed in the same directory as the table</property>
                       </object>
                     </child>
                     <child>
-                      <object class="GtkImageMenuItem" id="imagemenuitem12">
+                      <object class="GtkImageMenuItem" id="menu_help">
                         <property name="visible">True</property>
                         <property name="related_action">action_help</property>
                         <property name="use_underline">True</property>
@@ -364,53 +349,24 @@ are placed in the same directory as the table</property>
       </object>
     </child>
   </object>
-  <object class="GtkActionGroup" id="file_actions"/>
-  <object class="GtkAction" id="action_open">
-    <property name="tooltip">Open a file</property>
-    <property name="stock_id">gtk-open</property>
-    <signal name="activate" handler="_onOpen" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="action_save">
-    <property name="stock_id">gtk-save</property>
-    <property name="sensitive">False</property>
-    <signal name="activate" handler="_onSave" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="action_save_as">
-    <property name="stock_id">gtk-save-as</property>
-    <property name="sensitive">False</property>
-    <signal name="activate" handler="_onSaveAs" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="action_quit">
-    <property name="stock_id">gtk-quit</property>
-    <signal name="activate" handler="_onQuit" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="action_print">
-    <property name="stock_id">gtk-print</property>
-    <property name="sensitive">False</property>
-    <signal name="activate" handler="_onPrint" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="action_about">
-    <property name="stock_id">gtk-about</property>
-    <signal name="activate" handler="_onAbout" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="action_help">
-    <property name="stock_id">gtk-help</property>
-    <signal name="activate" handler="_onHelp" swapped="no"/>
-  </object>
-  <object class="GtkMessageDialog" id="notext-dialog">
+  <object class="GtkMessageDialog" id="table_error_dialog">
     <property name="border_width">5</property>
     <property name="type_hint">normal</property>
     <property name="skip_taskbar_hint">True</property>
-    <property name="message_type">warning</property>
+    <property name="message_type">error</property>
     <property name="buttons">ok</property>
-    <property name="text" translatable="yes">Cannot extract text from the document.</property>
-    <property name="secondary_text" translatable="yes">Make sure that the document is valid and does contain text</property>
+    <property name="text" translatable="yes">The selected table is not valid</property>
+    <property name="secondary_text" translatable="yes">The selected table cannot be used by
+liblouisxml. Please make sure that if you
+are using "include" directive, those files
+are placed in the same directory as the table</property>
+    <property name="secondary_use_markup">True</property>
     <child internal-child="vbox">
-      <object class="GtkVBox" id="dialog-vbox1">
+      <object class="GtkVBox" id="dialog-vbox3">
         <property name="visible">True</property>
         <property name="spacing">2</property>
         <child internal-child="action_area">
-          <object class="GtkHButtonBox" id="dialog-action_area1">
+          <object class="GtkHButtonBox" id="dialog-action_area3">
             <property name="visible">True</property>
             <property name="layout_style">end</property>
             <child>
diff --git a/dots/app_window.py b/dots/app_window.py
index 4ac9535..bb81788 100644
--- a/dots/app_window.py
+++ b/dots/app_window.py
@@ -386,11 +386,34 @@ class AppWindow(object):
 	return res
 
 
-
+    # FIXME: this should be doable in glade
+    def _add_control_key(self, widget, accel_group, key):
+	widget.add_accelerator("activate", accel_group, ord(key),
+                               gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
+
+    def _add_shift_control_key(self, widget, accel_group, key):
+	widget.add_accelerator("activate", accel_group, ord(key),
+                               gtk.gdk.SHIFT_MASK | gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
+
+
+
+    def _menu_add_accels(self):
+	accel_group = gtk.AccelGroup()
+	self.window.add_accel_group(accel_group)
+	self._add_control_key(self.main_xml.get_object('menu_open'), accel_group, 'o')
+	self._add_control_key(self.main_xml.get_object('menu_save'), accel_group, 's')
+	self._add_shift_control_key(self.main_xml.get_object('menu_save_as'), accel_group, 's')
+	self._add_control_key(self.main_xml.get_object('menu_print'), accel_group, 'p')
+	self._add_control_key(self.main_xml.get_object('ascii_radio'), accel_group, 'a')
+	self._add_control_key(self.main_xml.get_object('braille_radio'), accel_group, 'b')
+	self._add_control_key(self.main_xml.get_object('line_check'), accel_group, 'l')
+	self._add_control_key(self.main_xml.get_object('menu_format'), accel_group, 'f')
+	self.main_xml.get_object('menu_help').add_accelerator("activate", accel_group, gtk.keysyms.F1, 0, gtk.ACCEL_VISIBLE)
 
     def run(self):
         self.window.show_all()
         self.main_xml.get_object('reviewentry').hide()
+	self._menu_add_accels()
         gtk.main()
 
     def _onHelp(self, action):



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