[alacarte] ItemEditor: Refactor and deduplicate code
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [alacarte] ItemEditor: Refactor and deduplicate code
- Date: Fri, 11 Jan 2013 06:40:44 +0000 (UTC)
commit fc8351173b470033e290f647c338f2801421c323
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Fri Jan 11 01:38:39 2013 -0500
ItemEditor: Refactor and deduplicate code
Alacarte/ItemEditor.py | 45 +++++++++++++++++++++++----------------------
1 files changed, 23 insertions(+), 22 deletions(-)
---
diff --git a/Alacarte/ItemEditor.py b/Alacarte/ItemEditor.py
index a41ab59..df33807 100644
--- a/Alacarte/ItemEditor.py
+++ b/Alacarte/ItemEditor.py
@@ -92,6 +92,25 @@ class IconPicker(object):
chooser.destroy()
class ItemEditor(object):
+ ui_file = None
+
+ def __init__(self, parent, item_path):
+ self.builder = Gtk.Builder()
+ self.builder.add_from_file(os.path.join(config.pkgdatadir, self.ui_file))
+
+ self.dialog = self.builder.get_object('editor')
+ self.dialog.set_transient_for(parent)
+ self.dialog.connect('response', self.on_response)
+
+ self.build_ui()
+
+ self.item_path = item_path
+ self.load()
+ self.resync_validity()
+
+ def build_ui(self):
+ raise NotImplementedError()
+
def get_keyfile_edits(self):
raise NotImplementedError()
@@ -141,14 +160,9 @@ class ItemEditor(object):
self.dialog.destroy()
class LauncherEditor(ItemEditor):
- def __init__(self, parent, item_path):
- self.builder = Gtk.Builder()
- self.builder.add_from_file(os.path.join(config.pkgdatadir, 'launcher-editor.ui'))
-
- self.dialog = self.builder.get_object('editor')
- self.dialog.set_transient_for(parent)
- self.dialog.connect('response', self.on_response)
+ ui_file = 'launcher-editor.ui'
+ def build_ui(self):
self.icon_picker = IconPicker(self.dialog,
self.builder.get_object('icon-button'),
self.builder.get_object('icon-image'))
@@ -158,10 +172,6 @@ class LauncherEditor(ItemEditor):
self.builder.get_object('name-entry').connect('changed', self.resync_validity)
self.builder.get_object('exec-entry').connect('changed', self.resync_validity)
- self.item_path = item_path
- self.load()
- self.resync_validity()
-
def resync_validity(self, *args):
name_text = self.builder.get_object('name-entry').get_text()
exec_text = self.builder.get_object('exec-entry').get_text()
@@ -195,24 +205,15 @@ class LauncherEditor(ItemEditor):
chooser.destroy()
class DirectoryEditor(ItemEditor):
- def __init__(self, parent, item_path):
- self.builder = Gtk.Builder()
- self.builder.add_from_file(os.path.join(config.pkgdatadir, 'directory-editor.ui'))
-
- self.dialog = self.builder.get_object('editor')
- self.dialog.set_transient_for(parent)
- self.dialog.connect('response', self.on_response)
+ ui_file = 'directory-editor.ui'
+ def build_ui(self):
self.icon_picker = IconPicker(self.dialog,
self.builder.get_object('icon-button'),
self.builder.get_object('icon-image'))
self.builder.get_object('name-entry').connect('changed', self.resync_validity)
- self.item_path = item_path
- self.load()
- self.resync_validity()
-
def resync_validity(self, *args):
name_text = self.builder.get_object('name-entry').get_text()
valid = (name_text is not None)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]