def on_update_driver(self, event): driver_name = self.driver_select.get() driver = plugin.get_driver(driver_name) self.spreads_config["driver"] = driver_name if plugin.DeviceFeatures.IS_CAMERA in driver.features: for widget in (self.orient_label, self.orient_odd_btn, self.orient_even_btn, self.focus_label, self.focus_btn): widget['state'] = "enabled"
def _add_device_arguments(name, parser): tmpl = plugin.get_driver(config["driver"] .get()).driver.configuration_template() if not tmpl: return for key, option in tmpl.iteritems(): try: add_argument_from_option('device', key, option, parser) except: return
def configure(config): old_plugins = config["plugins"].get() driver_name = _select_driver(config["driver"].get() if 'driver' in config.keys() else None) if driver_name: config["driver"] = driver_name driver = plugin.get_driver(config["driver"].get()) else: driver = None # Save driver config.dump(filename=config.cfg_path) config["plugins"] = _select_plugins(old_plugins) _setup_processing_pipeline(config) # Load default configuration for newly added plugins new_plugins = [x for x in config["plugins"].get() if x not in old_plugins] for name in new_plugins: if not name in config.templates: continue config.set_from_template(name, config.templates[name]) # Save plugins config.dump(filename=config.cfg_path) # We only need to set the device target_page if the driver supports # shooting with two devices if driver and plugin.DeviceFeatures.IS_CAMERA in driver.features: answer = raw_input( "Do you want to configure the target_page of your devices?\n" "(Required for shooting with two devices) [y/N]: ") answer = True if answer.lower() == 'y' else False if answer: print("Setting target page on cameras") for target_page in ('odd', 'even'): _set_device_target_page(config, target_page) answer = raw_input("Do you want to setup the focus for your cameras? " "[y/N]: ") answer = True if answer.lower() == 'y' else False if answer: print("Please turn on one of your capture devices.\n" "Press any key to continue") getch() devs = plugin.get_devices(config, force_reload=True) print("Please put a book with as little whitespace as possible" "under your cameras.\nPress any button to continue") getch() focus = devs[0]._acquire_focus() config['device']['focus_distance'] = focus print("Configuration file written to '{0}'".format(config.cfg_path)) config.dump(filename=config.cfg_path)
def run_server(self): """ Run the web application. """ self.setup_logging() self.setup_task_queue() self.setup_signals() self.setup_tornado() self._listening_port = self.config['port'].get(int) self._ip_address = get_ip_address() try: device_driver = plugin.get_driver(self.global_config['driver'] .get()) should_display_ip = (app.config['standalone'] and self._ip_address and plugin.DeviceFeatures.CAN_DISPLAY_TEXT in device_driver.features) except ConfigError: if self.config['mode'] not in ('scanner', 'full'): should_display_ip = False raise ConfigError( "You need to specify a value for `driver`.\n" "Either run `spread [gui]configure` or edit the configuration " "file.") if should_display_ip: # Every 30 seconds, see if there are devices attached and display # IP address and port on them, then disable the callback self._display_callback = PeriodicCallback( self.display_ip, 30*10**3) # Run once immediately self.display_ip() # Start task consumer self.consumer.start() # Start discovery listener if app.config['mode'] in ('processor', 'full'): discovery_listener = DiscoveryListener(self._listening_port) discovery_listener.start() # Spin up WSGI server self.application.listen(self._listening_port) try: IOLoop.instance().start() finally: # Shut everything down that is still running in the background self.consumer.shutdown() if app.config['mode'] in ('processor', 'full'): discovery_listener.stop()
def on_update_driver(self, event): """ Callback for when the user selects a driver. Updates the driver in the configuration and toggles the status of widgets that depend on certain device features. :param event: Event from Tkinter :type event: :py:class:`Tkinter.Event` """ driver_name = self.driver_select.get() driver = plugin.get_driver(driver_name) self.spreads_config["driver"] = driver_name if plugin.DeviceFeatures.IS_CAMERA in driver.features: for widget in (self.orient_label, self.orient_odd_btn, self.orient_even_btn, self.focus_label, self.focus_btn): widget['state'] = "enabled"
def configure(config): config["driver"] = _select_driver() config["plugins"] = _select_plugins(config["plugins"].get()) # Set default plugin configuration plugin.set_default_config(config) _setup_processing_pipeline(config) cfg_path = os.path.join(config.config_dir(), confit.CONFIG_FILENAME) driver = plugin.get_driver(config["driver"].get()).driver # We only need to set the device target_page if the driver supports # shooting with two devices if plugin.DeviceFeatures.IS_CAMERA in driver.features: answer = raw_input( "Do you want to configure the target_page of your devices?\n" "(Required for shooting with two devices) [y/n]: ") answer = True if answer.lower() == 'y' else False if answer: print("Setting target page on cameras") for target_page in ('odd', 'even'): _set_device_target_page(config, target_page) answer = raw_input("Do you want to setup the focus for your cameras? " "[y/n]: ") answer = True if answer.lower() == 'y' else False if answer: print("Please turn on one of your capture devices.\n" "Press any key to continue") getch() devs = plugin.get_devices(config, force_reload=True) print("Please put a book with as little whitespace as possible" "under your cameras.\nPress any button to continue") getch() focus = devs[0]._acquire_focus() config['device']['focus_distance'] = focus print("Writing configuration file to '{0}'".format(cfg_path)) config.dump(filename=cfg_path)
def configure(config): """ Configuration subcommand that runs through the various dialogs, builds a new configuration and writes it to disk. :param config: Currently active global configuration :type config: :py:class:`spreads.config.Configuration` """ old_plugins = config["plugins"].get() driver_name = _select_driver( config["driver"].get() if 'driver' in config.keys() else None) if driver_name: config["driver"] = driver_name driver = plugin.get_driver(config["driver"].get()) else: driver = None # Save driver config.dump(filename=config.cfg_path) config["plugins"] = _select_plugins(old_plugins) _setup_processing_pipeline(config) # Load default configuration for newly added plugins new_plugins = [x for x in config["plugins"].get() if x not in old_plugins] for name in new_plugins: if name not in config.templates: continue config.set_from_template(name, config.templates[name]) # Save plugins config.dump(filename=config.cfg_path) # We only need to set the device target_page if the driver supports # shooting with two devices if driver and plugin.DeviceFeatures.IS_CAMERA in driver.features: answer = raw_input( "Do you want to configure the target_page of your devices?\n" "(Required for shooting with two devices) [y/N]: ") answer = True if answer.lower() == 'y' else False if answer: print("Setting target page on cameras") for target_page in ('odd', 'even'): _set_device_target_page(config, target_page) answer = raw_input("Do you want to setup the focus for your cameras? " "[y/N]: ") answer = True if answer.lower() == 'y' else False if answer: # TODO: Set focus for both devices independently print("Please turn on one of your capture devices.\n" "Press any key to continue") getch() devs = plugin.get_devices(config, force_reload=True) print("Please put a book with as little whitespace as possible " "under your cameras.\nPress any button to continue") getch() focus = devs[0]._acquire_focus() config['device']['focus_mode'] = 'manual' config['device']['focus_distance'] = focus else: config['device']['focus_mode'] = 'autofocus_all' print("Configuration file written to '{0}'".format(config.cfg_path)) config.dump(filename=config.cfg_path)
def initializePage(self): wizard = self.wizard() self.pluginmanager = get_pluginmanager(wizard.config) wizard.active_plugins = self.pluginmanager.names() self.setTitle("Welcome!") intro_label = QtGui.QLabel( "This wizard will guide you through the digitization workflow. " ) intro_label.setWordWrap(True) dirpick_layout = QtGui.QHBoxLayout() self.line_edit = QtGui.QLineEdit() self.line_edit.textChanged.connect(self.completeChanged) browse_btn = QtGui.QPushButton("Browse") dirpick_layout.addWidget(self.line_edit) dirpick_layout.addWidget(browse_btn) browse_btn.clicked.connect(self.show_filepicker) self.stack_widget = QtGui.QStackedWidget() page_combobox = QtGui.QComboBox() page_combobox.activated.connect(self.stack_widget.setCurrentIndex) #QtCore.QObject.connect(page_combobox, SIGNAL("activated(int)"), # self.stack_widget, SLOT("setCurrentIndex(int)")) templates = {ext.name: ext.plugin.configuration_template() for ext in self.pluginmanager} templates["device"] = (get_driver(wizard.config["driver"].get()) .driver.configuration_template()) # Add configuration widgets from plugins self.plugin_widgets = {} for name, tmpl in templates.iteritems(): if not tmpl: continue page = QtGui.QGroupBox() layout = QtGui.QFormLayout() widgets = self._get_plugin_config_widgets(tmpl) self.plugin_widgets[name] = widgets for label, widget in widgets.values(): # We don't need a label for QCheckBoxes if isinstance(widget, QtGui.QCheckBox): layout.addRow(widget) else: layout.addRow(label, widget) page.setLayout(layout) self.stack_widget.addWidget(page) page_combobox.addItem(name.title()) main_layout = QtGui.QVBoxLayout() main_layout.addWidget(intro_label) main_layout.addSpacing(30) main_layout.addWidget( QtGui.QLabel("Please select a project directory.") ) main_layout.addLayout(dirpick_layout) main_layout.addSpacing(30) main_layout.addWidget(page_combobox) main_layout.addWidget(self.stack_widget) main_layout.setSizeConstraint(QtGui.QLayout.SetNoConstraint) self.setLayout(main_layout) self.adjustSize()
def configure(config): """ Configuration subcommand that runs through the various dialogs, builds a new configuration and writes it to disk. :param config: Currently active global configuration :type config: :py:class:`spreads.config.Configuration` """ old_plugins = config["plugins"].get() driver_name = _select_driver(config["driver"].get() if 'driver' in config.keys() else None) if driver_name: config["driver"] = driver_name driver = plugin.get_driver(config["driver"].get()) else: driver = None # Save driver config.dump(filename=config.cfg_path) config["plugins"] = _select_plugins(old_plugins) _setup_processing_pipeline(config) # Load default configuration for newly added plugins new_plugins = [x for x in config["plugins"].get() if x not in old_plugins] for name in new_plugins: if name not in config.templates: continue config.set_from_template(name, config.templates[name]) # Save plugins config.dump(filename=config.cfg_path) # We only need to set the device target_page if the driver supports # shooting with two devices if driver and plugin.DeviceFeatures.IS_CAMERA in driver.features: answer = raw_input( "Do you want to configure the target_page of your devices?\n" "(Required for shooting with two devices) [y/N]: ") answer = True if answer.lower() == 'y' else False if answer: print("Setting target page on cameras") for target_page in ('odd', 'even'): _set_device_target_page(config, target_page) answer = raw_input("Do you want to setup the focus for your cameras? " "[y/N]: ") answer = True if answer.lower() == 'y' else False if answer: # TODO: Set focus for both devices independently print("Please turn on one of your capture devices.\n" "Press any key to continue") getch() devs = plugin.get_devices(config, force_reload=True) print("Please put a book with as little whitespace as possible " "under your cameras.\nPress any button to continue") getch() focus = devs[0]._acquire_focus() config['device']['focus_mode'] = 'manual' config['device']['focus_distance'] = focus else: config['device']['focus_mode'] = 'autofocus_all' print("Configuration file written to '{0}'".format(config.cfg_path)) config.dump(filename=config.cfg_path)
def test_get_driver(self): assert "dummy" in plugin.get_driver("dummy").names()