_moduleLogger = logging.getLogger(__name__)
+class LedWrapper(object):
+
+ def __init__(self):
+ self._ledHandler = None
+ self._init = False
+
+ def off(self):
+ self._lazy_init()
+ if self._ledHandler is not None:
+ self._ledHandler.off()
+
+ def _lazy_init(self):
+ if self._init:
+ return
+ self._init = True
+ try:
+ import led_handler
+ self._ledHandler = led_handler.LedHandler()
+ except Exception, e:
+ _moduleLogger.exception('Unable to initialize LED Handling: "%s"' % str(e))
+ self._ledHandler = None
+
+
+
class Dialcentral(object):
_DATA_PATHS = [
self._hiddenUnits = {}
self._clipboard = QtGui.QApplication.clipboard()
self._dataPath = None
+ self._ledHandler = LedWrapper()
self.notifyOnMissed = False
self.notifyOnVoicemail = False
self.notifyOnSms = False
self._fullscreenAction.setShortcut(QtGui.QKeySequence("CTRL+Enter"))
self._fullscreenAction.toggled.connect(self._on_toggle_fullscreen)
+ self._orientationAction = QtGui.QAction(None)
+ self._orientationAction.setText("Orientation")
+ self._orientationAction.setCheckable(True)
+ self._orientationAction.setShortcut(QtGui.QKeySequence("CTRL+o"))
+ self._orientationAction.toggled.connect(self._on_toggle_orientation)
+
self._logAction = QtGui.QAction(None)
self._logAction.setText("Log")
self._logAction.setShortcut(QtGui.QKeySequence("CTRL+l"))
blobs = "", ""
isFullscreen = False
+ isPortrait = qui_utils.screen_orientation() == QtCore.Qt.Vertical
tabIndex = 0
try:
- blobs = (
+ blobs = [
config.get(constants.__pretty_app_name__, "bin_blob_%i" % i)
for i in xrange(len(self._mainWindow.get_default_credentials()))
- )
+ ]
isFullscreen = config.getboolean(constants.__pretty_app_name__, "fullscreen")
tabIndex = config.getint(constants.__pretty_app_name__, "tab")
+ isPortrait = config.getboolean(constants.__pretty_app_name__, "portrait")
except ConfigParser.NoOptionError, e:
_moduleLogger.info(
"Settings file %s is missing option %s" % (
)
self._mainWindow.set_default_credentials(*creds)
self._fullscreenAction.setChecked(isFullscreen)
+ self._orientationAction.setChecked(isPortrait)
self._mainWindow.set_current_tab(tabIndex)
self._mainWindow.load_settings(config)
config.add_section(constants.__pretty_app_name__)
config.set(constants.__pretty_app_name__, "tab", str(self._mainWindow.get_current_tab()))
config.set(constants.__pretty_app_name__, "fullscreen", str(self._fullscreenAction.isChecked()))
+ config.set(constants.__pretty_app_name__, "portrait", str(self._orientationAction.isChecked()))
for i, value in enumerate(self._mainWindow.get_default_credentials()):
blob = base64.b64encode(value)
config.set(constants.__pretty_app_name__, "bin_blob_%i" % i, blob)
return self._fullscreenAction
@property
+ def orientationAction(self):
+ return self._orientationAction
+
+ @property
def logAction(self):
return self._logAction
def alarmHandler(self):
return self._alarmHandler
+ @property
+ def ledHandler(self):
+ return self._ledHandler
+
def _walk_children(self):
if self._mainWindow is not None:
return (self._mainWindow, )
@QtCore.pyqtSlot()
@QtCore.pyqtSlot(bool)
@misc_utils.log_exception(_moduleLogger)
+ def _on_toggle_orientation(self, checked = False):
+ for window in self._walk_children():
+ window.set_orientation(checked)
+
+ @QtCore.pyqtSlot()
+ @QtCore.pyqtSlot(bool)
+ @misc_utils.log_exception(_moduleLogger)
def _on_log(self, checked = False):
with open(constants._user_logpath_, "r") as f:
logLines = f.xreadlines()
self._window = QtGui.QMainWindow(parent)
self._window.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
- qui_utils.set_autorient(self._window, True)
qui_utils.set_stackable(self._window, True)
self._window.setWindowTitle("%s" % constants.__pretty_app_name__)
self._window.setCentralWidget(centralWidget)
self._window.addAction(self._closeWindowAction)
self._window.addAction(self._app.quitAction)
self._window.addAction(self._app.fullscreenAction)
+ self._window.addAction(self._app.orientationAction)
else:
fileMenu = self._window.menuBar().addMenu("&File")
fileMenu.addAction(self._loginTabAction)
toolsMenu.addAction(self._importTabAction)
toolsMenu.addAction(self._aboutAction)
+ self._window.addAction(self._app.orientationAction)
+
self._window.addAction(self._app.logAction)
self._initialize_tab(self._tabWidget.currentIndex())
self.set_fullscreen(self._app.fullscreenAction.isChecked())
+ self.set_orientation(self._app.orientationAction.isChecked())
@property
def window(self):
for child in self.walk_children():
child.set_fullscreen(isFullscreen)
+ def set_orientation(self, isPortrait):
+ if isPortrait:
+ self._tabWidget.setTabPosition(QtGui.QTabWidget.South)
+ qui_utils.set_window_orientation(self.window, QtCore.Qt.Vertical)
+ else:
+ self._tabWidget.setTabPosition(QtGui.QTabWidget.West)
+ qui_utils.set_window_orientation(self.window, QtCore.Qt.Horizontal)
+ for child in self.walk_children():
+ child.set_orientation(isPortrait)
+
def _initialize_tab(self, index):
assert index < self.MAX_TABS, "Invalid tab"
if not self._tabsContents[index].has_child():