[rostertweaks] Fix some Bugs

- pylint/pep8
- Fix show/hide menubar
- Fix send status
- Update glade file to Gtk 3.18
This commit is contained in:
Philipp Hörist
2017-10-17 23:35:19 +02:00
parent 55c3cf781c
commit b96cb2ee2b
2 changed files with 71 additions and 72 deletions

View File

@@ -1,11 +1,13 @@
<?xml version="1.0"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<interface> <interface>
<requires lib="gtk+" version="2.16"/> <requires lib="gtk+" version="3.18"/>
<!-- interface-naming-policy toplevel-contextual -->
<object class="GtkWindow" id="window1"> <object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child> <child>
<object class="GtkVBox" id="roster_tweaks_config_vbox"> <object class="GtkBox" id="roster_tweaks_config_vbox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">9</property> <property name="border_width">9</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="spacing">4</property> <property name="spacing">4</property>
@@ -14,13 +16,14 @@
<property name="label" translatable="yes">Hide status combobox</property> <property name="label" translatable="yes">Hide status combobox</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="focus_on_click">False</property> <property name="focus_on_click">False</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
<signal name="toggled" handler="on_hide_combo_toggled"/> <signal name="toggled" handler="on_hide_combo_toggled" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
@@ -29,13 +32,14 @@
<property name="label" translatable="yes">Use Ctrl +M to hide/show menu</property> <property name="label" translatable="yes">Use Ctrl +M to hide/show menu</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="focus_on_click">False</property> <property name="focus_on_click">False</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
<signal name="toggled" handler="on_use_ctr_m_toggled"/> <signal name="toggled" handler="on_use_ctr_m_toggled" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
@@ -44,13 +48,14 @@
<property name="label" translatable="yes">Show quick-change status field</property> <property name="label" translatable="yes">Show quick-change status field</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="focus_on_click">False</property> <property name="focus_on_click">False</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
<signal name="toggled" handler="on_quick_status_toggled"/> <signal name="toggled" handler="on_quick_status_toggled" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
@@ -59,13 +64,14 @@
<property name="label" translatable="yes">Always show contacts status substrings</property> <property name="label" translatable="yes">Always show contacts status substrings</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="focus_on_click">False</property> <property name="focus_on_click">False</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
<signal name="toggled" handler="on_contact_status_subs_toggled"/> <signal name="toggled" handler="on_contact_status_subs_toggled" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property> <property name="position">3</property>
</packing> </packing>
</child> </child>
@@ -73,17 +79,21 @@
</child> </child>
</object> </object>
<object class="GtkWindow" id="window2"> <object class="GtkWindow" id="window2">
<property name="can_focus">False</property>
<child> <child>
<object class="GtkHBox" id="hbox1"> <object class="GtkBox" id="hbox1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<child> <child>
<object class="GtkEntry" id="status_entry"> <object class="GtkEntry" id="status_entry">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property> <property name="invisible_char"></property>
<signal name="key_press_event" handler="status_changed"/> <signal name="key-press-event" handler="status_changed" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
@@ -93,12 +103,13 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="relief">none</property> <property name="relief">none</property>
<signal name="clicked" handler="on_activity_button_clicked"/> <signal name="clicked" handler="on_activity_button_clicked" swapped="no"/>
<child> <child>
<object class="GtkImage" id="activity_image"> <object class="GtkImage" id="activity_image">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-stop</property> <property name="stock">gtk-stop</property>
<property name="icon-size">1</property> <property name="icon_size">1</property>
</object> </object>
</child> </child>
</object> </object>
@@ -114,12 +125,13 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="relief">none</property> <property name="relief">none</property>
<signal name="clicked" handler="on_mood_button_clicked"/> <signal name="clicked" handler="on_mood_button_clicked" swapped="no"/>
<child> <child>
<object class="GtkImage" id="mood_image"> <object class="GtkImage" id="mood_image">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-stop</property> <property name="stock">gtk-stop</property>
<property name="icon-size">1</property> <property name="icon_size">1</property>
</object> </object>
</child> </child>
</object> </object>

View File

