From b7698987ee75e78dd0f3832c8e489f878f5aaa93 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Sun, 11 May 2014 22:10:24 +0200 Subject: pyosd support added, password from file for poller added --- beinc_server.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'beinc_server.py') diff --git a/beinc_server.py b/beinc_server.py index 64e21f5..906b303 100755 --- a/beinc_server.py +++ b/beinc_server.py @@ -33,6 +33,17 @@ try: except ImportError as e: pynotify = None +try: + import pyosd + pyosd_positions = {'top': pyosd.POS_TOP, + 'middle': pyosd.POS_MID, + 'bottom': pyosd.POS_BOT} + pyosd_alignments = {'left': pyosd.ALIGN_LEFT, + 'center': pyosd.ALIGN_CENTER, + 'right': pyosd.ALIGN_RIGHT} +except ImportError as e: + pyosd = None + __author__ = 'Simeon Simeonov' __version__ = '1.0' @@ -41,6 +52,7 @@ __license__ = 'GPL3' BEINC_OSD_TYPE_NONE = 0 BEINC_OSD_TYPE_PYNOTIFY = 1 +BEINC_OSD_TYPE_PYOSD = 2 class BEINCInstance(object): @@ -66,12 +78,14 @@ class BEINCInstance(object): 'This server does not possess pynotify capability\n') sys.stderr.write( 'Remove the instance {0}'.format(self.__name)) - sys.stderr.write("or define it with 'osd_system': 'none'\n") + sys.stderr.write( + 'or define it with "osd_system": "none" ' + 'or other available backend\n') sys.exit(errno.EPERM) try: self.__osd_notification = pynotify.Notification(' ') self.__osd_notification.set_timeout( - int(instance_dict.get('osd_timeout', 5000))) + 1000 * int(instance_dict.get('osd_timeout', 5))) self.__osd_notification.set_property( 'app_name', '{0} {1}'.format(sys.argv[0], __version__)) @@ -80,6 +94,41 @@ class BEINCInstance(object): 'Unable to set up a notification object for {0} ({1})\n') sys.exit(errno.EPERM) self.__osd_type = BEINC_OSD_TYPE_PYNOTIFY + elif instance_dict['osd_system'].lower() == 'pyosd': + self.__queue_size = 0 # disable queueing + if not pyosd: + sys.stderr.write( + 'This server does not possess pyosd capability\n') + sys.stderr.write( + 'Remove the instance {0}'.format(self.__name)) + sys.stderr.write( + 'or define it with "osd_system": "none" ' + 'or other available backend\n') + sys.exit(errno.EPERM) + try: + self.__osd_notification = pyosd.osd() + self.__osd_notification.set_timeout( + int(instance_dict.get('osd_timeout', 5))) + pyosd_font = instance_dict.get('pyosd_font') + if pyosd_font: + self.__osd_notification.set_font(pyosd_font) + self.__osd_notification.set_vertical_offset( + instance_dict.get('pyosd_vertical_offset', 120)) + self.__osd_notification.set_horizontal_offset( + instance_dict.get('pyosd_horizontal_offset', 30)) + align_str = instance_dict.get('pyosd_align', 'left') + self.__osd_notification.set_align( + pyosd_alignments.get(align_str, pyosd.ALIGN_LEFT)) + position_str = instance_dict.get('pyosd_position', 'bottom') + self.__osd_notification.set_pos( + pyosd_positions.get(position_str, pyosd.POS_BOT)) + self.__osd_notification.set_colour( + instance_dict.get('pyosd_color', 'blue')) + except Exception as e: + sys.stderr.write( + 'Unable to set up a notification object for {0} ({1})\n') + sys.exit(errno.EPERM) + self.__osd_type = BEINC_OSD_TYPE_PYOSD @property def name(self): @@ -109,6 +158,8 @@ class BEINCInstance(object): """ if self.__osd_type == BEINC_OSD_TYPE_PYNOTIFY: self.__send_pynotify_messaage(title, message) + elif self.__osd_type == BEINC_OSD_TYPE_PYOSD: + self.__send_pyosd_message(title, message) else: self.__send_message_to_queue(title, message) @@ -127,6 +178,13 @@ class BEINCInstance(object): self.__osd_notification.set_properties(summary=title, body=message) self.__osd_notification.show() + def __send_pyosd_message(self, title, message): + """ + Displays pyosd message + """ + self.__osd_notification.display(title, line=0) + self.__osd_notification.display(message, line=1) + def __send_message_to_queue(self, title, message): """ Enqueues the message -- cgit v1.3