Esempio n. 1
0
 def goal_done_callback(self, terminal_state, result):
     if result.result == 0:
         self.emit(SIGNAL('goalDone(PyQt_PyObject)'),
                   "MC finished succesfully")
     else:
         self.emit(SIGNAL('goalDone(PyQt_PyObject)'),
                   "MC finished without success!!!")
Esempio n. 2
0
    def __init__(self, *args, **kwargs):
        self.id = self.uid
        self.uid += 1
        kwargs['gui'] = True
        self.cancelled = False
        super().__init__(*args, **kwargs)
        # Initialize the GUI display
        if self.disable or not kwargs['gui']:
            return

        self.mininterval = max(self.mininterval, 0.5)

        # assert maxval >= 0
        # self.maxval = maxval
        self.signal_set = False

        global signaler
        signaler.connect(signaler, SIGNAL('cancel(int)'),
                         self.cancel)

        self.currval = 0
        self.finished = False
        self.start_time = None
        self.seconds_elapsed = 0

        signaler.emit(SIGNAL('created(int, int, QString)'), self.id,
                      self.total, "")
Esempio n. 3
0
 def on_MC_goal_done(self, msg):
     #Show some info in the general info area
     self.general_info_area_widget.log_area_TextEdit.appendHtml(
         "<font color=\"red\">" + msg + "</font>")
     #We'll emit a signal to show all the buttons to start sequence
     self.emit(SIGNAL('showStartSequenceButtons(PyQt_PyObject)'), True)
     self.first_time = True
Esempio n. 4
0
    def __init__(self, sequence, config):
        super(ObjectSelectionControl, self).__init__(sequence, config)

        self_dir = os.path.dirname(os.path.realpath(__file__))
        self.ui_dir = os.path.join(self_dir, '../../ui')

        # info bar UI setup
        self.info_bar_widget.step_name_label.setText(self.config_dict['label'])

        # info area UI setup
        self.info_area_widget = QWidget()
        ui_file = os.path.join(self.ui_dir, 'ObjectSelectionInfoArea.ui')
        loadUi(ui_file, self.info_area_widget)

        self.init_step_info_area()

        self.connect(self, SIGNAL('objectSelection(PyQt_PyObject)'),
                     self.on_object_selection_request)

        self.feedback_subscription()

        #Setup a server to let the object_selection actionlib server ask for the object to select from a list
        srvname = 'decision_services/object_selection'
        self.object_selection_server = rospy.Service(
            srvname, ObjectSelectionFromList, self.object_selection_callback)
Esempio n. 5
0
    def update(self, n=1):
        """
        Updates the progress bar to a new value. Called by the hyperspy side.
        Not safe to call from UI.
        """
        if self.disable:
            return
        if self.cancelled is True:
            raise ProcessCanceled("User cancelled operation")

        if n < 0:
            n = 1
        self.n += n

        delta_it = self.n - self.last_print_n  # should be n?
        if delta_it >= self.miniters:
            # We check the counter first, to reduce the overhead of time()
            cur_t = time()
            delta_t = cur_t - self.last_print_t
            if delta_t >= self.mininterval:
                elapsed = cur_t - self.start_t
                # EMA (not just overall average)
                if self.smoothing and delta_t:
                    self.avg_time = delta_t / delta_it \
                        if self.avg_time is None \
                        else self.smoothing * delta_t / delta_it + \
                        (1 - self.smoothing) * self.avg_time

                txt = self.format_string(
                    self.n, self.total, elapsed,
                    1 / self.avg_time if self.avg_time else None)

                global signaler
                signaler.emit(SIGNAL('progress(int, int, QString)'),
                              self.id, self.n, txt)

                # If no `miniters` was specified, adjust automatically to the
                # maximum iteration rate seen so far.
                # e.g.: After running `tqdm.update(5)`, subsequent
                # calls to `tqdm.update()` will only cause an update after
                # at least 5 more iterations.
                if self.dynamic_miniters:
                    if self.maxinterval and delta_t > self.maxinterval:
                        self.miniters = self.miniters * self.maxinterval \
                            / delta_t
                    elif self.mininterval and delta_t:
                        self.miniters = self.smoothing * delta_it \
                            * self.mininterval / delta_t + \
                            (1 - self.smoothing) * self.miniters
                    else:
                        self.miniters = self.smoothing * delta_it + \
                            (1 - self.smoothing) * self.miniters

                # Store old values for next call
                self.last_print_n = self.n
                self.last_print_t = cur_t
