[emoticons] Use IntEnum

This commit is contained in:
Philipp Hörist
2017-02-28 18:28:01 +01:00
parent a47842a42a
commit 7f166dcd80

View File

@@ -13,7 +13,7 @@ import tempfile
from shutil import rmtree from shutil import rmtree
import sys import sys
import imp import imp
from enum import IntEnum
from common import gajim from common import gajim
from plugins import GajimPlugin from plugins import GajimPlugin
from plugins.helpers import log_calls from plugins.helpers import log_calls
@@ -21,14 +21,15 @@ from htmltextview import HtmlTextView
from conversation_textview import ConversationTextview from conversation_textview import ConversationTextview
from dialogs import WarningDialog, HigDialog from dialogs import WarningDialog, HigDialog
(
C_PIXBUF, class Column(IntEnum):
C_NAME, PIXBUF = 0
C_DESCRIPTION, NAME = 1
C_AUTHORS, DESCRIPTION = 2
C_CONVERTER, AUTHORS = 3
C_HOMEPAGE, CONVERTER = 4
C_UPGRADE) = range(7) HOMEPAGE = 5
UPGRADE = 6
class EmoticonsPackPlugin(GajimPlugin): class EmoticonsPackPlugin(GajimPlugin):
@@ -104,9 +105,9 @@ class EmoticonsPackPlugin(GajimPlugin):
col = Gtk.TreeViewColumn(_('Name')) col = Gtk.TreeViewColumn(_('Name'))
cell = Gtk.CellRendererPixbuf() cell = Gtk.CellRendererPixbuf()
col.pack_start(cell, False) 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.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_property('expand', True)
col.set_sizing(Gtk.TreeViewColumnSizing.GROW_ONLY) col.set_sizing(Gtk.TreeViewColumnSizing.GROW_ONLY)
self.available_treeview.append_column(col) self.available_treeview.append_column(col)
@@ -115,7 +116,7 @@ class EmoticonsPackPlugin(GajimPlugin):
renderer.set_property('activatable', True) renderer.set_property('activatable', True)
renderer.connect('toggled', self.available_emoticons_toggled_cb) renderer.connect('toggled', self.available_emoticons_toggled_cb)
col = Gtk.TreeViewColumn( col = Gtk.TreeViewColumn(
_('Install /\nUpgrade'), renderer, active=C_UPGRADE) _('Install /\nUpgrade'), renderer, active=Column.UPGRADE)
col.set_property('expand', False) col.set_property('expand', False)
col.set_resizable(False) col.set_resizable(False)
self.available_treeview.append_column(col) self.available_treeview.append_column(col)
@@ -135,7 +136,7 @@ class EmoticonsPackPlugin(GajimPlugin):
treeview_selection = self.available_treeview.get_selection() treeview_selection = self.available_treeview.get_selection()
model, iter = treeview_selection.get_selected() 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') label = self.xml.get_object('label2')
if label.get_text() == _('Legend'): if label.get_text() == _('Legend'):
@@ -179,7 +180,7 @@ class EmoticonsPackPlugin(GajimPlugin):
sw.add(self.emoticons_description_textview.tv) sw.add(self.emoticons_description_textview.tv)
sw.show_all() sw.show_all()
label.set_text(_('Legend')) label.set_text(_('Legend'))
desc = _(model.get_value(iter, C_DESCRIPTION)) desc = _(model.get_value(iter, Column.DESCRIPTION))
if not desc.startswith('<body '): if not desc.startswith('<body '):
desc = '<body xmlns=\'http://www.w3.org/1999/xhtml\'>' + \ desc = '<body xmlns=\'http://www.w3.org/1999/xhtml\'>' + \
desc + ' </body>' desc + ' </body>'
@@ -205,8 +206,8 @@ class EmoticonsPackPlugin(GajimPlugin):
name_list = [] name_list = []
for i in range(len(self.model)): for i in range(len(self.model)):
if self.model[i][C_UPGRADE]: if self.model[i][Column.UPGRADE]:
name_list.append(self.model[i][C_NAME]) name_list.append(self.model[i][Column.NAME])
for name in name_list: for name in name_list:
# remove dirs # remove dirs
target_dir = os.path.join(gajim.MY_EMOTS_PATH, name) target_dir = os.path.join(gajim.MY_EMOTS_PATH, name)
@@ -226,7 +227,7 @@ class EmoticonsPackPlugin(GajimPlugin):
self.errors += str(e) self.errors += str(e)
# unset all checkbattons # unset all checkbattons
for i in range(len(self.model)): for i in range(len(self.model)):
self.model[i][C_UPGRADE] = False self.model[i][Column.UPGRADE] = False
if self.errors: if self.errors:
WarningDialog( WarningDialog(
@@ -246,12 +247,12 @@ class EmoticonsPackPlugin(GajimPlugin):
del self.page_num del self.page_num
def available_emoticons_toggled_cb(self, cell, path): def available_emoticons_toggled_cb(self, cell, path):
is_active = self.model[path][C_UPGRADE] is_active = self.model[path][Column.UPGRADE]
self.model[path][C_UPGRADE] = not is_active self.model[path][Column.UPGRADE] = not is_active
dir_list = [] dir_list = []
for i in range(len(self.model)): for i in range(len(self.model)):
if self.model[i][C_UPGRADE]: if self.model[i][Column.UPGRADE]:
dir_list.append(self.model[i][C_NAME]) dir_list.append(self.model[i][Column.NAME])
if not dir_list: if not dir_list:
self.inslall_upgrade_button.set_property('sensitive', False) self.inslall_upgrade_button.set_property('sensitive', False)
else: else:
@@ -299,7 +300,7 @@ class EmoticonsPackPlugin(GajimPlugin):
label = self.xml.get_object('label2') label = self.xml.get_object('label2')
label.set_text(_('Legend')) label.set_text(_('Legend'))
if iter: 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): if os.path.isdir(self.tmp_dir):
rmtree(self.tmp_dir, True) rmtree(self.tmp_dir, True)
self.tmp_dir = tempfile.mkdtemp() self.tmp_dir = tempfile.mkdtemp()
@@ -313,12 +314,12 @@ class EmoticonsPackPlugin(GajimPlugin):
myzip.extract(n, path=self.tmp_dir) myzip.extract(n, path=self.tmp_dir)
self.set_name.set_text(set_name) self.set_name.set_text(set_name)
self.authors_label.set_text(model.get_value(iter, C_AUTHORS)) self.authors_label.set_text(model.get_value(iter, Column.AUTHORS))
self.converter_label.set_text(model.get_value(iter, C_CONVERTER)) self.converter_label.set_text(model.get_value(iter, Column.CONVERTER))
self.homepage_linkbutton.set_uri( self.homepage_linkbutton.set_uri(
model.get_value(iter, C_HOMEPAGE)) model.get_value(iter, Column.HOMEPAGE))
self.homepage_linkbutton.set_label( 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 = self.homepage_linkbutton.get_children()[0]
label.set_ellipsize(Pango.EllipsizeMode.END) label.set_ellipsize(Pango.EllipsizeMode.END)
self.homepage_linkbutton.set_property('sensitive', True) self.homepage_linkbutton.set_property('sensitive', True)
@@ -328,7 +329,7 @@ class EmoticonsPackPlugin(GajimPlugin):
sw = self.xml.get_object('scrolledwindow1') sw = self.xml.get_object('scrolledwindow1')
sw.add(self.emoticons_description_textview.tv) sw.add(self.emoticons_description_textview.tv)
sw.show_all() sw.show_all()
desc = _(model.get_value(iter, C_DESCRIPTION)) desc = _(model.get_value(iter, Column.DESCRIPTION))
if not desc.startswith('<body '): if not desc.startswith('<body '):
desc = '<body xmlns=\'http://www.w3.org/1999/xhtml\'>' + \ desc = '<body xmlns=\'http://www.w3.org/1999/xhtml\'>' + \
desc + ' </body>' desc + ' </body>'