diff --git a/emoticons_pack/emoticons_pack.py b/emoticons_pack/emoticons_pack.py index 0985f71..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 @@ -13,22 +12,23 @@ import tempfile from shutil import rmtree import sys import imp - +import posixpath +from enum import IntEnum 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 -( - 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): @@ -38,6 +38,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 = {} @@ -45,15 +46,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) @@ -61,19 +58,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') @@ -99,14 +92,13 @@ 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() 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 +107,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) @@ -124,18 +116,18 @@ 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, C_NAME) + 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'): @@ -145,11 +137,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) @@ -174,20 +161,16 @@ 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, C_DESCRIPTION)) + desc = _(model.get_value(iter, Column.DESCRIPTION)) if not desc.startswith('
' + \ desc + ' ' desc = desc.replace('preview.image', ('file:' + os.path.join( self.tmp_dir, name, 'preview.png'))).replace('\n', '