Start to improve remote

This commit is contained in:
Tim Bentley 2014-04-14 19:09:47 +01:00
parent 8813490bad
commit d681f0a059
6 changed files with 55 additions and 17 deletions

View File

@ -38,9 +38,10 @@ import os
import logging import logging
import time import time
from PyQt4 import QtCore from PyQt4 import QtCore, QtGui
from openlp.core.common import AppLocation, Settings from openlp.core.common import AppLocation, Settings, RegistryProperties
from openlp.core.lib import build_icon
from openlp.plugins.remotes.lib import HttpRouter from openlp.plugins.remotes.lib import HttpRouter
@ -95,12 +96,13 @@ class HttpThread(QtCore.QThread):
self.http_server.start_server() self.http_server.start_server()
class OpenLPServer(): class OpenLPServer(RegistryProperties):
def __init__(self): def __init__(self):
""" """
Initialise the http server, and start the server of the correct type http / https Initialise the http server, and start the server of the correct type http / https
""" """
log.debug('Initialise httpserver') super(OpenLPServer, self).__init__()
log.debug('Initialise OpenLP')
self.settings_section = 'remotes' self.settings_section = 'remotes'
self.http_thread = HttpThread(self) self.http_thread = HttpThread(self)
self.http_thread.start() self.http_thread.start()
@ -112,25 +114,47 @@ class OpenLPServer():
address = Settings().value(self.settings_section + '/ip address') address = Settings().value(self.settings_section + '/ip address')
if Settings().value(self.settings_section + '/https enabled'): if Settings().value(self.settings_section + '/https enabled'):
port = Settings().value(self.settings_section + '/https port') port = Settings().value(self.settings_section + '/https port')
self.httpd = HTTPSServer((address, port), CustomHandler) self.start_server_instance(address, port, HTTPSServer)
log.debug('Started ssl httpd...')
else: else:
port = Settings().value(self.settings_section + '/port') port = Settings().value(self.settings_section + '/port')
loop = 1 self.start_server_instance(address, port, ThreadingHTTPServer)
while loop < 3:
try:
self.httpd = ThreadingHTTPServer((address, port), CustomHandler)
except OSError:
loop += 1
time.sleep(0.1)
except:
log.error('Failed to start server ')
log.debug('Started non ssl httpd...')
if hasattr(self, 'httpd') and self.httpd: if hasattr(self, 'httpd') and self.httpd:
self.httpd.serve_forever() self.httpd.serve_forever()
icon = QtGui.QImage(':/remote/network_server.png')
icon = icon.scaled(80, 80, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
overlay = QtGui.QImage(':/remote/network_ssl.png')
overlay = overlay.scaled(40, 40, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
painter = QtGui.QPainter(icon)
painter.drawImage(0, 0, overlay)
painter.end()
print("Hi")
self.default_theme_label.setText("hello")
self.default_theme_label.setIcon(build_icon(icon))
self.default_theme_label.show()
else: else:
log.debug('Failed to start server') log.debug('Failed to start server')
def start_server_instance(self, address, port, server_class):
"""
Start the server
:param address: The server address
:param port: The run port
:param server_class: the class to start
"""
loop = 1
while loop < 4:
try:
self.httpd = server_class((address, port), CustomHandler)
log.debug("Server started for class %s %s %d" % (server_class, address, port))
except OSError:
log.debug("failed to start http server thread state %d %s" %
(loop, self.http_thread.isRunning() is True))
loop += 1
time.sleep(0.1)
except:
log.error('Failed to start server ')
def stop_server(self): def stop_server(self):
""" """
Stop the server Stop the server

View File

@ -30,6 +30,8 @@
import logging import logging
import time import time
from PyQt4 import QtGui
from openlp.core.lib import Plugin, StringContent, translate, build_icon from openlp.core.lib import Plugin, StringContent, translate, build_icon
from openlp.plugins.remotes.lib import RemoteTab, OpenLPServer from openlp.plugins.remotes.lib import RemoteTab, OpenLPServer
@ -67,6 +69,13 @@ class RemotesPlugin(Plugin):
log.debug('initialise') log.debug('initialise')
super(RemotesPlugin, self).initialise() super(RemotesPlugin, self).initialise()
self.server = OpenLPServer() self.server = OpenLPServer()
self.default_theme_label = QtGui.QToolButton(self.main_window.status_bar)
self.default_theme_label.setCheckable(False)
self.default_theme_label.setAutoRaise(True)
self.default_theme_label.setObjectName('default_theme_label')
self.main_window.status_bar.insertPermanentWidget(2, self.default_theme_label)
self.default_theme_label.hide()
self.server.default_theme_label = self.default_theme_label
def finalise(self): def finalise(self):
""" """
@ -108,5 +117,5 @@ class RemotesPlugin(Plugin):
""" """
log.debug('remote config changed') log.debug('remote config changed')
self.finalise() self.finalise()
time.sleep(0.5) time.sleep(1)
self.initialise() self.initialise()

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 B

View File

@ -149,6 +149,11 @@
<file>messagebox_info.png</file> <file>messagebox_info.png</file>
<file>messagebox_warning.png</file> <file>messagebox_warning.png</file>
</qresource> </qresource>
<qresource prefix="remote">
<file>network_server.png</file>
<file>network_ssl.png</file>
<file>network_auth.png</file>
</qresource>
<qresource prefix="songusage"> <qresource prefix="songusage">
<file>song_usage_active.png</file> <file>song_usage_active.png</file>
<file>song_usage_inactive.png</file> <file>song_usage_inactive.png</file>