Пример #1
0
 def on_new(self, boolean=False):
     """
     Handle a subsequence creation
     """
     new_subsequence = XMLSequence("New Subsequence")
     self.sequence.subsequences.append(new_subsequence)
     item = SequenceItem(self, new_subsequence, self.editor)
     self.setExpanded(True)
     item.setText(0, u"")
     item.on_rename()
     self.editor.set_changed(True, global_change=True)
Пример #2
0
 def on_new(self):
     """
     Create a new sequence
     """
     # Reset control
     if not self.control_widget.reset():
         return
     self.control_widget.disable()
     # Create new sequence
     self.file_path = None
     self.set_changed(False)
     self.current_sequence = XMLSequence("New sequence",
                                         depth=0,
                                         level=0,
                                         execution=False)
     # Update
     self.update()
     self.log('NEW : New sequence')
Пример #3
0
    def __init__(self, parent=None):
        # Setup UI
        super(EditorWidget, self).__init__(parent)
        self.ui = Ui_PySequenceEditor()
        self.ui.setupUi(self)

        # Customize UI
        self.ui.main_splitter.setStretchFactor(1, 1)
        self.ui.center_splitter.setStretchFactor(0, 1)
        self.logging_tab = LoggingTabWidget(parent=self)
        self.logging_tab.setTabPosition(QtGui.QTabWidget.South)
        self.logging_tab.log_table.verticalHeader().setDefaultSectionSize(20)
        self.logging_tab.resize(0, 0)
        self.ui.center_splitter.addWidget(self.logging_tab)
        self.ui.tab_widget.clear()
        self.control_widget = ControlWidget(parent=self)
        self.ui.horizontalLayout.insertWidget(13, self.control_widget)

        # Monkey Patching
        def dropEvent(self, event):
            QtGui.QTreeWidget.dropEvent(self, event)
            self.currentItemChanged.emit(None, None)

        sub_editor = self.ui.subsequence_editor
        sub_editor.dropEvent = types.MethodType(dropEvent, sub_editor)

        # Stream redirection
        self.save_stdout = sys.stdout
        self.save_stderr = sys.stderr
        safe_write = lambda arg: self.print_signal.emit(arg)
        safe_write.write = safe_write
        sys.stdout = sys.stderr = safe_write
        self.print_signal.connect(self.logging_tab.write)

        # Sequence Engine
        self.control_widget.enable_path_request()
        self.control_widget.path_requested.connect(self.on_path_requested)
        self.control_widget.log_signal.connect(self.log)

        # Property editor initialization
        self.block_model = BlockModel(self, parent=self.ui.property_editor)
        self.block_model.model_changed.connect(partial(self.set_changed, True))
        self.ui.property_editor.setModel(self.block_model)

        # Create block Mapping
        self.block_mapping = {
            "Begin/End": {
                'Begin': XBM.BEGIN,
                'End': XBM.END
            },
            "Time": {
                'Init': XBM.TIMEINIT,
                'Wait': XBM.WAIT
            },
            "Branch": {
                'Branch': XBM.BRANCH
            },
            "Subsequence": {
                'Macro': XBM.MACRO
            }
        }
        action_list = get_action_list()
        self.module_to_name = {module: name for name, module in action_list}
        for name, module in action_list:
            family = module.split(".")[-2].capitalize()
            self.block_mapping.setdefault(family,
                                          {})[name] = (XBM.ACTION, module)

        # Block list initialization
        self.ui.block_list.setHeaderLabels(['Block list'])
        self.fill_block_list()
        self.ui.block_list.expandAll()
        self.ui.block_list.resizeColumnToContents(0)
        self.ui.block_list.expandToDepth(0)

        # Sequence initialization
        self.current_sequence = XMLSequence("New sequence")

        # Signals connection
        self.ui.open_button.clicked.connect(self.on_open)
        self.ui.new_button.clicked.connect(self.on_new)
        self.ui.save_button.clicked.connect(self.on_save)
        self.ui.save_as_button.clicked.connect(self.on_save_as)
        self.ui.undo_button.clicked.connect(self.on_undo)
        self.ui.redo_button.clicked.connect(self.on_redo)
        self.ui.about_button.clicked.connect(self.on_about)
        self.ui.zoom_slider.valueChanged.connect(self.on_change_zoom_value)
        self.ui.block_list.itemClicked.connect(self.on_click_family)
        self.ui.tab_widget.tabCloseRequested.connect(self.on_close_tab)
        self.ui.tab_widget.currentChanged.connect(self.update_zoom_slider)
        sub_editor = self.ui.subsequence_editor
        sub_editor.itemDoubleClicked.connect(self.subsequence_double_clicked)
        sub_editor.itemActivated.connect(self.subsequence_activated)
        sub_editor.customContextMenuRequested.connect(self.context_requested)
        sub_editor.currentItemChanged.connect(self.subsequence_changed)
        QtGui.QShortcut(QtGui.QKeySequence.SelectAll, self, self.on_select_all)

        # Update
        self.file_path = None
        self.changed = False
        self.set_changed(False)
        self.update()

        # Logging
        self.log(u'Sequence editor initialized.')

        self.signal_handler = SignalHandler(logging.DEBUG)
        self.signal_handler.signal.connect(self.handle_log_record)
        add_log_handler(self.signal_handler)