diff options
| author | Simeon Simeonov | 2014-05-11 22:10:24 +0200 |
|---|---|---|
| committer | Simeon Simeonov | 2014-05-11 22:10:24 +0200 |
| commit | b7698987ee75e78dd0f3832c8e489f878f5aaa93 (patch) | |
| tree | 8a763f9c0e8e43a312df569e5b0f24bfa1076758 /beinc_server.py | |
| parent | 4a09b47e45b544ee96dbb09577c51a4c7d4ea675 (diff) | |
pyosd support added, password from file for poller added
Diffstat (limited to 'beinc_server.py')
| -rwxr-xr-x | beinc_server.py | 62 |
1 files changed, 60 insertions, 2 deletions
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: | |||
| 33 | except ImportError as e: | 33 | except ImportError as e: |
| 34 | pynotify = None | 34 | pynotify = None |
| 35 | 35 | ||
| 36 | try: | ||
| 37 | import pyosd | ||
| 38 | pyosd_positions = {'top': pyosd.POS_TOP, | ||
| 39 | 'middle': pyosd.POS_MID, | ||
| 40 | 'bottom': pyosd.POS_BOT} | ||
| 41 | pyosd_alignments = {'left': pyosd.ALIGN_LEFT, | ||
| 42 | 'center': pyosd.ALIGN_CENTER, | ||
| 43 | 'right': pyosd.ALIGN_RIGHT} | ||
| 44 | except ImportError as e: | ||
| 45 | pyosd = None | ||
| 46 | |||
| 36 | 47 | ||
| 37 | __author__ = 'Simeon Simeonov' | 48 | __author__ = 'Simeon Simeonov' |
| 38 | __version__ = '1.0' | 49 | __version__ = '1.0' |
| @@ -41,6 +52,7 @@ __license__ = 'GPL3' | |||
| 41 | 52 | ||
| 42 | BEINC_OSD_TYPE_NONE = 0 | 53 | BEINC_OSD_TYPE_NONE = 0 |
| 43 | BEINC_OSD_TYPE_PYNOTIFY = 1 | 54 | BEINC_OSD_TYPE_PYNOTIFY = 1 |
| 55 | BEINC_OSD_TYPE_PYOSD = 2 | ||
| 44 | 56 | ||
| 45 | 57 | ||
| 46 | class BEINCInstance(object): | 58 | class BEINCInstance(object): |
| @@ -66,12 +78,14 @@ class BEINCInstance(object): | |||
| 66 | 'This server does not possess pynotify capability\n') | 78 | 'This server does not possess pynotify capability\n') |
| 67 | sys.stderr.write( | 79 | sys.stderr.write( |
| 68 | 'Remove the instance {0}'.format(self.__name)) | 80 | 'Remove the instance {0}'.format(self.__name)) |
| 69 | sys.stderr.write("or define it with 'osd_system': 'none'\n") | 81 | sys.stderr.write( |
| 82 | 'or define it with "osd_system": "none" ' | ||
| 83 | 'or other available backend\n') | ||
| 70 | sys.exit(errno.EPERM) | 84 | sys.exit(errno.EPERM) |
| 71 | try: | 85 | try: |
| 72 | self.__osd_notification = pynotify.Notification(' ') | 86 | self.__osd_notification = pynotify.Notification(' ') |
| 73 | self.__osd_notification.set_timeout( | 87 | self.__osd_notification.set_timeout( |
| 74 | int(instance_dict.get('osd_timeout', 5000))) | 88 | 1000 * int(instance_dict.get('osd_timeout', 5))) |
| 75 | self.__osd_notification.set_property( | 89 | self.__osd_notification.set_property( |
| 76 | 'app_name', | 90 | 'app_name', |
| 77 | '{0} {1}'.format(sys.argv[0], __version__)) | 91 | '{0} {1}'.format(sys.argv[0], __version__)) |
| @@ -80,6 +94,41 @@ class BEINCInstance(object): | |||
| 80 | 'Unable to set up a notification object for {0} ({1})\n') | 94 | 'Unable to set up a notification object for {0} ({1})\n') |
| 81 | sys.exit(errno.EPERM) | 95 | sys.exit(errno.EPERM) |
| 82 | self.__osd_type = BEINC_OSD_TYPE_PYNOTIFY | 96 | self.__osd_type = BEINC_OSD_TYPE_PYNOTIFY |
| 97 | elif instance_dict['osd_system'].lower() == 'pyosd': | ||
| 98 | self.__queue_size = 0 # disable queueing | ||
| 99 | if not pyosd: | ||
| 100 | sys.stderr.write( | ||
| 101 | 'This server does not possess pyosd capability\n') | ||
| 102 | sys.stderr.write( | ||
| 103 | 'Remove the instance {0}'.format(self.__name)) | ||
| 104 | sys.stderr.write( | ||
| 105 | 'or define it with "osd_system": "none" ' | ||
| 106 | 'or other available backend\n') | ||
| 107 | sys.exit(errno.EPERM) | ||
| 108 | try: | ||
| 109 | self.__osd_notification = pyosd.osd() | ||
| 110 | self.__osd_notification.set_timeout( | ||
| 111 | int(instance_dict.get('osd_timeout', 5))) | ||
| 112 | pyosd_font = instance_dict.get('pyosd_font') | ||
| 113 | if pyosd_font: | ||
| 114 | self.__osd_notification.set_font(pyosd_font) | ||
| 115 | self.__osd_notification.set_vertical_offset( | ||
| 116 | instance_dict.get('pyosd_vertical_offset', 120)) | ||
| 117 | self.__osd_notification.set_horizontal_offset( | ||
| 118 | instance_dict.get('pyosd_horizontal_offset', 30)) | ||
| 119 | align_str = instance_dict.get('pyosd_align', 'left') | ||
| 120 | self.__osd_notification.set_align( | ||
| 121 | pyosd_alignments.get(align_str, pyosd.ALIGN_LEFT)) | ||
| 122 | position_str = instance_dict.get('pyosd_position', 'bottom') | ||
| 123 | self.__osd_notification.set_pos( | ||
| 124 | pyosd_positions.get(position_str, pyosd.POS_BOT)) | ||
| 125 | self.__osd_notification.set_colour( | ||
| 126 | instance_dict.get('pyosd_color', 'blue')) | ||
| 127 | except Exception as e: | ||
| 128 | sys.stderr.write( | ||
| 129 | 'Unable to set up a notification object for {0} ({1})\n') | ||
| 130 | sys.exit(errno.EPERM) | ||
| 131 | self.__osd_type = BEINC_OSD_TYPE_PYOSD | ||
| 83 | 132 | ||
| 84 | @property | 133 | @property |
| 85 | def name(self): | 134 | def name(self): |
| @@ -109,6 +158,8 @@ class BEINCInstance(object): | |||
| 109 | """ | 158 | """ |
| 110 | if self.__osd_type == BEINC_OSD_TYPE_PYNOTIFY: | 159 | if self.__osd_type == BEINC_OSD_TYPE_PYNOTIFY: |
| 111 | self.__send_pynotify_messaage(title, message) | 160 | self.__send_pynotify_messaage(title, message) |
| 161 | elif self.__osd_type == BEINC_OSD_TYPE_PYOSD: | ||
| 162 | self.__send_pyosd_message(title, message) | ||
| 112 | else: | 163 | else: |
| 113 | self.__send_message_to_queue(title, message) | 164 | self.__send_message_to_queue(title, message) |
| 114 | 165 | ||
| @@ -127,6 +178,13 @@ class BEINCInstance(object): | |||
| 127 | self.__osd_notification.set_properties(summary=title, body=message) | 178 | self.__osd_notification.set_properties(summary=title, body=message) |
| 128 | self.__osd_notification.show() | 179 | self.__osd_notification.show() |
| 129 | 180 | ||
| 181 | def __send_pyosd_message(self, title, message): | ||
| 182 | """ | ||
| 183 | Displays pyosd message | ||
| 184 | """ | ||
| 185 | self.__osd_notification.display(title, line=0) | ||
| 186 | self.__osd_notification.display(message, line=1) | ||
| 187 | |||
| 130 | def __send_message_to_queue(self, title, message): | 188 | def __send_message_to_queue(self, title, message): |
| 131 | """ | 189 | """ |
| 132 | Enqueues the message | 190 | Enqueues the message |