Esempio n. 6
0
    def object_selection_callback(self, req):
        self.selected_object_index = None
        self.emit(SIGNAL('objectSelection(PyQt_PyObject)'), req.objects)

        while not rospy.is_shutdown():
            if self.selected_object_index != None:
                break
            rospy.sleep(0.1)

        return ObjectSelectionFromListResponse(self.selected_object_index)
Esempio n. 7
0
 def position_selection_callback(self, req):
     self.selected_pose = None
     self.emit(SIGNAL('positionSelection(PyQt_PyObject)'), req.initial_pose_of_the_object)
     
     while not rospy.is_shutdown():
         if self.selected_pose != None:
             break
         rospy.sleep(0.1)
     
     return PlacePositionSelectionResponse(self.selected_pose)
Esempio n. 8
0
 def init_step_info_area(self):
     self.connect(self.info_area_widget.treeWidget,
                  SIGNAL('itemDoubleClicked (QTreeWidgetItem *, int)'),
                  self.double_click)
     self.info_area_widget.treeWidget.setHeaderLabels(
         ["Index", "Object Name", "Maker", "tags"])
     self.info_area_widget.treeWidget.resizeColumnToContents(0)
     self.info_area_widget.treeWidget.resizeColumnToContents(1)
     self.info_area_widget.treeWidget.resizeColumnToContents(2)
     self.info_area_widget.treeWidget.resizeColumnToContents(3)
Esempio n. 9
0
    def next_step_selection_callback(self, req):
        self.next_step_selected = None
        self.emit(SIGNAL('nextStepSelection()'))

        while not rospy.is_shutdown():
            if self.next_step_selected:
                break
            rospy.sleep(0.1)

        return NextStepSelectionResponse(self.next_step_selected)
Esempio n. 10
0
    def __init__(self, sequence, config):
        QObject.__init__(self)
        #Will contain the results of the execution of this step
        self.results = None
        #Will contain the commands given by the user. This will be considered by subsequent steps
        self.commands = None
        #Dictionary of all the steps. This allows this object to have access to the info (results, user commands) from the other steps
        self.sequence_dict = sequence
        #Dictionary containing the configuration (name, tag, etc) for this step. This info comes from the yaml file
        self.config_dict = config
        #Information bar for this step shown in the sequence list. This will be loaded by a subclass
        self.info_bar_widget = None
        #Information area for this step shown when this step is active or selected. This will be loaded by a subclass
        self.info_area_widget = None

        #Listener for the feedback topic of this step's actionlib
        self.feedback_listener = None

        self_dir = os.path.dirname(os.path.realpath(__file__))
        self.bar_ui_dir = os.path.join(self_dir, '../../ui')
        self.ui_dir = None

        # info bar UI setup
        self.info_bar_widget = QFrame()
        ui_file = os.path.join(self.bar_ui_dir, 'StepBar.ui')
        loadUi(ui_file, self.info_bar_widget)
        #Connect info bar events
        self.info_bar_widget.show_checkBox.stateChanged.connect(
            self.on_show_checkbox_state_changed)
        self.connect(self, SIGNAL('changeProgressBarValue(int)'),
                     self.on_change_progress_bar_value)

        #Run and start buttons in the bar will be initially disabled as the first time we run the sequence
        #it only makes sense to start from the beginning
        self.info_bar_widget.btn_start.setEnabled(False)
        self.info_bar_widget.btn_run.setEnabled(False)
        self.info_bar_widget.btn_start.pressed.connect(
            self.on_btn_start_pressed)
        self.info_bar_widget.btn_run.pressed.connect(self.on_btn_run_pressed)
Esempio n. 11
0
    def draw(self):
        self.frame = QFrame(self)

        self.tree = QTreeWidget()
        self.connect(self.tree,
                     SIGNAL('itemDoubleClicked (QTreeWidgetItem *, int)'),
                     self.double_click)
        self.tree.setHeaderLabels(["Object Name", "Maker", "tags"])
        self.tree.resizeColumnToContents(0)
        self.tree.resizeColumnToContents(1)
        self.tree.resizeColumnToContents(2)

        self.layout = QVBoxLayout()
        self.layout.addWidget(self.title)
        self.layout.addWidget(self.tree)

        self.frame.setLayout(self.layout)
        layout = QVBoxLayout()
        layout.addWidget(self.frame)
        self.frame.show()
        self.setLayout(layout)
        self.show()
