Merge branch 'emoticons' into 'gtk3'
Emoticons Version 2.0.0 See merge request !26
This commit is contained in:
@@ -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('<body '):
|
||||
desc = '<body xmlns=\'http://www.w3.org/1999/xhtml\'>' + \
|
||||
desc + ' </body>'
|
||||
desc = desc.replace('preview.image', ('file:' + os.path.join(
|
||||
self.tmp_dir, name, 'preview.png'))).replace('\n', '<br/>')
|
||||
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):
|
||||
@@ -205,8 +188,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 +209,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,21 +229,23 @@ 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:
|
||||
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()
|
||||
@@ -274,8 +259,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')
|
||||
@@ -299,7 +283,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,31 +297,27 @@ 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)
|
||||
|
||||
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()
|
||||
desc = _(model.get_value(iter, C_DESCRIPTION))
|
||||
self.emoticons_description_textview.get_buffer().set_text('')
|
||||
desc = _(model.get_value(iter, Column.DESCRIPTION))
|
||||
if not desc.startswith('<body '):
|
||||
desc = '<body xmlns=\'http://www.w3.org/1999/xhtml\'>' + \
|
||||
desc + ' </body>'
|
||||
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)
|
||||
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('')
|
||||
@@ -356,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)
|
||||
|
||||
@@ -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 <fominde@gmail.com>
|
||||
homepage: http://trac-plugins.gajim.org/wiki/PluginInstallerPlugin
|
||||
homepage: https://dev.gajim.org/gajim/gajim-plugins/wikis/EmoticonPackPlugin
|
||||
min_gajim_version: 0.16.10
|
||||
|
||||
Reference in New Issue
Block a user