[Dextrose] [PATCH sugar] Adding a "hook"-function, that is called when the "OK" button in the SectionView Toolbar is clicked.

Ajay Garg ajay at activitycentral.com
Wed Feb 22 03:41:03 EST 2012


Making use of this hook-function in "DateTime" and "Network" CP views,
to get rid of the "Save" button in the "NTP Servers Configuration" and
"Hidden Networks" sections respectively.

Thanks to Anish for the motivation.

 extensions/cpsection/datetime/view.py  |   16 +---------------
 extensions/cpsection/network/view.py   |   15 +--------------
 src/jarabe/controlpanel/gui.py         |    1 +
 src/jarabe/controlpanel/sectionview.py |    4 ++++
 4 files changed, 7 insertions(+), 29 deletions(-)

diff --git a/extensions/cpsection/datetime/view.py b/extensions/cpsection/datetime/view.py
index e488485..1a4dfe8 100644
--- a/extensions/cpsection/datetime/view.py
+++ b/extensions/cpsection/datetime/view.py
@@ -252,21 +252,8 @@ class TimeZone(SectionView):
                                           expand=False)
         label_ntp_servers_config.show()
 
-        self._ntp_servers_save_button = gtk.Button()
-        self._ntp_servers_save_button.set_alignment(0, 0)
-        self._ntp_servers_save_button.set_label(_('Save'))
-        self._ntp_servers_save_button.connect('clicked',
-                self.__ntp_servers_save_button_clicked_cb)
-
-        box_save_button = gtk.HBox()
-        box_save_button.set_homogeneous(False)
-        box_save_button.pack_start(self._ntp_servers_save_button,
-                                   expand=False)
-        self._ntp_servers_save_button.show()
-
         self._widget_table = MultiWidget()
         box_ntp_servers_config.pack_start(self._widget_table, expand=False)
-        box_ntp_servers_config.pack_start(box_save_button, expand=False)
         box_ntp_servers_config.show_all()
 
         self._ntp_scrolled_window.add_with_viewport(box_ntp_servers_config)
@@ -316,6 +303,5 @@ class TimeZone(SectionView):
         self._zone_alert.show()
         return False
 
-    def __ntp_servers_save_button_clicked_cb(self, save_button):
+    def perform_accept_actions(self):
         self._model.set_ntp_servers(self._widget_table._get_entries())
-        save_button.set_sensitive(False)
diff --git a/extensions/cpsection/network/view.py b/extensions/cpsection/network/view.py
index 5bfe01c..de2fd81 100644
--- a/extensions/cpsection/network/view.py
+++ b/extensions/cpsection/network/view.py
@@ -744,18 +744,6 @@ class Network(SectionView):
             box_hidden_network.pack_start(self._widget_table, expand=False)
             self._widget_table.show()
 
-            save_button = gtk.Button()
-            save_button.set_alignment(0, 0)
-            save_button.set_label('Save')
-            save_button.connect('clicked', self.__save_button_clicked_cb)
-            box_save_button = gtk.HBox()
-            box_save_button.set_homogeneous(False)
-            box_save_button.pack_start(save_button, expand=False)
-            save_button.show()
-
-            box_hidden_network.pack_start(box_save_button, expand=False)
-            box_save_button.show()
-
             workspace.pack_start(box_hidden_network, expand=False)
             box_hidden_network.show()
 
@@ -1017,9 +1005,8 @@ class Network(SectionView):
         if not self._model.have_networks():
             self._clear_history_button.set_sensitive(False)
 
-    def __save_button_clicked_cb(self, save_button):
+    def perform_accept_actions(self):
         self._model.set_ssids(self._widget_table._get_entries())
-        save_button.set_sensitive(False)
 
     def __launch_button_clicked_cb(self, launch_button):
         self._model.launch_nm_connection_editor()
diff --git a/src/jarabe/controlpanel/gui.py b/src/jarabe/controlpanel/gui.py
index 61520e0..0b70af6 100644
--- a/src/jarabe/controlpanel/gui.py
+++ b/src/jarabe/controlpanel/gui.py
@@ -291,6 +291,7 @@ class ControlPanel(gtk.Window):
         self._show_main_view()
 
     def __accept_clicked_cb(self, widget):
+        self._section_view.perform_accept_actions()
         if self._section_view.needs_restart:
             self._section_toolbar.accept_button.set_sensitive(False)
             self._section_toolbar.cancel_button.set_sensitive(False)
diff --git a/src/jarabe/controlpanel/sectionview.py b/src/jarabe/controlpanel/sectionview.py
index 4b5751f..836adf4 100644
--- a/src/jarabe/controlpanel/sectionview.py
+++ b/src/jarabe/controlpanel/sectionview.py
@@ -52,3 +52,7 @@ class SectionView(gtk.VBox):
     def undo(self):
         """Undo here the changes that have been made in this section."""
         pass
+
+    def perform_accept_actions(self):
+        """Perform additional actions, when the "Ok" button is clicked."""
+        pass
-- 
1.7.4.4



More information about the Dextrose mailing list