Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        # Init GroupBox
        super(RunnerWidget, self).__init__(*args, **kwargs)
        self.resize(*self.base_size)
        self.saved_height = self.base_size[1]

        # Fist line
        self.vbox_layout = QtGui.QVBoxLayout(self)
        hbox_layout = QtGui.QHBoxLayout()
        self.filename_edit = QtGui.QLineEdit(self)
        self.select_button = QtGui.QPushButton(u'Select', self)
        self.edit_button = QtGui.QPushButton(u'Edit', self)
        self.new_button = QtGui.QPushButton(u'New', self)
        hbox_layout.addWidget(self.filename_edit, 1)
        hbox_layout.addWidget(self.select_button)
        hbox_layout.addSpacing(self.hspace)
        line = QtGui.QFrame(self)
        line.setFrameShape(QtGui.QFrame.VLine)
        line.setFrameShadow(QtGui.QFrame.Sunken)
        hbox_layout.addWidget(line)
        hbox_layout.addSpacing(self.hspace)
        hbox_layout.addWidget(self.edit_button)
        hbox_layout.addWidget(self.new_button)
        self.vbox_layout.addLayout(hbox_layout)
        self.vbox_layout.addSpacing(self.vspace)

        # Second line
        hbox_layout = QtGui.QHBoxLayout()
        hbox_layout.addWidget(QtGui.QLabel(u"Display Console:"))
        self.check_box = QtGui.QCheckBox(self)
        self.check_box.setChecked(True)
        hbox_layout.addWidget(self.check_box)
        hbox_layout.addStretch(1)
        hbox_layout.addSpacing(self.hspace)
        hbox_layout.addWidget(QtGui.QLabel(u"Sequence Control :"))
        hbox_layout.addSpacing(self.hspace)

        # Create control widget
        self.control_widget = ControlWidget(parent=self)
        self.control_widget.enable_path_request()
        self.control_widget.disable()
        hbox_layout.addWidget(self.control_widget)

        # Create logging tab
        self.logging_tab = LoggingTabWidget("CONSOLE INITIALIZED",
                                            parent=self)
        self.logging_tab.setTabPosition(QtGui.QTabWidget.South)
        self.logging_tab.log_table.verticalHeader().setDefaultSectionSize(20)
        self.logging_tab.setVisible(True)
        self.vbox_layout.addLayout(hbox_layout)
        self.vbox_layout.addSpacing(self.vspace)
        self.vbox_layout.addWidget(self.logging_tab)
        self.setLayout(self.vbox_layout)

        # Connect signals
        self.select_button.clicked.connect(self.on_select)
        self.check_box.stateChanged.connect(self.on_display_console)
        self.control_widget.log_signal.connect(self.logging_tab.log)
        self.control_widget.path_requested.connect(self.on_path_requested)
        self.filename_edit.textChanged.connect(self.on_path_changed)
        self.new_button.clicked.connect(self.open_editor)
        def open_with_file(_):
            return self.open_editor(True, self.filename_edit.text())
        self.edit_button.clicked.connect(open_with_file)
        if self.isWindow():
            self.size_changed.connect(self.custom_resize)
Ejemplo n.º 2
0
        else:
            self.eol = False
        # Write it
        cursor = self.log_console.textCursor()
        cursor.movePosition(QtGui.QTextCursor.End)
        cursor.insertText(string)
        self.log_console.setTextCursor(cursor)

    def log(self, text, end='\n'):
        """
        Method to properly log a message
        """
        return self.write(unicode(text) + end)


# Main execution to test the widget
if __name__ == '__main__':
    import sequence
    app = QtGui.QApplication(sys.argv)
    ui1 = LoggingTabWidget("LoggingTabWidget Initialized.")
    ui1.show()
    ui2 = ControlWidget(log_signal=ui1.log)
    path = os.path.join(os.path.dirname(sequence.__file__), os.pardir,
                        "examples", "BranchTest.xml")
    ui2.set_path(path)
    ui2.enable()
    ui2.show()
    sys.stdout = ui1
    print("Test print : OK !")
    sys.exit(app.exec_())
Ejemplo n.º 3
0
        i = self.rowCount()
        self.insertRow(i)
        for j, item in enumerate(log_item):
            self.setItem(i, j, item)

    def remove_log_item(self, item):
        """
        Remove a Tango Event from the widget
        """
        self.removeRow(item.row())


# Main execution to test the widget
if __name__ == '__main__':
    import sequence
    app = QtGui.QApplication(sys.argv)

    def print_in_console(msg, end):
        sys.stdout.write(msg + end)
        sys.stdout.flush()

    ui1 = ControlWidget(log_signal=print_in_console)
    path = os.path.join(os.path.dirname(sequence.__file__), os.pardir,
                        "examples", "BranchTest.xml")
    ui1.set_path(path)
    ui1.enable()
    ui1.show()
    ui2 = LoggingWidget()
    ui2.show()
    sys.exit(app.exec_())
Ejemplo n.º 4
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)