Commit 82027d11 authored by Yann Leboulanger's avatar Yann Leboulanger

[flashing_keyboard] add an option to just light on the LED. Fixes #52

parent 87e70032
......@@ -7,7 +7,7 @@
<object class="GtkTable" id="config_table">
<property name="visible">True</property>
<property name="border_width">6</property>
<property name="n_rows">2</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>
......@@ -45,7 +45,7 @@
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="y_options"></property>
<property name="y_options"/>
</packing>
</child>
<child>
......@@ -59,9 +59,28 @@
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="flash_cb">
<property name="label" translatable="yes">Do not flash the LED, only switch it on.</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"/>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
......
......@@ -17,7 +17,9 @@ class FlashingKeyboard(GajimPlugin):
self.config_dialog = FlashingKeyboardPluginConfigDialog(self)
self.config_default_values = {
'command1': ("xset led named 'Scroll Lock'", ''),
'command2': ("xset -led named 'Scroll Lock'", '')}
'command2': ("xset -led named 'Scroll Lock'", ''),
'flash': (True, ''),
}
self.is_active = None
self.timeout = 500
......@@ -35,15 +37,22 @@ class FlashingKeyboard(GajimPlugin):
if gajim.events.get_nb_systray_events():
if self.id_0:
return
self.id_0 = GObject.timeout_add(self.timeout, self.led_on)
if self.config['flash']:
self.id_0 = GObject.timeout_add(self.timeout, self.led_on)
else:
self.led_on()
self.id_0 = True
else:
if self.id_0:
GObject.source_remove(self.id_0)
if self.config['flash']:
GObject.source_remove(self.id_0)
self.id_0 = None
self.led_off()
def led_on(self):
subprocess.Popen('%s' % self.config['command1'], shell=True).wait()
GObject.timeout_add(self.timeout_off, self.led_off)
if self.config['flash']:
GObject.timeout_add(self.timeout_off, self.led_off)
return True
def led_off(self):
......@@ -54,7 +63,11 @@ class FlashingKeyboard(GajimPlugin):
gajim.events.event_added_subscribe(self.on_event_added)
gajim.events.event_removed_subscribe(self.on_event_removed)
if gajim.events.get_nb_systray_events():
self.id_0 = GObject.timeout_add(self.timeout, self.led_on)
if self.config['flash']:
self.id_0 = GObject.timeout_add(self.timeout, self.led_on)
else:
self.led_on()
self.id_0 = True
@log_calls('FlashingKeyboard')
def deactivate(self):
......@@ -62,6 +75,7 @@ class FlashingKeyboard(GajimPlugin):
gajim.events.event_removed_unsubscribe(self.on_event_removed)
if self.id_0:
GObject.source_remove(self.id_0)
self.led_off()
class FlashingKeyboardPluginConfigDialog(GajimPluginConfigDialog):
......@@ -81,14 +95,18 @@ class FlashingKeyboardPluginConfigDialog(GajimPluginConfigDialog):
self.isactive = self.plugin.active
if self.plugin.active:
gajim.plugin_manager.deactivate_plugin(self.plugin)
for name in self.plugin.config_default_values:
for name in ('command1', 'command2'):
widget = self.xml.get_object(name)
widget.set_text(self.plugin.config[name])
widget = self.xml.get_object('flash_cb')
widget.set_active(not self.plugin.config['flash'])
def on_close_button_clicked(self, widget):
widget = self.xml.get_object('command1')
self.plugin.config['command1'] = widget.get_text()
widget = self.xml.get_object('command2')
self.plugin.config['command2'] = widget.get_text()
widget = self.xml.get_object('flash_cb')
self.plugin.config['flash'] = not widget.get_active()
if self.isactive:
gajim.plugin_manager.activate_plugin(self.plugin)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment