Ejemplo n.º 1
0
    def __init__(self, BLACS, blacs_ui):
        self.inqueue = queue.Queue()
        self.BLACS = BLACS
        self.port = int(self.BLACS.exp_config.get('ports', 'lyse'))

        self._ui = UiLoader().load(
            os.path.join(BLACS_DIR, 'analysis_submission.ui'))
        blacs_ui.analysis.addWidget(self._ui)
        self._ui.frame.setMinimumWidth(
            blacs_ui.queue_controls_frame.sizeHint().width())
        elide_label(self._ui.resend_shots_label,
                    self._ui.failed_to_send_frame.layout(), Qt.ElideRight)
        # connect signals
        self._ui.send_to_server.toggled.connect(
            lambda state: self._set_send_to_server(state))
        self._ui.server.editingFinished.connect(
            lambda: self._set_server(self._ui.server.text()))
        self._ui.clear_unsent_shots_button.clicked.connect(
            lambda _: self.clear_waiting_files())
        self._ui.retry_button.clicked.connect(lambda _: self.check_retry())

        self._waiting_for_submission = []
        self.failure_reason = None
        self.server_online = 'offline'
        self.send_to_server = False
        self.server = ''
        self.time_of_last_connectivity_check = 0

        self.mainloop_thread = threading.Thread(target=self.mainloop)
        self.mainloop_thread.daemon = True
        self.mainloop_thread.start()
Ejemplo n.º 2
0
    def __init__(self, BLACS, ui):
        self._ui = ui
        self.BLACS = BLACS
        self.last_opened_shots_folder = BLACS.exp_config.get('paths', 'experiment_shot_storage')
        self._manager_running = True
        self._manager_paused = False
        self._manager_repeat = False
        self._manager_repeat_mode = self.REPEAT_ALL
        self.master_pseudoclock = self.BLACS.connection_table.master_pseudoclock
        
        self._logger = logging.getLogger('BLACS.QueueManager')   
        
        # Create listview model
        self._model = QStandardItemModel()
        self._create_headers()
        self._ui.treeview.setModel(self._model)
        self._ui.treeview.add_to_queue = self.process_request
        self._ui.treeview.delete_selection = self._delete_selected_items
        
        # set up buttons
        self._ui.queue_pause_button.toggled.connect(self._toggle_pause)
        self._ui.queue_repeat_button.toggled.connect(self._toggle_repeat)
        self._ui.queue_delete_button.clicked.connect(self._delete_selected_items)
        self._ui.queue_clear_button.clicked.connect(self._toggle_clear)
        self._ui.actionAdd_to_queue.triggered.connect(self.on_add_shots_triggered)
        self._ui.queue_add_button.setDefaultAction(self._ui.actionAdd_to_queue)
        self._ui.queue_push_up.clicked.connect(self._move_up)
        self._ui.queue_push_down.clicked.connect(self._move_down)
        self._ui.queue_push_to_top.clicked.connect(self._move_top)
        self._ui.queue_push_to_bottom.clicked.connect(self._move_bottom)

        # Set the elision of the status labels:
        elide_label(self._ui.queue_status, self._ui.queue_status_verticalLayout, Qt.ElideRight)
        elide_label(self._ui.running_shot_name, self._ui.queue_status_verticalLayout, Qt.ElideLeft)
        
        # Set up repeat mode button menu:
        self.repeat_mode_menu = QMenu(self._ui)

        self.action_repeat_all = QAction(QIcon(self.ICON_REPEAT), 'Repeat all', self._ui)
        self.action_repeat_last = QAction(QIcon(self.ICON_REPEAT_LAST), 'Repeat last', self._ui)

        self.action_repeat_all.triggered.connect(lambda *args: setattr(self, 'manager_repeat_mode', self.REPEAT_ALL))
        self.action_repeat_last.triggered.connect(lambda *args: setattr(self, 'manager_repeat_mode', self.REPEAT_LAST))

        self.repeat_mode_menu.addAction(self.action_repeat_all)
        self.repeat_mode_menu.addAction(self.action_repeat_last)

        self._ui.repeat_mode_select_button.setMenu(self.repeat_mode_menu)

        # The button already has an arrow indicating a menu, don't draw another one:
        self._ui.repeat_mode_select_button.setStyleSheet("QToolButton::menu-indicator{width: 0;}")

        self.manager = threading.Thread(target = self.manage)
        self.manager.daemon=True
        self.manager.start()

        self._callbacks = None
    def __init__(self, notebook, settings, restart=False):
        # Store important parameters
        self.notebook = notebook
        self.settings = settings
        self._device_name = self.settings["device_name"]

        # Setup logging
        self.logger = logging.getLogger('BLACS.%s' % (self.device_name))
        self.logger.debug('Started')

        # Setup the timer for updating that tab text label when the tab is not
        # actively part of a notebook
        self._tab_icon_and_colour_timer = QTimer()
        self._tab_icon_and_colour_timer.timeout.connect(
            self.set_tab_icon_and_colour)
        self._tab_icon = self.ICON_OK
        self._tab_text_colour = 'black'

        # Create instance variables
        self._not_responding_error_message = ''
        self._error = ''
        self._state = ''
        self._time_of_last_state_change = time.time()
        self.not_responding_for = 0
        self.hide_not_responding_error_until = 0
        self._timeouts = set()
        self._timeout_ids = {}
        self._force_full_buffered_reprogram = True
        self.event_queue = StateQueue(self.device_name)
        self.workers = {}
        self._supports_smart_programming = False
        self._restart_receiver = []

        # Load the UI
        self._ui = UiLoader().load(
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         'tab_frame.ui'))
        self._layout = self._ui.device_layout
        self._device_widget = self._ui.device_controls
        self._changed_widget = self._ui.changed_widget
        self._changed_layout = self._ui.changed_layout
        self._changed_widget.hide()
        self.BLACS_connection = self.settings['connection_table'].find_by_name(
            self.device_name).BLACS_connection
        self._ui.device_name.setText(
            "<b>%s</b> [conn: %s]" %
            (str(self.device_name), str(self.BLACS_connection)))
        elide_label(self._ui.device_name, self._ui.horizontalLayout,
                    Qt.ElideRight)
        elide_label(self._ui.state_label, self._ui.state_label_layout,
                    Qt.ElideRight)
        # connect signals
        self._ui.button_clear_smart_programming.clicked.connect(
            self.on_force_full_buffered_reprogram)
        self._ui.button_clear_smart_programming.setEnabled(False)
        self.force_full_buffered_reprogram = True
        self._ui.button_close.clicked.connect(self.hide_error)
        self._ui.button_restart.clicked.connect(self.restart)
        self._update_error_and_tab_icon()
        self.supports_smart_programming(False)

        # This should be done beofre the main_loop starts or else there is a race condition as to whether the
        # self._mode variable is even defined!
        # However it must be done after the UI is created!
        self.mode = MODE_MANUAL
        self.state = 'idle'

        # Setup the not responding timeout
        self._timeout = QTimer()
        self._timeout.timeout.connect(self.check_time)
        self._timeout.start(1000)

        # Launch the mainloop
        self._mainloop_thread = threading.Thread(target=self.mainloop)
        self._mainloop_thread.daemon = True
        self._mainloop_thread.start()

        # Add the tab to the notebook
        self.notebook.addTab(self._ui, self.device_name)
        self._ui.show()