diff options
author | Daniel Brötzmann <mailtrash@posteo.de> | 2019-12-16 21:10:50 +0300 |
---|---|---|
committer | Daniel Brötzmann <mailtrash@posteo.de> | 2019-12-21 14:15:12 +0300 |
commit | 048e96fd8cca2c3981d505fcf826cd6e03af06dd (patch) | |
tree | 981b9fb9fb10ccc49e1806344c1149dc531e8be7 /length_notifier | |
parent | 4fadcb5342346198fd5fdbe2db164e36268ba3de (diff) |
[length_notifier] Add character counter
Diffstat (limited to 'length_notifier')
-rw-r--r-- | length_notifier/config_dialog.ui | 181 | ||||
-rw-r--r-- | length_notifier/length_notifier.py | 33 |
2 files changed, 110 insertions, 104 deletions
diff --git a/length_notifier/config_dialog.ui b/length_notifier/config_dialog.ui index f06bfe1..7190f86 100644 --- a/length_notifier/config_dialog.ui +++ b/length_notifier/config_dialog.ui @@ -1,151 +1,126 @@ -<?xml version="1.0"?> +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.22.1 --> <interface> - <requires lib="gtk+" version="2.16"/> - <!-- interface-naming-policy toplevel-contextual --> - <object class="GtkWindow" id="window1"> + <requires lib="gtk+" version="3.20"/> + <object class="GtkWindow"> + <property name="can_focus">False</property> <child> - <object class="GtkTable" id="length_notifier_config_table"> + <object class="GtkGrid" id="length_notifier_config_table"> <property name="visible">True</property> - <property name="border_width">9</property> - <property name="n_rows">3</property> - <property name="n_columns">2</property> - <property name="column_spacing">7</property> - <property name="row_spacing">5</property> + <property name="can_focus">False</property> + <property name="tooltip_text" translatable="yes">Background color of the text entry when the specified message length is exceeded</property> + <property name="halign">center</property> + <property name="border_width">18</property> + <property name="row_spacing">6</property> + <property name="column_spacing">12</property> <child> - <object class="GtkLabel" id="label1"> + <object class="GtkLabel"> <property name="visible">True</property> - <property name="tooltip_text" translatable="yes">Message length at which notification is invoked.</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">Message length:</property> + <property name="can_focus">False</property> + <property name="halign">end</property> + <property name="label" translatable="yes">Message Length</property> + <style> + <class name="dim-label"/> + </style> </object> <packing> - <property name="x_options">GTK_FILL</property> - <property name="y_options">GTK_FILL</property> + <property name="left_attach">0</property> + <property name="top_attach">0</property> </packing> </child> <child> - <object class="GtkLabel" id="label2"> + <object class="GtkSpinButton" id="message_length_spinbutton"> <property name="visible">True</property> - <property name="tooltip_text" translatable="yes">Background color of text entry field in chat window when notification is invoked.</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">Notification color:</property> + <property name="can_focus">True</property> + <property name="tooltip_text" translatable="yes">Message length for the notification to be shown</property> + <property name="halign">start</property> + <property name="width_chars">6</property> + <property name="input_purpose">number</property> + <property name="snap_to_ticks">True</property> + <property name="numeric">True</property> + <signal name="value-changed" handler="on_message_length_spinbutton_value_changed" swapped="no"/> </object> <packing> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options">GTK_FILL</property> + <property name="left_attach">1</property> + <property name="top_attach">0</property> </packing> </child> <child> - <object class="GtkLabel" id="label3"> + <object class="GtkLabel"> <property name="visible">True</property> - <property name="tooltip_text" translatable="yes">JabberIDs that plugin should be used with (eg. restrict only to one microblogging bot). Use comma (without space) as separator. If empty plugin is used with every JID. </property> - <property name="xalign">0</property> - <property name="label" translatable="yes">JabberIDs to include:</property> + <property name="can_focus">False</property> + <property name="halign">end</property> + <property name="label" translatable="yes">XMPP Addresses</property> + <style> + <class name="dim-label"/> + </style> </object> <packing> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options">GTK_FILL</property> + <property name="left_attach">0</property> + <property name="top_attach">3</property> </packing> </child> <child> <object class="GtkEntry" id="jids_entry"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="tooltip_text" translatable="yes">JabberIDs that plugin should be used with (eg. restrict only to one microblogging bot). Use comma (without space) as separator. If empty plugin is used with every JID. </property> - <signal name="editing_done" handler="on_jids_entry_editing_done"/> - <signal name="changed" handler="on_jids_entry_changed"/> + <property name="tooltip_text" translatable="yes">Restrict this plugin to certain contacts, e.g. to one microblogging bot (use comma without space as separator)</property> + <property name="halign">start</property> + <property name="placeholder_text" translatable="yes">user@example.org</property> </object> <packing> <property name="left_attach">1</property> - <property name="right_attach">2</property> + <property name="top_attach">3</property> + </packing> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">end</property> + <property name="label" translatable="yes">Notification Color</property> + <style> + <class name="dim-label"/> + </style> + </object> + <packing> + <property name="left_attach">0</property> <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="y_options">GTK_FILL</property> </packing> </child> <child> - <object class="GtkHBox" id="hbox1"> + <object class="GtkColorButton" id="notification_colorbutton"> <property name="visible">True</property> - <child> - <object class="GtkColorButton" id="notification_colorbutton"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="tooltip_text" translatable="yes">Background color of text entry field in chat window when notification is invoked.</property> - <property name="xalign">0</property> - <property name="title" translatable="yes">Pick a color for notification</property> - <property name="color">#000000000000</property> - <signal name="color_set" handler="on_notification_colorbutton_color_set"/> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkAlignment" id="alignment1"> - <property name="visible">True</property> - <child> - <placeholder/> - </child> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="tooltip_text" translatable="yes">Background color of the message input when the specified message length is reached</property> + <property name="halign">start</property> + <property name="title" translatable="yes">Pick a color for notification</property> </object> <packing> <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options"></property> + <property name="top_attach">2</property> </packing> </child> <child> - <object class="GtkHBox" id="hbox2"> + <object class="GtkCheckButton" id="char_counter"> + <property name="label" translatable="yes">Show Character Count</property> <property name="visible">True</property> - <child> - <object class="GtkSpinButton" id="message_length_spinbutton"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="tooltip_text" translatable="yes">Message length at which notification is invoked.</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_message_length_spinbutton_value_changed"/> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkAlignment" id="alignment2"> - <property name="visible">True</property> - <child> - <placeholder/> - </child> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="tooltip_text" translatable="yes">Adds a character counter to the message input</property> + <property name="halign">start</property> + <property name="draw_indicator">True</property> + <signal name="toggled" handler="_on_char_counter_toggled" swapped="no"/> </object> <packing> <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options">GTK_FILL</property> + <property name="top_attach">1</property> </packing> </child> + <child> + <placeholder/> + </child> </object> </child> </object> diff --git a/length_notifier/length_notifier.py b/length_notifier/length_notifier.py index 1cad8d0..649af5e 100644 --- a/length_notifier/length_notifier.py +++ b/length_notifier/length_notifier.py @@ -48,6 +48,7 @@ class LengthNotifierPlugin(GajimPlugin): self.config_default_values = { 'MESSAGE_WARNING_LENGTH' : (140, 'Message length at which notification is invoked.'), + 'CHAR_COUNTER': (True, 'Show character count'), 'WARNING_COLOR' : ('#F0DB3E', 'Background color of text entry field in chat window when notification is invoked.'), 'JIDS' : ([], 'JabberIDs that plugin should be used with (eg. restrict only to one microblogging bot). If empty plugin is used with every JID. [not implemented]') } @@ -56,9 +57,12 @@ class LengthNotifierPlugin(GajimPlugin): def textview_length_warning(self, tb, chat_control): tv = chat_control.msg_textview d = chat_control.length_notifier_plugin_data + if not tv.has_text(): + self.counter.set_text('0') if tv.has_text(): t = tb.get_text(tb.get_start_iter(), tb.get_end_iter(), True) len_t = len(t) + self.counter.set_text(str(len_t)) if len_t > self.config['MESSAGE_WARNING_LENGTH']: if not d['prev_color']: #FIXME: That doesn't work @@ -80,6 +84,7 @@ class LengthNotifierPlugin(GajimPlugin): def connect_with_chat_control(self, chat_control): jid = chat_control.contact.jid if self.jid_is_ok(jid): + self._create_counter(chat_control) d = {'prev_color' : None} tv = chat_control.msg_textview tb = tv.get_buffer() @@ -90,6 +95,7 @@ class LengthNotifierPlugin(GajimPlugin): if tv.has_text(): t = tb.get_text(tb.get_start_iter(), tb.get_end_iter(), True) len_t = len(t) + self.counter.set_text(str(len_t)) if len_t > self.config['MESSAGE_WARNING_LENGTH']: context = tv.get_style_context() d['prev_color'] = context.get_background_color( @@ -97,7 +103,8 @@ class LengthNotifierPlugin(GajimPlugin): color = Gdk.RGBA() Gdk.RGBA.parse(color, self.config['WARNING_COLOR']) tv.override_background_color(Gtk.StateType.NORMAL, color) - + else: + self.counter.set_text('0') chat_control.length_notifier_plugin_data = d return True @@ -107,6 +114,8 @@ class LengthNotifierPlugin(GajimPlugin): @log_calls('LengthNotifierPlugin') def disconnect_from_chat_control(self, chat_control): try: + actions_hbox = chat_control.xml.get_object('hbox') + actions_hbox.remove(self.counter) d = chat_control.length_notifier_plugin_data tv = chat_control.msg_textview tv.get_buffer().disconnect(d['h_id']) @@ -124,6 +133,22 @@ class LengthNotifierPlugin(GajimPlugin): return False + def _create_counter(self, chat_control): + actions_hbox = chat_control.xml.get_object('hbox') + self.counter = Gtk.Label() + self.counter.set_tooltip_text(_('Number of typed characters')) + self.counter.get_style_context().add_class('dim-label') + self.counter.set_no_show_all(True) + actions_hbox.pack_start(self.counter, False, False, 0) + self.toggle_counter() + + def toggle_counter(self): + if self.config['CHAR_COUNTER']: + self.counter.show() + else: + self.counter.hide() + + class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog): def init(self): self.GTK_BUILDER_FILE_PATH = self.plugin.local_file_path( @@ -139,6 +164,7 @@ class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog): 'message_length_spinbutton') self.message_length_spinbutton.get_adjustment().configure(140, 0, 500, 1, 10, 0) + self.char_counter = self.xml.get_object('char_counter') self.notification_colorbutton = self.xml.get_object( 'notification_colorbutton') self.jids_entry = self.xml.get_object('jids_entry') @@ -149,6 +175,7 @@ class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog): self.message_length_spinbutton.set_value(self.plugin.config[ 'MESSAGE_WARNING_LENGTH']) color = Gdk.Color.parse(self.plugin.config['WARNING_COLOR'])[1] + self.char_counter.set_active(self.plugin.config['CHAR_COUNTER']) self.notification_colorbutton.set_color(color) #self.jids_entry.set_text(self.plugin.config['JIDS']) self.jids_entry.set_text(','.join(self.plugin.config['JIDS'])) @@ -157,6 +184,10 @@ class LengthNotifierPluginConfigDialog(GajimPluginConfigDialog): def on_message_length_spinbutton_value_changed(self, spinbutton): self.plugin.config['MESSAGE_WARNING_LENGTH'] = spinbutton.get_value() + def _on_char_counter_toggled(self, checkbutton): + self.plugin.config['CHAR_COUNTER'] = checkbutton.get_active() + self.plugin.toggle_counter() + @log_calls('LengthNotifierPluginConfigDialog') def on_notification_colorbutton_color_set(self, colorbutton): self.plugin.config['WARNING_COLOR'] = colorbutton.get_color().\ |