Esempio n. 12
0
 def action_server_feedback_callback(self, feedback_msg):
     self.emit(SIGNAL('currentStepReceived(PyQt_PyObject)'),
               feedback_msg.current_step)
Esempio n. 13
0
 def set_progress_bar_value(self, progress):
     self.emit(SIGNAL('changeProgressBarValue(int)'), progress)
    def __init__(self, context):
        super(HipViewerPlugin, self).__init__(context)
        self.setObjectName('HipViewer')

        self._current_dotcode = None

        self._widget = QWidget()

        ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               'hip_viewer.ui')
        loadUi(ui_file, self._widget,
               {'InteractiveGraphicsView': InteractiveGraphicsView})
        self._widget.setObjectName('HipViewerUi')
        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() +
                                        (' (%d)' % context.serial_number()))

        self._scene = QGraphicsScene()
        self._widget.graphics_view.setScene(self._scene)

        self._widget.graph_type_combo_box.insertItem(0, self.tr('infinite'),
                                                     -1)
        self._widget.graph_type_combo_box.insertItem(1, self.tr('1'), 2)
        self._widget.graph_type_combo_box.insertItem(2, self.tr('2'), 3)
        self._widget.graph_type_combo_box.insertItem(3, self.tr('3'), 4)
        self._widget.graph_type_combo_box.insertItem(4, self.tr('4'), 5)
        self._widget.graph_type_combo_box.setCurrentIndex(0)

        self._widget.refresh_graph_push_button.setIcon(
            QIcon.fromTheme('view-refresh'))

        self._widget.highlight_connections_check_box.toggled.connect(
            self._redraw_graph_view)
        self._widget.auto_fit_graph_check_box.toggled.connect(
            self._redraw_graph_view)
        self._widget.fit_in_view_push_button.setIcon(
            QIcon.fromTheme('zoom-original'))
        self._widget.fit_in_view_push_button.pressed.connect(self._fit_in_view)

        self._widget.load_dot_push_button.setIcon(
            QIcon.fromTheme('document-open'))
        self._widget.load_dot_push_button.pressed.connect(self._load_dot)
        self._widget.save_dot_push_button.setIcon(
            QIcon.fromTheme('document-save-as'))
        self._widget.save_dot_push_button.pressed.connect(self._save_dot)
        self._widget.save_as_svg_push_button.setIcon(
            QIcon.fromTheme('document-save-as'))
        self._widget.save_as_svg_push_button.pressed.connect(self._save_svg)
        self._widget.save_as_image_push_button.setIcon(
            QIcon.fromTheme('image'))
        self._widget.save_as_image_push_button.pressed.connect(
            self._save_image)

        self._deferred_fit_in_view.connect(self._fit_in_view,
                                           Qt.QueuedConnection)
        self._deferred_fit_in_view.emit()

        context.add_widget(self._widget)

        self.connect(self, SIGNAL('update_planning_graph'),
                     self.update_planning_graph_synchronous)

        # start the planner in a separate thread
        planning_node = HipViewerNode(ex_callback=self.update_planning_graph)
        planning_node.start()
 def update_planning_graph(self, op, htree):
     self.emit(SIGNAL('update_planning_graph'), op, htree)
Esempio n. 16
0
 def on_btn_run_pressed(self):
     self.emit(SIGNAL('runStepPressed(PyQt_PyObject)'),
               self.config_dict['name'])