@@ -3,27 +3,20 @@
from gi.repository import Pango from gi.repository import Pango
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import GObject from gi.repository import GLib
from gajim.common import app, ged, helpers, pep from gajim.common import app, ged, helpers
from gajim.plugins import GajimPlugin from gajim.plugins import GajimPlugin
from gajim.plugins.helpers import log_calls
from gajim.plugins.gui import GajimPluginConfigDialog from gajim.plugins.gui import GajimPluginConfigDialog
from gajim.dialogs import ChangeActivityDialog, ChangeMoodDialog from gajim.dialogs import ChangeActivityDialog, ChangeMoodDialog
from gajim import gtkgui_helpers from gajim import gtkgui_helpers
class RosterTweaksPlugin(GajimPlugin): class RosterTweaksPlugin(GajimPlugin):
@log_calls('RosterTweaksPlugin')
def init(self): def init(self):
self.description = _('Allows user to tweak roster window appearance ' self.description = _(
'(eg. make it compact).\nBased on ticket #3340:\n' 'Allows user to tweak roster window appearance '
'http://trac.gajim.org/ticket/3340.\n' '(eg. make it compact).')
'Added ability to quickly change the status message '
'to all connected accounts.\n'
'Based on ticket #5085:\n'
'http://trac.gajim.org/ticket/5085.')
self.config_default_values = {'hide_status_combo': (False, ''), self.config_default_values = {'hide_status_combo': (False, ''),
'use_ctr_m': (False, ''), 'use_ctr_m': (False, ''),
'menu_visible': (True, ''), 'menu_visible': (True, ''),
@@ -43,15 +36,15 @@ class RosterTweaksPlugin(GajimPlugin):
return return
if not self.config['contact_status_subs']: if not self.config['contact_status_subs']:
return return
child_iters = roster._get_contact_iter(jid, account, contact, child_iters = roster._get_contact_iter(
roster.model) jid, account, contact, roster.model)
if not child_iters: if not child_iters:
return return
name = roster.model[child_iters[0]][1] name = roster.model[child_iters[0]][1]
if '\n<span ' not in name: if '\n<span ' not in name:
roster.model[child_iters[0]][1] = name + '\n' roster.model[child_iters[0]][1] = name + '\n'
def disconnect_roster_draw_contact(self, roster,jid, account, contact): def disconnect_roster_draw_contact(self, *args):
if self.connected: if self.connected:
self.roster.setup_and_draw_roster() self.roster.setup_and_draw_roster()
self.connected = False self.connected = False
@@ -76,14 +69,13 @@ class RosterTweaksPlugin(GajimPlugin):
else: else:
img.set_from_stock('gtk-stop', Gtk.IconSize.MENU) img.set_from_stock('gtk-stop', Gtk.IconSize.MENU)
def our_show(self, obj): def our_show(self, *args):
if self.active: if self.active:
if helpers.get_global_show() != app.SHOW_LIST[0]: if helpers.get_global_show() != app.SHOW_LIST[0]:
self.status_widget.set_text(helpers.get_global_status()) self.status_widget.set_text(helpers.get_global_status())
else: else:
self.status_widget.set_text('') self.status_widget.set_text('')
@log_calls('RosterTweaksPlugin')
def activate(self): def activate(self):
self.pep_dict = {} self.pep_dict = {}
self.roster.status_combobox.set_property('visible', not self.config[ self.roster.status_combobox.set_property('visible', not self.config[
@@ -118,33 +110,26 @@ class RosterTweaksPlugin(GajimPlugin):
window = self.roster.window window = self.roster.window
self.accel_group = Gtk.accel_groups_from_object(window)[0] self.accel_group = Gtk.accel_groups_from_object(window)[0]
self.accel_group.connect(Gdk.KEY_m, self.accel_group.connect(Gdk.KEY_m,
Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.MASK, Gdk.ModifierType.CONTROL_MASK,
Gtk.AccelFlags.MASK,
self.on_ctrl_m) self.on_ctrl_m)
self.config['menu_visible'] = not self.config['menu_visible'] self.config['menu_visible'] = not self.config['menu_visible']
self.on_ctrl_m(None, None, None, None) self.on_ctrl_m()
@log_calls('RosterTweaksPlugin')
def deactivate(self): def deactivate(self):
self.roster.status_combobox.show() self.roster.status_combobox.show()
self.status_widget.destroy() self.status_widget.destroy()
self.activity_button.destroy() self.activity_button.destroy()
self.mood_button.destroy() self.mood_button.destroy()
self.roster.xml.get_object('menubar').set_size_request(-1, -1) self.roster.window.set_show_menubar(True)
def on_ctrl_m(self, accel_group, acceleratable, keyval, modifier): def on_ctrl_m(self, *args):
menubar = self.roster.xml.get_object('menubar') self.roster.window.set_show_menubar(self.config['menu_visible'])
if not self.config['menu_visible']:
#menubar.set_size_request(-1, -1)
menubar.hide()
else:
menubar.show()
#menubar.set_size_request(-1, -1)
self.config['menu_visible'] = not self.config['menu_visible'] self.config['menu_visible'] = not self.config['menu_visible']
return True return True
def status_changed(self, widget, event): def status_changed(self, widget, event):
if event.keyval == gtk.keysyms.Return or \ if event.keyval in (Gdk.KEY_Return, Gdk.KEY_KP_Enter):
event.keyval == gtk.keysyms.KP_Enter:
accounts = app.connections.keys() accounts = app.connections.keys()
message = widget.get_text() message = widget.get_text()
for account in accounts: for account in accounts:
@@ -153,10 +138,10 @@ class RosterTweaksPlugin(GajimPlugin):
current_show = app.SHOW_LIST[ current_show = app.SHOW_LIST[
app.connections[account].connected] app.connections[account].connected]
self.roster.send_status(account, current_show, message) self.roster.send_status(account, current_show, message)
self.font_desc.set_weight(pango.WEIGHT_BOLD) self.font_desc.set_weight(Pango.Weight.BOLD)
widget.modify_font(self.font_desc) widget.modify_font(self.font_desc)
self.font_desc.set_weight(pango.WEIGHT_NORMAL) self.font_desc.set_weight(Pango.Weight.NORMAL)
gobject.timeout_add(1000, widget.modify_font, self.font_desc) GLib.timeout_add(1000, widget.modify_font, self.font_desc)
def on_activity_button_clicked(self, widget): def on_activity_button_clicked(self, widget):
def on_response(activity, subactivity, text): def on_response(activity, subactivity, text):
@@ -164,7 +149,8 @@ class RosterTweaksPlugin(GajimPlugin):
self.pep_dict['subactivity'] = subactivity or '' self.pep_dict['subactivity'] = subactivity or ''
self.pep_dict['activity_text'] = text self.pep_dict['activity_text'] = text
self.send_pep() self.send_pep()
ChangeActivityDialog(on_response, self.pep_dict.get('activity', None), ChangeActivityDialog(on_response,
self.pep_dict.get('activity', None),
self.pep_dict.get('subactivity', None), self.pep_dict.get('subactivity', None),
self.pep_dict.get('activity_text', None)) self.pep_dict.get('activity_text', None))
@@ -173,7 +159,8 @@ class RosterTweaksPlugin(GajimPlugin):
self.pep_dict['mood'] = mood or '' self.pep_dict['mood'] = mood or ''
self.pep_dict['mood_text'] = text self.pep_dict['mood_text'] = text
self.send_pep() self.send_pep()
ChangeMoodDialog(on_response, self.pep_dict.get('mood', None), ChangeMoodDialog(on_response,
self.pep_dict.get('mood', None),
self.pep_dict.get('mood_text', None)) self.pep_dict.get('mood_text', None))
def send_pep(self): def send_pep(self):
@@ -189,8 +176,8 @@ class RosterTweaksPluginConfigDialog(GajimPluginConfigDialog):
'config_dialog.ui') 'config_dialog.ui')
self.xml = Gtk.Builder() self.xml = Gtk.Builder()
self.xml.set_translation_domain('gajim_plugins') self.xml.set_translation_domain('gajim_plugins')
self.xml.add_objects_from_file(self.GTK_BUILDER_FILE_PATH, self.xml.add_objects_from_file(
['roster_tweaks_config_vbox']) self.GTK_BUILDER_FILE_PATH, ['roster_tweaks_config_vbox'])
self.config_vbox = self.xml.get_object('roster_tweaks_config_vbox') self.config_vbox = self.xml.get_object('roster_tweaks_config_vbox')
self.get_child().pack_start(self.config_vbox, True, True, 0) self.get_child().pack_start(self.config_vbox, True, True, 0)
@@ -210,8 +197,8 @@ class RosterTweaksPluginConfigDialog(GajimPluginConfigDialog):
def on_hide_combo_toggled(self, button): def on_hide_combo_toggled(self, button):
self.plugin.config['hide_status_combo'] = button.get_active() self.plugin.config['hide_status_combo'] = button.get_active()
self.plugin.roster.status_combobox.set_property('visible', not \ self.plugin.roster.status_combobox.set_property(
self.plugin.config['hide_status_combo']) 'visible', not self.plugin.config['hide_status_combo'])
def on_quick_status_toggled(self, button): def on_quick_status_toggled(self, button):
self.plugin.config['quick_status'] = button.get_active() self.plugin.config['quick_status'] = button.get_active()
@@ -228,10 +215,10 @@ class RosterTweaksPluginConfigDialog(GajimPluginConfigDialog):
if is_ctr_m_enabled: if is_ctr_m_enabled:
self.plugin.enable_ctrl_m() self.plugin.enable_ctrl_m()
else: else:
self.plugin.accel_group.disconnect_key(Gdk.KEY_m, self.plugin.accel_group.disconnect_key(
Gdk.ModifierType.CONTROL_MASK) Gdk.KEY_m, Gdk.ModifierType.CONTROL_MASK)
self.plugin.config['menu_visible'] = True self.plugin.config['menu_visible'] = True
self.plugin.roster.xml.get_object('menubar').set_size_request(-1, -1) self.plugin.roster.window.set_show_menubar(True)
def on_contact_status_subs_toggled(self, button): def on_contact_status_subs_toggled(self, button):
self.plugin.config['contact_status_subs'] = button.get_active() self.plugin.config['contact_status_subs'] = button.get_active()