def __loadStyleSheet(self, styleSheetFileName): """ Load and apply the style sheet. @param styleSheetFileName: name of the style sheet @type styleSheetFileName: str """ Logger().debug("MainController.__loadStyleSheet(): style sheet=%s" % styleSheetFileName) try: styleSheetFile = file(styleSheetFileName) QtGui.qApp.setStyleSheet(styleSheetFile.read()) styleSheetFile.close() except Exception, msg: Logger().exception("MainController.__loadStyleSheet()") dialog = ExceptionMessageDialog(self.tr("Can't load style sheet"), unicode(msg)) dialog.exec_()
def __importPresetFile(self, presetFileName): """ Import the presets from given file. @param presetFileName: name of the preset xml file @type presetFileName: str """ Logger().debug("MainController.__importPresetFile(): preset file=%s" % presetFileName) try: PresetManager().importPresetFile(presetFileName) self.__populatePresetComboBox() self.refreshView() except Exception, msg: Logger().exception("MainController.__importPresetFile()") dialog = ExceptionMessageDialog(self.tr("Can't import preset file"), unicode(msg)) dialog.exec_()
def __onBluetoothChoosePushButtonClicked(self): """ Choose bluetooth button clicked. Open the bluetooth chooser dialog. """ Logger().trace("PluginsController.__onBluetoothChoosePushButtonClicked()") QtGui.qApp.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) while QtGui.QApplication.hasPendingEvents(): QtGui.QApplication.processEvents() #QtCore.QEventLoop.ExcludeUserInputEvents) bluetoothTransport = BluetoothTransport() try: bluetoothDevices = bluetoothTransport.discoverDevices() except Exception, msg: QtGui.qApp.restoreOverrideCursor() Logger().exception("PluginsController.__onBluetoothChoosePushButtonClicked()") Logger().error("Can't scan bluetooth\n%s" % unicode(msg)) dialog = ExceptionMessageDialog(self.tr("Can't scan bluetooth"), unicode(msg)) dialog.exec_()
def main(): try: # Give a name to the main trhead threading.currentThread().setName("Main") # Init the logger if hasattr(sys, "frozen"): # Forbid all console outputs sys.stderr = BlackHole() Logger(defaultStreamHandler=False) else: Logger() # Create the buffer for GUI log logStream = LogBuffer() Logger().addStreamHandler(logStream, QSpaceColorFormatter) Logger().info("Starting Papywizard...") # Misc infos Logger().debug("main(): platform=%s" % config.platform) # Init global Qt application qtApp = QtGui.QApplication(sys.argv) qtApp.setApplicationName("Papywizard") qtApp.setApplicationVersion(config.VERSION) # Create the splashscreen from papywizard.common import pixmaps pixmap = QtGui.QPixmap() pixmap.load(":/pixmaps/%s" % config.SPLASHCREEN_FILE) splash = QtGui.QSplashScreen(pixmap, QtCore.Qt.WindowStaysOnTopHint) splash.show() qtApp.processEvents() # Addtional imports Logger().info("Importing modules...") splash.showMessage("Importing modules...") qtApp.processEvents() from papywizard.common import i18n from papywizard.common.configManager import ConfigManager #from papywizard.common.publisher import Publisher from papywizard.model.shooting import Shooting from papywizard.controller.mainController import MainController from papywizard.controller.spy import Spy from papywizard.view import icons # i18n stuff Logger().info("Loading i18n files...") splash.showMessage("Loading i18n files...") qtApp.processEvents() locale = QtCore.QLocale.system().name() Logger().debug("main(): locale=%s" % locale) qtTranslator = QtCore.QTranslator() if qtTranslator.load( "qt_%s" % locale, QtCore.QLibraryInfo.location( QtCore.QLibraryInfo.TranslationsPath)): qtApp.installTranslator(qtTranslator) else: Logger().warning("Can't find qt translation file") appTranslator = QtCore.QTranslator() if appTranslator.load("papywizard_%s" % locale, ":/i18n"): qtApp.installTranslator(appTranslator) else: Logger().warning("Can't find papywizard translation file") # Load Qt stylesheet Logger().info("Loading Style Sheets...") splash.showMessage("Loading Style Sheets...") qtApp.processEvents() try: styleSheet = file(config.USER_STYLESHEET_FILE) qtApp.setStyleSheet(styleSheet.read()) styleSheet.close() except IOError: Logger().warning("No user Style Sheet found") styleSheet = qtApp.styleSheet() if styleSheet: if styleSheet.startsWith("file://"): Logger().debug("Style Sheet loaded from command line param.") else: Logger().debug("User Style Sheet loaded") # Load user configuration Logger().info("Loading configuration...") splash.showMessage("Loading configuration...") qtApp.processEvents() ConfigManager().load() # Load plugins (move to shooting?) Logger().info("Load plugins...") splash.showMessage("Load plugins...") from papywizard.plugins.dslrRemoteProPlugins import register register() from papywizard.plugins.eosUtilityPlugins import register register() from papywizard.plugins.genericTetheredPlugins import register register() from papywizard.plugins.gigaPanBotPlugins import register register() from papywizard.plugins.gphotoBracketPlugins import register register() from papywizard.plugins.merlinOrionPlugins import register register() from papywizard.plugins.nkRemotePlugins import register register() from papywizard.plugins.panoduinoPlugins import register register() from papywizard.plugins.pixOrbPlugins import register register() from papywizard.plugins.simulationPlugins import register register() from papywizard.plugins.timelordPlugins import register register() from papywizard.plugins.ursaMinorBt2Plugins import register register() from papywizard.plugins.ursaMinorUsbPlugins import register register() from papywizard.plugins.claussPlugins import register register() from papywizard.plugins.owlPlugins import register register() PluginsManager().load() # Activate selected plugins (move to PluginsManager ?) Logger().info("Activate plugins...") plugin = ConfigManager().get('Plugins/PLUGIN_YAW_AXIS') PluginsManager().get('yawAxis', plugin)[0].activate() plugin = ConfigManager().get('Plugins/PLUGIN_PITCH_AXIS') PluginsManager().get('pitchAxis', plugin)[0].activate() plugin = ConfigManager().get('Plugins/PLUGIN_SHUTTER') PluginsManager().get('shutter', plugin)[0].activate() # Create model Logger().info("Creating model...") splash.showMessage("Creating model...") qtApp.processEvents() model = Shooting() # Create spy thread Logger().info("Starting Spy...") Spy(model).start() # Create main controller Logger().info("Creating GUI...") splash.showMessage("Creating GUI...") qtApp.processEvents() mainController = MainController(model, logStream) # Set user logger level Logger().setLevel(ConfigManager().get('Configuration/LOGGER_LEVEL')) # Terminate splashscreen splash.finish(mainController._view) # Check if teh configuration is set if not ConfigManager().isConfigured(): from papywizard.view.messageDialog import InfoMessageDialog #dialog = WarningMessageDialog(QtCore.QObject().tr("Configuration"), #QtCore.QObject().tr("Papywizard needs to be configured")) dialog = InfoMessageDialog(QtGui.QApplication.translate("main", "Plugins selection"), QtGui.QApplication.translate("main", "Before you can use Papywizard, you must choose what " \ "plugins to use to control your hardware.\n\n" \ "After closing this dialog, you will be prompt to select " \ "these plugins. Once it is done, you can configure them " "in the global Configuration dialog")) dialog.exec_() from papywizard.controller.pluginsController import PluginsController controller = PluginsController(None, model) controller.exec_() controller.shutdown() # Enter Qt main loop qtApp.exec_() # Shutdown controller Logger().info("Shuting down GUI...") mainController.shutdown() # Stop spy thread Logger().info("Shuting down Spy...") Spy().stop() Logger().debug("Waiting Spy thread to terminate...") Spy().wait() # Shutdown model Logger().info("Shuting down model...") model.shutdown() # Cleanup resources Logger().info("Cleaning up resources...") i18n.qCleanupResources() pixmaps.qCleanupResources() icons.qCleanupResources() Logger().info("Papywizard stopped") except Exception, msg: Logger().exception("main()") if 'splash' in locals(): splash.finish(None) from papywizard.view.messageDialog import ExceptionMessageDialog try: msg = msg.message # Windows exception? except AttributeError: pass dialog = ExceptionMessageDialog("Unhandled exception", unicode(msg)) dialog.exec_()