diff options
author | Philipp Hörist <forenjunkie@chello.at> | 2017-02-22 00:15:29 +0300 |
---|---|---|
committer | Philipp Hörist <forenjunkie@chello.at> | 2017-02-24 01:07:10 +0300 |
commit | 02f2f38bbe02b09b5290fde5c565b65351891350 (patch) | |
tree | 6e1d8fbb93fdb39393cdff9c8d683abbbf85552f /plugin_installer | |
parent | a41a3e915b2bc03d18a93cbff64d22f10f94d43a (diff) |
[plugin_installer] Refactor UI
- Move UI code to glade file
- Remove use of deprecated widgets
- Rename some widgets
Diffstat (limited to 'plugin_installer')
-rw-r--r-- | plugin_installer/config_dialog.ui | 381 | ||||
-rw-r--r-- | plugin_installer/plugin_installer.py | 121 |
2 files changed, 205 insertions, 297 deletions
diff --git a/plugin_installer/config_dialog.ui b/plugin_installer/config_dialog.ui index dca05f7..5ce735d 100644 --- a/plugin_installer/config_dialog.ui +++ b/plugin_installer/config_dialog.ui @@ -30,29 +30,67 @@ </object> </child> </object> - <object class="GtkWindow" id="window1"> + <object class="GtkListStore" id="plugin_store"> + <columns> + <!-- column-name icon --> + <column type="GdkPixbuf"/> + <!-- column-name dir --> + <column type="gchararray"/> + <!-- column-name name --> + <column type="gchararray"/> + <!-- column-name localversion --> + <column type="gchararray"/> + <!-- column-name version --> + <column type="gchararray"/> + <!-- column-name upgrade --> + <column type="gboolean"/> + <!-- column-name description --> + <column type="gchararray"/> + <!-- column-name authors --> + <column type="gchararray"/> + <!-- column-name homepage --> + <column type="gchararray"/> + </columns> + </object> + <object class="GtkImage" id="refresh"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="stock">gtk-refresh</property> + </object> + <object class="GtkWindow" id="AvailablePlugins"> <property name="can_focus">False</property> <child> - <object class="GtkHPaned" id="hpaned2"> - <property name="width_request">800</property> + <object class="GtkPaned" id="paned"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="position">340</property> - <property name="position_set">True</property> <child> - <object class="GtkVBox" id="vbox1"> + <object class="GtkGrid" id="plugin_grid"> <property name="visible">True</property> <property name="can_focus">False</property> <child> + <object class="GtkProgressBar" id="progressbar"> + <property name="can_focus">False</property> + <property name="ellipsize">end</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> + </packing> + </child> + <child> <object class="GtkScrolledWindow" id="scrolledwindow2"> <property name="visible">True</property> <property name="can_focus">True</property> + <property name="hexpand">True</property> <property name="border_width">6</property> <property name="hscrollbar_policy">never</property> <child> <object class="GtkTreeView" id="available_treeview"> <property name="visible">True</property> <property name="can_focus">True</property> + <property name="vexpand">True</property> + <property name="model">plugin_store</property> + <property name="headers_clickable">False</property> <property name="search_column">1</property> <child internal-child="selection"> <object class="GtkTreeSelection"/> @@ -116,294 +154,185 @@ Upgrade</property> </child> </object> <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkProgressBar" id="progressbar"> - <property name="can_focus">False</property> - <property name="ellipsize">end</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">1</property> + <property name="left_attach">0</property> + <property name="top_attach">0</property> </packing> </child> </object> <packing> - <property name="resize">False</property> + <property name="resize">True</property> <property name="shrink">False</property> </packing> </child> <child> - <object class="GtkBox" id="vbox2"> + <object class="GtkGrid" id="description_grid"> + <property name="width_request">350</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="border_width">6</property> - <property name="orientation">vertical</property> - <property name="spacing">6</property> + <property name="row_spacing">3</property> + <property name="column_spacing">5</property> <child> - <object class="GtkLabel" id="plugin_name_label"> + <object class="GtkLabel" id="name_label"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="halign">start</property> <property name="label" translatable="yes">&lt;empty&gt;</property> <property name="selectable">True</property> - <property name="xalign">0</property> <attributes> <attribute name="weight" value="bold"/> </attributes> </object> <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + <property name="width">2</property> </packing> </child> <child> - <object class="GtkBox" id="hbox1"> + <object class="GtkLabel" id="versionlabel"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="spacing">6</property> - <child> - <object class="GtkLabel" id="label5"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Version:</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="plugin_version_label"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label"><empty></property> - <property name="selectable">True</property> - <property name="xalign">0</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> + <property name="halign">start</property> + <property name="label" translatable="yes">Version:</property> </object> <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">1</property> + <property name="left_attach">0</property> + <property name="top_attach">1</property> </packing> </child> <child> - <object class="GtkBox" id="hbox3"> + <object class="GtkLabel" id="authorslabel"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="spacing">6</property> - <child> - <object class="GtkLabel" id="label4"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Authors:</property> - <property name="yalign">0</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="plugin_authors_label"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label"><empty></property> - <property name="wrap_mode">word-char</property> - <property name="selectable">True</property> - <property name="ellipsize">end</property> - <property name="xalign">0</property> - <property name="yalign">0</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> + <property name="halign">start</property> + <property name="valign">start</property> + <property name="label" translatable="yes">Authors:</property> </object> <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">2</property> + <property name="left_attach">0</property> + <property name="top_attach">2</property> </packing> </child> <child> - <object class="GtkBox" id="hbox4"> + <object class="GtkLabel" id="homepage_label"> <property name="visible">True</property> <property name="can_focus">False</property> - <child> - <object class="GtkLabel" id="label6"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Homepage:</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLinkButton" id="plugin_homepage_linkbutton"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="focus_on_click">False</property> - <property name="receives_default">True</property> - <property name="relief">none</property> - <property name="xalign">0</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> + <property name="halign">start</property> + <property name="label" translatable="yes">Homepage:</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">3</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="description_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + <property name="label" translatable="yes">Description:</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">4</property> + <property name="width">2</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="version_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + <property name="hexpand">False</property> + <property name="label"><empty></property> + <property name="selectable">True</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="authors_label"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">start</property> + <property name="valign">start</property> + <property name="label"><empty></property> + <property name="wrap_mode">word-char</property> + <property name="selectable">True</property> + <property name="ellipsize">end</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">2</property> + </packing> + </child> + <child> + <object class="GtkLinkButton" id="homepage_linkbutton"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="focus_on_click">False</property> + <property name="receives_default">True</property> + <property name="halign">start</property> + <property name="hexpand">True</property> + <property name="relief">none</property> </object> <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">3</property> + <property name="left_attach">1</property> + <property name="top_attach">3</property> </packing> </child> <child> - <object class="GtkBox" id="vbox3"> + <object class="GtkButtonBox"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="halign">end</property> + <property name="margin_top">2</property> + <property name="margin_bottom">2</property> <property name="orientation">vertical</property> + <property name="layout_style">start</property> <child> - <object class="GtkBox" id="hbox5"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <child> - <object class="GtkLabel" id="label7"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Description:</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <placeholder/> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkScrolledWindow" id="scrolledwindow1"> + <object class="GtkButton" id="install_button"> + <property name="label" translatable="yes">Install/Upgrade</property> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="shadow_type">in</property> - <child> - <placeholder/> - </child> + <property name="receives_default">True</property> + <property name="valign">start</property> + <property name="vexpand">False</property> + <property name="image">refresh</property> + <property name="always_show_image">True</property> + <signal name="clicked" handler="on_install_upgrade_clicked" swapped="no"/> </object> <packing> <property name="expand">True</property> <property name="fill">True</property> - <property name="position">1</property> + <property name="position">0</property> </packing> </child> </object> <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">4</property> + <property name="left_attach">0</property> + <property name="top_attach">6</property> + <property name="width">2</property> </packing> </child> <child> - <object class="GtkHBox" id="hbox15"> + <object class="GtkScrolledWindow" id="scrolled_description_window"> <property name="visible">True</property> - <property name="can_focus">False</property> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="shadow_type">in</property> <child> <placeholder/> </child> - <child> - <object class="GtkHButtonBox" id="hbuttonbox3"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="layout_style">end</property> - <child> - <object class="GtkButton" id="inslall_upgrade_button"> - <property name="use_action_appearance">False</property> - <property name="visible">True</property> - <property name="sensitive">False</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <signal name="clicked" handler="on_inslall_upgrade_clicked" swapped="no"/> - <child> - <object class="GtkHBox" id="hbox6"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <child> - <object class="GtkImage" id="image1"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="stock">gtk-refresh</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label1"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Install/Upgrade</property> - <property name="xalign">0</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="pack_type">end</property> - <property name="position">1</property> - </packing> - </child> </object> <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">5</property> + <property name="left_attach">0</property> + <property name="top_attach">5</property> + <property name="width">2</property> </packing> </child> </object> diff --git a/plugin_installer/plugin_installer.py b/plugin_installer/plugin_installer.py index ebf9540..b2086af 100644 --- a/plugin_installer/plugin_installer.py +++ b/plugin_installer/plugin_installer.py @@ -203,51 +203,32 @@ class PluginInstaller(GajimPlugin): self.Gtk_BUILDER_FILE_PATH = self.local_file_path('config_dialog.ui') self.xml = Gtk.Builder() self.xml.set_translation_domain('gajim_plugins') - self.xml.add_objects_from_file(self.Gtk_BUILDER_FILE_PATH, ['hpaned2']) - self.hpaned = self.xml.get_object('hpaned2') - self.page_num = self.notebook.append_page(self.hpaned, - Gtk.Label.new(_('Available'))) + self.xml.add_objects_from_file(self.Gtk_BUILDER_FILE_PATH, + ['refresh', 'paned', 'plugin_store']) widgets_to_extract = ( - 'plugin_name_label', 'available_treeview', 'progressbar', - 'inslall_upgrade_button', 'plugin_authors_label', - 'plugin_homepage_linkbutton', 'plugin_version_label') + 'name_label', 'available_treeview', 'progressbar', 'paned', + 'install_button', 'authors_label', + 'homepage_linkbutton', 'version_label', 'scrolled_description_window') for widget_name in widgets_to_extract: setattr(self, widget_name, self.xml.get_object(widget_name)) - self.available_plugins_model = Gtk.ListStore(GdkPixbuf.Pixbuf, - object, str, str, str, bool,object, object, object) - self.available_treeview.set_model(self.available_plugins_model) - self.available_treeview.set_rules_hint(True) + # Make Link in LinkButton not centered + style_provider = Gtk.CssProvider() + css = '.link { padding-left: 0px; padding-right: 0px; }' + style_provider.load_from_data(css.encode()) + context = self.homepage_linkbutton.get_style_context() + context.add_provider(style_provider, + Gtk.STYLE_PROVIDER_PRIORITY_USER) + + self.page_num = self.notebook.append_page( + self.paned, Gtk.Label.new(_('Available'))) + + self.available_plugins_model = self.xml.get_object('plugin_store') self.available_plugins_model.set_sort_column_id(2, Gtk.SortType.ASCENDING) self.progressbar.set_property('no-show-all', True) - renderer = Gtk.CellRendererText() - col = Gtk.TreeViewColumn(_('Plugin')) - cell = Gtk.CellRendererPixbuf() - col.pack_start(cell, False) - col.add_attribute(cell, 'pixbuf', Column.PIXBUF) - col.pack_start(renderer, True) - col.add_attribute(renderer, 'text', Column.NAME) - col.set_resizable(True) - col.set_property('expand', True) - col.set_sizing(Gtk.TreeViewColumnSizing.GROW_ONLY) - self.available_treeview.append_column(col) - col = Gtk.TreeViewColumn(_('Installed\nversion'), renderer, - text=Column.LOCAL_VERSION) - self.available_treeview.append_column(col) - col = Gtk.TreeViewColumn(_('Available\nversion'), renderer, - text=Column.VERSION) - col.set_property('expand', False) - self.available_treeview.append_column(col) - - renderer = Gtk.CellRendererToggle() - renderer.set_property('activatable', True) - renderer.connect('toggled', self.available_plugins_toggled_cb) - col = Gtk.TreeViewColumn(_('Install /\nUpgrade'), renderer, - active=Column.UPGRADE) - self.available_treeview.append_column(col) if GObject.signal_lookup('error_signal', self.window) is 0: GObject.signal_new('error_signal', self.window, @@ -264,16 +245,15 @@ class PluginInstaller(GajimPlugin): self.connected_ids[id_] = self.window selection = self.available_treeview.get_selection() - selection.connect('changed', - self.available_plugins_treeview_selection_changed) + selection.connect( + 'changed', self.available_plugins_treeview_selection_changed) selection.set_mode(Gtk.SelectionMode.SINGLE) self._clear_available_plugin_info() - self.plugin_description_textview = HtmlTextView() - self.plugin_description_textview.set_wrap_mode(Gtk.WrapMode.WORD) - sw = self.xml.get_object('scrolledwindow1') - sw.add(self.plugin_description_textview) + self.description_textview = HtmlTextView() + self.description_textview.set_wrap_mode(Gtk.WrapMode.WORD) + self.scrolled_description_window.add(self.description_textview) self.xml.connect_signals(self) self.window.show_all() @@ -292,12 +272,12 @@ class PluginInstaller(GajimPlugin): if self.available_plugins_model[i][Column.UPGRADE]: dir_list.append(self.available_plugins_model[i][Column.DIR]) if not dir_list: - self.inslall_upgrade_button.set_property('sensitive', False) + self.install_button.set_property('sensitive', False) else: - self.inslall_upgrade_button.set_property('sensitive', True) + self.install_button.set_property('sensitive', True) def on_notebook_switch_page(self, widget, page, page_num): - tab_label_text = self.notebook.get_tab_label_text(self.hpaned) + tab_label_text = self.notebook.get_tab_label_text(self.paned) if tab_label_text != (_('Available')): return if not hasattr(self, 'ftp'): @@ -308,8 +288,8 @@ class PluginInstaller(GajimPlugin): self.ftp.upgrading = True self.ftp.start() - def on_inslall_upgrade_clicked(self, widget): - self.inslall_upgrade_button.set_property('sensitive', False) + def on_install_upgrade_clicked(self, widget): + self.install_button.set_property('sensitive', False) dir_list = [] for i in range(len(self.available_plugins_model)): if self.available_plugins_model[i][Column.UPGRADE]: @@ -379,41 +359,41 @@ class PluginInstaller(GajimPlugin): def available_plugins_treeview_selection_changed(self, treeview_selection): model, iter = treeview_selection.get_selected() - self.xml.get_object('scrolledwindow1').get_children()[0].destroy() - self.plugin_description_textview = HtmlTextView() - self.plugin_description_textview.set_wrap_mode(Gtk.WrapMode.WORD) - sw = self.xml.get_object('scrolledwindow1') - sw.add(self.plugin_description_textview) + self.xml.get_object('scrolled_description_window').get_children()[0].destroy() + self.description_textview = HtmlTextView() + self.description_textview.set_wrap_mode(Gtk.WrapMode.WORD) + sw = self.xml.get_object('scrolled_description_window') + sw.add(self.description_textview) sw.show_all() if iter: - self.plugin_name_label.set_text(model.get_value(iter, Column.NAME)) - self.plugin_version_label.set_text(model.get_value(iter, Column.VERSION)) - self.plugin_authors_label.set_text(model.get_value(iter, Column.AUTHORS)) - self.plugin_homepage_linkbutton.set_uri(model.get_value(iter, + self.name_label.set_text(model.get_value(iter, Column.NAME)) + self.version_label.set_text(model.get_value(iter, Column.VERSION)) + self.authors_label.set_text(model.get_value(iter, Column.AUTHORS)) + self.homepage_linkbutton.set_uri(model.get_value(iter, Column.HOMEPAGE)) - self.plugin_homepage_linkbutton.set_label(model.get_value(iter, + self.homepage_linkbutton.set_label(model.get_value(iter, Column.HOMEPAGE)) - label = self.plugin_homepage_linkbutton.get_children()[0] + label = self.homepage_linkbutton.get_children()[0] label.set_ellipsize(Pango.EllipsizeMode.END) - self.plugin_homepage_linkbutton.set_property('sensitive', True) + self.homepage_linkbutton.set_property('sensitive', True) desc = _(model.get_value(iter, Column.DESCRIPTION)) if not desc.startswith('<body '): desc = '<body xmlns=\'http://www.w3.org/1999/xhtml\'>' + \ desc + ' </body>' desc = desc.replace('\n', '<br/>') - self.plugin_description_textview.display_html( - desc, self.plugin_description_textview, None) - self.plugin_description_textview.set_property('sensitive', True) + self.description_textview.display_html( + desc, self.description_textview, None) + self.description_textview.set_property('sensitive', True) else: self._clear_available_plugin_info() def _clear_available_plugin_info(self): - self.plugin_name_label.set_text('') - self.plugin_version_label.set_text('') - self.plugin_authors_label.set_text('') - self.plugin_homepage_linkbutton.set_uri('') - self.plugin_homepage_linkbutton.set_label('') - self.plugin_homepage_linkbutton.set_property('sensitive', False) + self.name_label.set_text('') + self.version_label.set_text('') + self.authors_label.set_text('') + self.homepage_linkbutton.set_uri('') + self.homepage_linkbutton.set_label('') + self.homepage_linkbutton.set_property('sensitive', False) def scan_dir_for_plugin(self, path): plugins_found = [] @@ -487,7 +467,7 @@ class PluginInstaller(GajimPlugin): if selection.count_selected_rows() == 0: root_iter = self.available_plugins_model.get_iter_first() selection.select_iter(root_iter) - scr_win = self.xml.get_object('scrolledwindow2') + scr_win = self.xml.get_object('scrolled_description_window') vadjustment = scr_win.get_vadjustment() if vadjustment: vadjustment.set_value(0) @@ -566,7 +546,7 @@ class Ftp(threading.Thread): if remote > local: upgrade = True GLib.idle_add( - self.plugin.inslall_upgrade_button.set_property, + self.plugin.install_button.set_property, 'sensitive', True) png_filename = dir_ + '/' + dir_ + '.png' if png_filename in manifest_list: @@ -581,7 +561,6 @@ class Ftp(threading.Thread): if local_version: base_dir, user_dir = gajim.PLUGINS_DIRS local_dir = os.path.join(user_dir, dir_) - GLib.idle_add(self.model_append, [def_icon, dir_, config.get('info', 'name'), local_version, config.get('info', 'version'), upgrade, |