From 7f166dcd80136f94d395f8a0ee4a6a5ef4d3e681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Tue, 28 Feb 2017 18:28:01 +0100 Subject: [PATCH 1/6] [emoticons] Use IntEnum --- emoticons_pack/emoticons_pack.py | 55 ++++++++++++++++---------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/emoticons_pack/emoticons_pack.py b/emoticons_pack/emoticons_pack.py index 0985f71..08e9901 100644 --- a/emoticons_pack/emoticons_pack.py +++ b/emoticons_pack/emoticons_pack.py @@ -13,7 +13,7 @@ import tempfile from shutil import rmtree import sys import imp - +from enum import IntEnum from common import gajim from plugins import GajimPlugin from plugins.helpers import log_calls @@ -21,14 +21,15 @@ from htmltextview import HtmlTextView from conversation_textview import ConversationTextview from dialogs import WarningDialog, HigDialog -( - C_PIXBUF, - C_NAME, - C_DESCRIPTION, - C_AUTHORS, - C_CONVERTER, - C_HOMEPAGE, - C_UPGRADE) = range(7) + +class Column(IntEnum): + PIXBUF = 0 + NAME = 1 + DESCRIPTION = 2 + AUTHORS = 3 + CONVERTER = 4 + HOMEPAGE = 5 + UPGRADE = 6 class EmoticonsPackPlugin(GajimPlugin): @@ -104,9 +105,9 @@ class EmoticonsPackPlugin(GajimPlugin): col = Gtk.TreeViewColumn(_('Name')) cell = Gtk.CellRendererPixbuf() col.pack_start(cell, False) - col.add_attribute(cell, 'pixbuf', C_PIXBUF) + col.add_attribute(cell, 'pixbuf', Column.PIXBUF) col.pack_start(renderer, True) - col.add_attribute(renderer, 'text', C_NAME) + col.add_attribute(renderer, 'text', Column.NAME) col.set_property('expand', True) col.set_sizing(Gtk.TreeViewColumnSizing.GROW_ONLY) self.available_treeview.append_column(col) @@ -115,7 +116,7 @@ class EmoticonsPackPlugin(GajimPlugin): renderer.set_property('activatable', True) renderer.connect('toggled', self.available_emoticons_toggled_cb) col = Gtk.TreeViewColumn( - _('Install /\nUpgrade'), renderer, active=C_UPGRADE) + _('Install /\nUpgrade'), renderer, active=Column.UPGRADE) col.set_property('expand', False) col.set_resizable(False) self.available_treeview.append_column(col) @@ -135,7 +136,7 @@ class EmoticonsPackPlugin(GajimPlugin): treeview_selection = self.available_treeview.get_selection() model, iter = treeview_selection.get_selected() - name = model.get_value(iter, C_NAME) + name = model.get_value(iter, Column.NAME) label = self.xml.get_object('label2') if label.get_text() == _('Legend'): @@ -179,7 +180,7 @@ class EmoticonsPackPlugin(GajimPlugin): sw.add(self.emoticons_description_textview.tv) sw.show_all() label.set_text(_('Legend')) - desc = _(model.get_value(iter, C_DESCRIPTION)) + desc = _(model.get_value(iter, Column.DESCRIPTION)) if not desc.startswith('' + \ desc + ' ' @@ -205,8 +206,8 @@ class EmoticonsPackPlugin(GajimPlugin): name_list = [] for i in range(len(self.model)): - if self.model[i][C_UPGRADE]: - name_list.append(self.model[i][C_NAME]) + if self.model[i][Column.UPGRADE]: + name_list.append(self.model[i][Column.NAME]) for name in name_list: # remove dirs target_dir = os.path.join(gajim.MY_EMOTS_PATH, name) @@ -226,7 +227,7 @@ class EmoticonsPackPlugin(GajimPlugin): self.errors += str(e) # unset all checkbattons for i in range(len(self.model)): - self.model[i][C_UPGRADE] = False + self.model[i][Column.UPGRADE] = False if self.errors: WarningDialog( @@ -246,12 +247,12 @@ class EmoticonsPackPlugin(GajimPlugin): del self.page_num def available_emoticons_toggled_cb(self, cell, path): - is_active = self.model[path][C_UPGRADE] - self.model[path][C_UPGRADE] = not is_active + is_active = self.model[path][Column.UPGRADE] + self.model[path][Column.UPGRADE] = not is_active dir_list = [] for i in range(len(self.model)): - if self.model[i][C_UPGRADE]: - dir_list.append(self.model[i][C_NAME]) + if self.model[i][Column.UPGRADE]: + dir_list.append(self.model[i][Column.NAME]) if not dir_list: self.inslall_upgrade_button.set_property('sensitive', False) else: @@ -299,7 +300,7 @@ class EmoticonsPackPlugin(GajimPlugin): label = self.xml.get_object('label2') label.set_text(_('Legend')) if iter: - set_name = model.get_value(iter, C_NAME) + set_name = model.get_value(iter, Column.NAME) if os.path.isdir(self.tmp_dir): rmtree(self.tmp_dir, True) self.tmp_dir = tempfile.mkdtemp() @@ -313,12 +314,12 @@ class EmoticonsPackPlugin(GajimPlugin): myzip.extract(n, path=self.tmp_dir) self.set_name.set_text(set_name) - self.authors_label.set_text(model.get_value(iter, C_AUTHORS)) - self.converter_label.set_text(model.get_value(iter, C_CONVERTER)) + self.authors_label.set_text(model.get_value(iter, Column.AUTHORS)) + self.converter_label.set_text(model.get_value(iter, Column.CONVERTER)) self.homepage_linkbutton.set_uri( - model.get_value(iter, C_HOMEPAGE)) + model.get_value(iter, Column.HOMEPAGE)) self.homepage_linkbutton.set_label( - model.get_value(iter, C_HOMEPAGE)) + model.get_value(iter, Column.HOMEPAGE)) label = self.homepage_linkbutton.get_children()[0] label.set_ellipsize(Pango.EllipsizeMode.END) self.homepage_linkbutton.set_property('sensitive', True) @@ -328,7 +329,7 @@ class EmoticonsPackPlugin(GajimPlugin): sw = self.xml.get_object('scrolledwindow1') sw.add(self.emoticons_description_textview.tv) sw.show_all() - desc = _(model.get_value(iter, C_DESCRIPTION)) + desc = _(model.get_value(iter, Column.DESCRIPTION)) if not desc.startswith('' + \ desc + ' ' From 5a05b0f844d6564654bfcb869317d2ee5f2f8ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Tue, 28 Feb 2017 20:11:10 +0100 Subject: [PATCH 2/6] [emoticons] Use extension point --- emoticons_pack/emoticons_pack.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/emoticons_pack/emoticons_pack.py b/emoticons_pack/emoticons_pack.py index 08e9901..680364f 100644 --- a/emoticons_pack/emoticons_pack.py +++ b/emoticons_pack/emoticons_pack.py @@ -39,6 +39,7 @@ class EmoticonsPackPlugin(GajimPlugin): self.description = _('Install, update and view detailed legend ' 'of emoticons') self.config_dialog = None # EmoticonsPackPluginConfigDialog(self) + self.gui_extension_points = {'plugin_window': (self.on_activate, None)} self.window = None self.model = None self.connected_ids = {} @@ -46,15 +47,11 @@ class EmoticonsPackPlugin(GajimPlugin): @log_calls('EmoticonsPackPlugin') def activate(self): - self.pl_menuitem = gajim.interface.roster.xml.get_object( - 'plugins_menuitem') - self.id_ = self.pl_menuitem.connect_after('activate', self.on_activate) if 'plugins' in gajim.interface.instances: - self.on_activate(None) + self.on_activate(gajim.interface.instances['plugins']) @log_calls('EmoticonsPackPlugin') def deactivate(self): - self.pl_menuitem.disconnect(self.id_) if hasattr(self, 'page_num'): self.notebook.remove_page(self.notebook.page_num(self.hpaned)) self.notebook.set_current_page(0) @@ -62,19 +59,15 @@ class EmoticonsPackPlugin(GajimPlugin): widget.disconnect(id_) del self.page_num - def on_activate(self, widget): - if 'plugins' not in gajim.interface.instances: - return + def on_activate(self, plugin_win): if hasattr(self, 'page_num'): # 'Available' tab exists return - self.installed_plugins_model = gajim.interface.instances[ - 'plugins'].installed_plugins_model - self.notebook = gajim.interface.instances['plugins'].plugins_notebook + self.notebook = plugin_win.plugins_notebook id_ = self.notebook.connect( 'switch-page', self.on_notebook_switch_page) self.connected_ids[id_] = self.notebook - self.window = gajim.interface.instances['plugins'].window + self.window = plugin_win.window id_ = self.window.connect('destroy', self.on_win_destroy) self.connected_ids[id_] = self.window self.Gtk_BUILDER_FILE_PATH = self.local_file_path('config_dialog.ui') From 2065cab50afd87e3b6ec059df02a0dfada4da050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Tue, 28 Feb 2017 20:13:41 +0100 Subject: [PATCH 3/6] [emoticons] Fix some breaking bugs --- emoticons_pack/emoticons_pack.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/emoticons_pack/emoticons_pack.py b/emoticons_pack/emoticons_pack.py index 680364f..f4c9813 100644 --- a/emoticons_pack/emoticons_pack.py +++ b/emoticons_pack/emoticons_pack.py @@ -13,6 +13,7 @@ import tempfile from shutil import rmtree import sys import imp +import posixpath from enum import IntEnum from common import gajim from plugins import GajimPlugin @@ -252,9 +253,11 @@ class EmoticonsPackPlugin(GajimPlugin): self.inslall_upgrade_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(page) if tab_label_text != (_('Emoticons')): return + if len(self.model): + return self.model.clear() self.fill_table() @@ -268,8 +271,7 @@ class EmoticonsPackPlugin(GajimPlugin): conf.read_file(_file) for section in conf.sections(): # get icon - filename = conf.get(section, 'icon') - filename = os.path.join(section, filename) + filename = posixpath.join(section, conf.get(section, 'icon')) zip_file = os.path.join(self.__path__, 'emoticons_pack.zip') with zipfile.ZipFile(zip_file, 'r') as myzip: icon_file = myzip.open(filename, mode='r') @@ -330,7 +332,7 @@ class EmoticonsPackPlugin(GajimPlugin): desc = desc.replace('preview.image', ('file:' + os.path.join( self.tmp_dir, set_name, 'preview.png'))) self.emoticons_description_textview.tv.display_html( - desc, self.emoticons_description_textview) + desc, self.emoticons_description_textview.tv, None) self.emoticons_description_textview.tv.set_property( 'sensitive', True) else: From fc77f07917eb030fd993b29a62451cc0d73c3aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Tue, 28 Feb 2017 20:25:00 +0100 Subject: [PATCH 4/6] [emoticons] Simplify displaying description/legend --- emoticons_pack/emoticons_pack.py | 36 ++++++++++---------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/emoticons_pack/emoticons_pack.py b/emoticons_pack/emoticons_pack.py index f4c9813..79bb496 100644 --- a/emoticons_pack/emoticons_pack.py +++ b/emoticons_pack/emoticons_pack.py @@ -19,7 +19,6 @@ from common import gajim from plugins import GajimPlugin from plugins.helpers import log_calls from htmltextview import HtmlTextView -from conversation_textview import ConversationTextview from dialogs import WarningDialog, HigDialog @@ -119,19 +118,19 @@ class EmoticonsPackPlugin(GajimPlugin): selection.connect('changed', self.emoticons_treeview_selection_changed) selection.set_mode(Gtk.SelectionMode.SINGLE) - self.emoticons_description_textview = ConversationTextview(None) + self.emoticons_description_textview = HtmlTextView() sw = self.xml.get_object('scrolledwindow1') - sw.add(self.emoticons_description_textview.tv) + sw.add(self.emoticons_description_textview) self.xml.connect_signals(self) self.window.show_all() def on_legend_button_clicked(self, widget): - self.xml.get_object('scrolledwindow1').get_children()[0].destroy() - treeview_selection = self.available_treeview.get_selection() model, iter = treeview_selection.get_selected() name = model.get_value(iter, Column.NAME) + self.emoticons_description_textview.get_buffer().set_text('') + label = self.xml.get_object('label2') if label.get_text() == _('Legend'): label.set_text(_('Description')) @@ -140,11 +139,6 @@ class EmoticonsPackPlugin(GajimPlugin): import emoticons imp.reload(emoticons) - self.emoticons_description_textview = Gtk.TextView() - sw = self.xml.get_object('scrolledwindow1') - sw.add(self.emoticons_description_textview) - sw.show_all() - buff = self.emoticons_description_textview.get_buffer() for icon in emoticons.emoticons: icon_file = os.path.join(self.tmp_dir, name, icon) @@ -169,10 +163,6 @@ class EmoticonsPackPlugin(GajimPlugin): sys.path.remove(os.path.join(self.tmp_dir, name)) else: - self.emoticons_description_textview = ConversationTextview(None) - sw = self.xml.get_object('scrolledwindow1') - sw.add(self.emoticons_description_textview.tv) - sw.show_all() label.set_text(_('Legend')) desc = _(model.get_value(iter, Column.DESCRIPTION)) if not desc.startswith('' desc = desc.replace('preview.image', ('file:' + os.path.join( self.tmp_dir, name, 'preview.png'))).replace('\n', '
') - self.emoticons_description_textview.tv.display_html( - desc, self.emoticons_description_textview) - self.emoticons_description_textview.tv.set_property( + self.emoticons_description_textview.display_html( + desc, self.emoticons_description_textview, None) + self.emoticons_description_textview.set_property( 'sensitive', True) def on_inslall_upgrade_clicked(self, widget): @@ -319,11 +309,7 @@ class EmoticonsPackPlugin(GajimPlugin): label.set_ellipsize(Pango.EllipsizeMode.END) self.homepage_linkbutton.set_property('sensitive', True) - self.xml.get_object('scrolledwindow1').get_children()[0].destroy() - self.emoticons_description_textview = ConversationTextview(None) - sw = self.xml.get_object('scrolledwindow1') - sw.add(self.emoticons_description_textview.tv) - sw.show_all() + self.emoticons_description_textview.get_buffer().set_text('') desc = _(model.get_value(iter, Column.DESCRIPTION)) if not desc.startswith('' + \ @@ -331,9 +317,9 @@ class EmoticonsPackPlugin(GajimPlugin): else: desc = desc.replace('preview.image', ('file:' + os.path.join( self.tmp_dir, set_name, 'preview.png'))) - self.emoticons_description_textview.tv.display_html( - desc, self.emoticons_description_textview.tv, None) - self.emoticons_description_textview.tv.set_property( + self.emoticons_description_textview.display_html( + desc, self.emoticons_description_textview, None) + self.emoticons_description_textview.set_property( 'sensitive', True) else: self.set_name.set_text('') From e4599e06087f1d838cb4bb8f35d63047ada13097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Tue, 28 Feb 2017 20:26:33 +0100 Subject: [PATCH 5/6] [emoticons] Remove unused code --- emoticons_pack/emoticons_pack.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/emoticons_pack/emoticons_pack.py b/emoticons_pack/emoticons_pack.py index 79bb496..6978ff8 100644 --- a/emoticons_pack/emoticons_pack.py +++ b/emoticons_pack/emoticons_pack.py @@ -5,7 +5,6 @@ from gi.repository import Gtk from gi.repository import GdkPixbuf from gi.repository import Pango from gi.repository import GObject -import io import configparser import os import zipfile @@ -93,7 +92,6 @@ class EmoticonsPackPlugin(GajimPlugin): self.available_treeview.set_rules_hint(True) self.model.set_sort_column_id(1, Gtk.SortType.ASCENDING) - #self.progressbar.set_property('no-show-all', True) renderer = Gtk.CellRendererText() col = Gtk.TreeViewColumn(_('Name')) cell = Gtk.CellRendererPixbuf() @@ -338,4 +336,3 @@ class EmoticonsPackPlugin(GajimPlugin): vadjustment = scr_win.get_vadjustment() if vadjustment: vadjustment.set_value(0) - #GObject.idle_add(self.available_treeview.grab_focus) From d9af84ac8af78a9aebb6eae6f225564a8724bf89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Tue, 28 Feb 2017 20:46:39 +0100 Subject: [PATCH 6/6] [emoticons] Update manifest.ini --- emoticons_pack/manifest.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/emoticons_pack/manifest.ini b/emoticons_pack/manifest.ini index c0cf4f1..f96cc83 100644 --- a/emoticons_pack/manifest.ini +++ b/emoticons_pack/manifest.ini @@ -1,8 +1,8 @@ [info] name: Emoticons pack short_name: emoticons_pack -version: 0.0.1 +version: 2.0.0 description: Install, update and view detailed legend of emoticons authors: Denis Fomin -homepage: http://trac-plugins.gajim.org/wiki/PluginInstallerPlugin +homepage: https://dev.gajim.org/gajim/gajim-plugins/wikis/EmoticonPackPlugin min_gajim_version: 0.16.10