Esempio n. 17
0
    def __init__(self, context):
        super(SrGuiEventSequence, self).__init__(context)

        self.setObjectName('SrGuiEventSequence')

        self_dir = os.path.dirname(os.path.realpath(__file__))
        self.config_dir = os.path.join(self_dir, '../../config')
        self.ui_dir = os.path.join(self_dir, '../../ui')

        # UI setup
        self._widget = QWidget()
        ui_file = os.path.join(self.ui_dir, 'SrGuiEventSequence.ui')
        loadUi(ui_file, self._widget)
        self._widget.setObjectName('SrGuiEventSequenceUi')
        context.add_widget(self._widget)

        #Step related
        self.current_step = None
        #To indicate that the step 0 hasn't been executed yet
        self.first_time = True
        #this list will be filled using the info in the yaml file
        self.step_names_list = []
        self.step_index_dict = {}

        #Dictionary containing the SequenceStep objects for every step in the sequence
        self.sequence_dict = {}
        #Dictionary containing the configuration of the steps read from the yaml file
        self.config_data = None
        #Read steps configuration from yaml file
        yaml_file = os.path.join(self.config_dir, 'sequence_config.yaml')
        try:
            self.config_data = yaml.load(open(yaml_file))
        except IOError as err:
            QMessageBox.warning(
                self._widget, "Warning",
                "Failed to load '" + yaml_file + "': " + str(err))
            raise

        #Autorun
        if self._widget.autorun_checkBox.isChecked():
            rospy.set_param('/master_controller/autorun', 1)
        else:
            rospy.set_param('/master_controller/autorun', 0)

        #Create the Master controller Client
        for (i, step) in enumerate(self.config_data['steps']):
            self.step_names_list.append(step['name'])
            self.step_index_dict[step['name']] = i

        self.master_controller_client = MasterControllerClient(
            self.step_names_list)
        #connect the signal to notify goal_done (all the steps in the sequence finished somehow)
        self.connect(self.master_controller_client,
                     SIGNAL('goalDone(PyQt_PyObject)'), self.on_MC_goal_done)
        #connect the signal to notify goal_done (all the steps in the sequence finished somehow)
        self.connect(self.master_controller_client,
                     SIGNAL('currentStepReceived(PyQt_PyObject)'),
                     self.on_MC_current_step_received)
        #connect the signal that notifies that the user should choose the next step to be run
        self.connect(self.master_controller_client,
                     SIGNAL('nextStepSelection()'),
                     self.on_MC_select_next_step)

        #Import and create an object of the class specified in the yaml for every step
        for step in self.config_data['steps']:
            roslib.load_manifest(step['package'])
            mod = __import__(step['package'] + '.' + step['module'],
                             fromlist=[step['class']])
            klass = getattr(mod, step['class'])
            self.sequence_dict[step['name']] = klass(self.sequence_dict, step)
            #Load the info bar widget for every step
            self._widget.step_list_layout.addWidget(
                self.sequence_dict[step['name']].info_bar_widget)
            #connect the signal to show the info for that step
            self.connect(self.sequence_dict[step['name']],
                         SIGNAL('showStateChanged(int, PyQt_PyObject)'),
                         self.on_show_state_changed)
            #connect the signal to start the sequence (using this step)
            self.connect(self.sequence_dict[step['name']],
                         SIGNAL('startStepPressed(PyQt_PyObject)'),
                         self.on_start_sequence_signal)
            #connect the signal to tell the MC that this step will be next
            self.connect(self.sequence_dict[step['name']],
                         SIGNAL('runStepPressed(PyQt_PyObject)'),
                         self.on_run_this_step_signal)
            #connect the signal to print a log to the general info area
            self.connect(
                self.sequence_dict[step['name']],
                SIGNAL(
                    'printGeneralInfoAreaLog(PyQt_PyObject, PyQt_PyObject)'),
                self.on_print_general_info_area_log)
            #connect the signal to tell the bar to make the run button visible
            self.connect(
                self, SIGNAL('showRunStepButtons(PyQt_PyObject)'),
                self.sequence_dict[step['name']].on_show_run_btn_signal)
            #connect the signal to tell the bar to make the run button visible
            self.connect(
                self, SIGNAL('showStartSequenceButtons(PyQt_PyObject)'),
                self.sequence_dict[step['name']].on_show_start_btn_signal)

        #Add a vertical spacer after the bars, to hold them together in the beginning of the vertical layout
        self._widget.step_list_layout.addStretch(0)

        self.general_info_area_widget = QWidget()
        ui_file = os.path.join(self.ui_dir, 'GeneralInfoArea.ui')
        loadUi(ui_file, self.general_info_area_widget)
        self._widget.general_info_area.addWidget(self.general_info_area_widget)

        #Load info area for the first step (maybe we shouldn't before it's running, but we'll show it for the time being)
        for step in self.config_data['steps']:
            if self.sequence_dict[step['name']].info_area_widget != None:
                self.current_step = step['name']
                self.shown_step_widget = self.sequence_dict[
                    self.current_step].info_area_widget
                self._widget.step_info_area.addWidget(self.shown_step_widget)
                break

        # Bind button clicks
        self._widget.btn_start.pressed.connect(self.on_btn_start_pressed)
        self._widget.btn_cancel.pressed.connect(self.on_btn_cancel_pressed)
        self._widget.btn_next.pressed.connect(self.on_btn_next_pressed)
        #Connect autorun check/uncheck events
        self._widget.autorun_checkBox.stateChanged.connect(
            self.on_autorun_checkbox_state_changed)

        #connect the signal to make the next (run) button visible
        self.connect(self, SIGNAL('showRunStepButtons(PyQt_PyObject)'),
                     self.on_show_next_btn_signal)
        #connect the signal to make the start button visible
        self.connect(self, SIGNAL('showStartSequenceButtons(PyQt_PyObject)'),
                     self.on_show_start_btn_signal)

        #We'll emit a signal to hide all the buttons to choose the next step
        self.emit(SIGNAL('showRunStepButtons(PyQt_PyObject)'), False)
