[message_box_size] Rewrite plugin
- Much simpler code - New config dialog
This commit is contained in:
40
message_box_size/config_dialog.py
Normal file
40
message_box_size/config_dialog.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from gi.repository import GObject
|
||||
from gi.repository import Gtk
|
||||
|
||||
from gajim.gtk.settings import SettingsDialog
|
||||
from gajim.gtk.settings import SpinSetting
|
||||
from gajim.gtk.const import Setting
|
||||
from gajim.gtk.const import SettingType
|
||||
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
|
||||
|
||||
class MessageBoxSizeConfigDialog(SettingsDialog):
|
||||
def __init__(self, plugin, parent):
|
||||
|
||||
self.plugin = plugin
|
||||
settings = [
|
||||
Setting('PreviewSizeSpinSetting', _('Height in pixels'),
|
||||
SettingType.VALUE, self.plugin.config['HEIGHT'],
|
||||
callback=self.on_setting, data='HEIGHT',
|
||||
desc=_('Size of message input in pixels'),
|
||||
props={'range_': (20, 200)}),
|
||||
]
|
||||
|
||||
SettingsDialog.__init__(self, parent, _('Message Box Size Configuration'),
|
||||
Gtk.DialogFlags.MODAL, settings, None,
|
||||
extend=[('PreviewSizeSpinSetting',
|
||||
SizeSpinSetting)])
|
||||
|
||||
def on_setting(self, value, data):
|
||||
self.plugin.config[data] = value
|
||||
|
||||
|
||||
class SizeSpinSetting(SpinSetting):
|
||||
|
||||
__gproperties__ = {
|
||||
"setting-value": (int, 'Size', '', 20, 200, 20,
|
||||
GObject.ParamFlags.READWRITE), }
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
SpinSetting.__init__(self, *args, **kwargs)
|
||||
@@ -1,77 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<interface>
|
||||
<requires lib="gtk+" version="2.16"/>
|
||||
<!-- interface-naming-policy toplevel-contextual -->
|
||||
<object class="GtkWindow" id="window1">
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox3">
|
||||
<property name="visible">True</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox1">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="message_box_size_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0.029999999329447746</property>
|
||||
<property name="label" translatable="yes">Minimum lines</property>
|
||||
<property name="ellipsize">start</property>
|
||||
<property name="track_visited_links">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSpinButton" id="minimum_lines">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="invisible_char">●</property>
|
||||
<property name="width_chars">6</property>
|
||||
<property name="snap_to_ticks">True</property>
|
||||
<property name="numeric">True</property>
|
||||
<signal name="value_changed" handler="on_minimum_lines_value_changed"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="checkbutton">
|
||||
<property name="label" translatable="yes">Do not resize input message field</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<signal name="toggled" handler="on_checkbutton_toggled"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
@@ -1,97 +1,25 @@
|
||||
from gi.repository import Gtk
|
||||
from functools import partial
|
||||
|
||||
from gajim.plugins import GajimPlugin
|
||||
from gajim.plugins.helpers import log_calls
|
||||
from gajim.plugins.gui import GajimPluginConfigDialog
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
from message_box_size.config_dialog import MessageBoxSizeConfigDialog
|
||||
|
||||
|
||||
class MsgBoxSizePlugin(GajimPlugin):
|
||||
@log_calls('MsgBoxSizePlugin')
|
||||
def init(self):
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
self.description = _('Allows you to adjust the height'
|
||||
' of the new message input field.')
|
||||
self.config_dialog = MsgBoxSizePluginConfigDialog(self)
|
||||
' of the message input.')
|
||||
self.config_dialog = partial(MessageBoxSizeConfigDialog, self)
|
||||
self.gui_extension_points = {
|
||||
'chat_control_base': (self.connect_with_chat_control,
|
||||
self.disconnect_from_chat_control)}
|
||||
self.config_default_values = {'Do_not_resize': (False, ''),
|
||||
'Minimum_lines': (2, ''),}
|
||||
self.chat_control = None
|
||||
self.controls = []
|
||||
'chat_control_base': (self._on_connect_chat_control,
|
||||
self._on_disconnect_chat_control)
|
||||
}
|
||||
self.config_default_values = {'HEIGHT': (20, ''),}
|
||||
|
||||
@log_calls('MsgBoxSizePlugin')
|
||||
def connect_with_chat_control(self, chat_control):
|
||||
self.chat_control = chat_control
|
||||
control = Base(self, self.chat_control)
|
||||
self.controls.append(control)
|
||||
def _on_connect_chat_control(self, control):
|
||||
control.msg_textview.set_size_request(-1, self.config['HEIGHT'])
|
||||
|
||||
@log_calls('MsgBoxSizePlugin')
|
||||
def disconnect_from_chat_control(self, chat_control):
|
||||
for control in self.controls:
|
||||
control.disconnect_from_chat_control()
|
||||
self.controls = []
|
||||
|
||||
|
||||
class Base(object):
|
||||
def __init__(self, plugin, chat_control):
|
||||
tbuffer = chat_control.msg_textview.get_buffer()
|
||||
min_size = chat_control.msg_textview.get_line_yrange(
|
||||
tbuffer.get_start_iter())[1] * plugin.config['Minimum_lines'] + 2
|
||||
|
||||
chat_control.msg_textview.set_property('height-request', min_size)
|
||||
# plugin.config['Minimum_lines'])
|
||||
|
||||
self.id_ = chat_control.msg_textview.connect('size-allocate',
|
||||
self.size_request)
|
||||
chat_control.handlers[self.id_] = chat_control.msg_textview
|
||||
self.chat_control = chat_control
|
||||
self.plugin = plugin
|
||||
|
||||
def size_request(self, msg_textview, requisition):
|
||||
tbuffer = msg_textview.get_buffer()
|
||||
min_size = msg_textview.get_line_yrange(tbuffer.get_start_iter())[1] * \
|
||||
self.plugin.config['Minimum_lines'] + 2
|
||||
|
||||
if self.plugin.config['Do_not_resize']:
|
||||
self.chat_control.msg_scrolledwindow.set_property(
|
||||
'vscrollbar-policy', Gtk.PolicyType.AUTOMATIC)
|
||||
elif requisition.height > min_size:
|
||||
msg_textview.set_property('height-request', requisition.height)
|
||||
else:
|
||||
msg_textview.set_property('height-request', min_size)
|
||||
|
||||
def disconnect_from_chat_control(self):
|
||||
if self.id_ not in self.chat_control.handlers:
|
||||
return
|
||||
if self.chat_control.handlers[self.id_].handler_is_connected(self.id_):
|
||||
self.chat_control.handlers[self.id_].disconnect(self.id_)
|
||||
del self.chat_control.handlers[self.id_]
|
||||
self.chat_control.msg_textview.set_property('height-request', -1)
|
||||
self.chat_control.msg_textview.queue_draw()
|
||||
|
||||
|
||||
class MsgBoxSizePluginConfigDialog(GajimPluginConfigDialog):
|
||||
def init(self):
|
||||
self.GTK_BUILDER_FILE_PATH = self.plugin.local_file_path(
|
||||
'config_dialog.ui')
|
||||
self.xml = Gtk.Builder()
|
||||
self.xml.set_translation_domain('gajim_plugins')
|
||||
self.xml.add_objects_from_file(self.GTK_BUILDER_FILE_PATH, ['vbox1'])
|
||||
self.checkbutton = self.xml.get_object('checkbutton')
|
||||
self.spinbutton = self.xml.get_object('minimum_lines')
|
||||
self.spinbutton.get_adjustment().configure(20, 1, 10, 1, 10, 0)
|
||||
vbox = self.xml.get_object('vbox1')
|
||||
self.get_child().pack_start(vbox, False, False, 0)
|
||||
|
||||
self.xml.connect_signals(self)
|
||||
|
||||
def on_run(self):
|
||||
self.checkbutton.set_active(self.plugin.config['Do_not_resize'])
|
||||
self.spinbutton.set_value(self.plugin.config['Minimum_lines'])
|
||||
|
||||
def on_checkbutton_toggled(self, checkbutton):
|
||||
self.plugin.config['Do_not_resize'] = checkbutton.get_active()
|
||||
|
||||
def on_minimum_lines_value_changed(self, spinbutton):
|
||||
self.plugin.config['Minimum_lines'] = spinbutton.get_value()
|
||||
@staticmethod
|
||||
def _on_disconnect_chat_control(control):
|
||||
control.msg_textview.set_size_request(-1, -1)
|
||||
|
||||
Reference in New Issue
Block a user