flashing_keyboard
This commit is contained in:
1
flashing_keyboard/__init__.py
Normal file
1
flashing_keyboard/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from flashing_keyboard import FlashingKeyboard
|
||||
68
flashing_keyboard/config_dialog.ui
Normal file
68
flashing_keyboard/config_dialog.ui
Normal file
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0"?>
|
||||
<interface>
|
||||
<requires lib="gtk+" version="2.16"/>
|
||||
<!-- interface-naming-policy toplevel-contextual -->
|
||||
<object class="GtkWindow" id="window1">
|
||||
<child>
|
||||
<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_columns">2</property>
|
||||
<property name="column_spacing">7</property>
|
||||
<property name="row_spacing">5</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label1">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">command 1:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label2">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="label" translatable="yes">command 2:</property>
|
||||
</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>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="command1">
|
||||
<property name="width_request">300</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="invisible_char">●</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="command2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="invisible_char">●</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="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
92
flashing_keyboard/flashing_keyboard.py
Normal file
92
flashing_keyboard/flashing_keyboard.py
Normal file
@@ -0,0 +1,92 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import gtk
|
||||
import subprocess
|
||||
import gobject
|
||||
|
||||
from common import gajim
|
||||
from plugins import GajimPlugin
|
||||
from plugins.helpers import log_calls, log
|
||||
from plugins.gui import GajimPluginConfigDialog
|
||||
|
||||
|
||||
class FlashingKeyboard(GajimPlugin):
|
||||
@log_calls('FlashingKeyboard')
|
||||
def init(self):
|
||||
self.config_dialog = FlashingKeyboardPluginConfigDialog(self)
|
||||
self.config_default_values = {
|
||||
'command1': ("xset led named 'Scroll Lock'",''),
|
||||
'command2': ("xset -led named 'Scroll Lock'", '')}
|
||||
|
||||
self.is_active = None
|
||||
self.timeout = 500
|
||||
self.timeout_off = self.timeout / 2
|
||||
self.id_0 = None
|
||||
|
||||
def on_event_added(self, event):
|
||||
if event.show_in_systray:
|
||||
self.flash_trigger()
|
||||
|
||||
def on_event_removed(self, event_list):
|
||||
self.flash_trigger()
|
||||
|
||||
def flash_trigger(self):
|
||||
if gajim.events.get_nb_systray_events():
|
||||
if self.id_0:
|
||||
return
|
||||
self.id_0 = gobject.timeout_add(self.timeout, self.led_on)
|
||||
else:
|
||||
if self.id_0:
|
||||
gobject.source_remove(self.id_0)
|
||||
self.id_0 = None
|
||||
|
||||
def led_on(self):
|
||||
subprocess.Popen('%s' % self.config['command1'], shell=True).wait()
|
||||
gobject.timeout_add(self.timeout_off, self.led_off)
|
||||
return True
|
||||
|
||||
def led_off(self):
|
||||
subprocess.Popen('%s' % self.config['command2'], shell=True).wait()
|
||||
|
||||
@log_calls('FlashingKeyboard')
|
||||
def activate(self):
|
||||
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)
|
||||
|
||||
@log_calls('FlashingKeyboard')
|
||||
def deactivate(self):
|
||||
gajim.events.event_added_unsubscribe(self.on_event_added)
|
||||
gajim.events.event_removed_unsubscribe(self.on_event_removed)
|
||||
if self.id_0:
|
||||
gobject.source_remove(self.id_0)
|
||||
|
||||
class FlashingKeyboardPluginConfigDialog(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('flashingkeyboard')
|
||||
self.xml.add_objects_from_file(self.GTK_BUILDER_FILE_PATH,
|
||||
['config_table'])
|
||||
config_table = self.xml.get_object('config_table')
|
||||
self.child.pack_start(config_table)
|
||||
self.xml.connect_signals(self)
|
||||
self.connect('hide', self.on_close_button_clicked)
|
||||
|
||||
def on_run(self):
|
||||
self.isactive = self.plugin.active
|
||||
if self.plugin.active:
|
||||
gajim.plugin_manager.deactivate_plugin(self.plugin)
|
||||
for name in self.plugin.config_default_values:
|
||||
widget = self.xml.get_object(name)
|
||||
widget.set_text(self.plugin.config[name])
|
||||
|
||||
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()
|
||||
if self.isactive:
|
||||
gajim.plugin_manager.activate_plugin(self.plugin)
|
||||
8
flashing_keyboard/manifest.ini
Normal file
8
flashing_keyboard/manifest.ini
Normal file
@@ -0,0 +1,8 @@
|
||||
[info]
|
||||
name: Flashing Keyboard
|
||||
short_name: flashing_keyboard
|
||||
version: 0.1
|
||||
description: Flashing keyboard led if there is unread messages
|
||||
authors: Denis Fomin <fominde@gmail.com>
|
||||
homepage: http://trac-plugins.gajim.org
|
||||
|
||||
Reference in New Issue
Block a user