Esempio n. 18
0
 def on_MC_select_next_step(self):
     #We'll emit a signal to show all the buttons to choose the next step
     self.emit(SIGNAL('showRunStepButtons(PyQt_PyObject)'), True)
Esempio n. 19
0
 def on_show_checkbox_state_changed(self, state):
     self.emit(SIGNAL('showStateChanged(int, PyQt_PyObject)'), state,
               self.config_dict['name'])
Esempio n. 20
0
 def print_general_info_area_log(self, log_msg):
     self.emit(
         SIGNAL('printGeneralInfoAreaLog(PyQt_PyObject, PyQt_PyObject)'),
         self.config_dict['name'], log_msg)
Esempio n. 21
0
 def on_start_sequence_signal(self, step_name):
     self.master_controller_client.on_start_step_signal(step_name)
     #We'll emit a signal to hide all the buttons to start sequence
     self.emit(SIGNAL('showStartSequenceButtons(PyQt_PyObject)'), False)
Esempio n. 22
0
def _on_cancel(pid):
    signaler.emit(SIGNAL('cancel(int)'), pid)
Esempio n. 23
0
 def finish(self):
     """
     Used to tell the progress is finished. Called by hyperspy side.
     """
     global signaler
     signaler.emit(SIGNAL('finished(int)'), self.id)
Esempio n. 24
0
 def on_run_this_step_signal(self, step_name):
     self.master_controller_client.next_step_selected = step_name
     #We'll emit a signal to hide all the buttons to choose the next step
     self.emit(SIGNAL('showRunStepButtons(PyQt_PyObject)'), False)
Esempio n. 25
0
    def __iter__(self):
        iterable = self.iterable
        if self.disable:
            for obj in iterable:
                if self.cancelled is True:
                    raise ProcessCanceled("User cancelled operation")
                yield obj
            return

        # ncols = self.ncols
        mininterval = self.mininterval
        maxinterval = self.maxinterval
        miniters = self.miniters
        dynamic_miniters = self.dynamic_miniters
        start_t = self.start_t
        last_print_t = self.last_print_t
        last_print_n = self.last_print_n
        n = self.n
        # dynamic_ncols = self.dynamic_ncols
        smoothing = self.smoothing
        avg_time = self.avg_time

        for obj in iterable:
            if self.cancelled is True:
                raise ProcessCanceled("User cancelled operation")
            yield obj
            # Update and print the progressbar.
            # Note: does not call self.update(1) for speed optimisation.
            n += 1
            delta_it = n - last_print_n
            # check the counter first (avoid calls to time())
            if delta_it >= miniters:
                cur_t = time()
                delta_t = cur_t - last_print_t
                if delta_t >= mininterval:
                    elapsed = cur_t - start_t
                    # EMA (not just overall average)
                    if smoothing and delta_t:
                        avg_time = delta_t / delta_it \
                            if avg_time is None \
                            else smoothing * delta_t / delta_it + \
                            (1 - smoothing) * avg_time

                    txt = self.format_string(
                        n, self.total, elapsed,
                        1 / avg_time if avg_time else None)

                    global signaler
                    signaler.emit(SIGNAL('progress(int, int, QString)'),
                                  self.id, n, txt)

                    # If no `miniters` was specified, adjust automatically
                    # to the maximum iteration rate seen so far.
                    if dynamic_miniters:
                        if maxinterval and delta_t > maxinterval:
                            # Set miniters to correspond to maxinterval
                            miniters = delta_it * maxinterval / delta_t
                        elif mininterval and delta_t:
                            # EMA-weight miniters to converge
                            # towards the timeframe of mininterval
                            miniters = smoothing * delta_it * mininterval \
                                / delta_t + (1 - smoothing) * miniters
                        else:
                            miniters = smoothing * delta_it + \
                                (1 - smoothing) * miniters

                    # Store old values for next call
                    last_print_n = n
                    last_print_t = cur_t

        # Closing the progress bar.
        # Update some internal variables for close().
        self.last_print_n = last_print_n
        self.n = n
        self.close()