Ejemplo n.º 1
1
class VectorDatabaseFrame(GenericFrame):
    def __init__(self, parent):
        super().__init__(QHBoxLayout(), 'Vector Database', parent)
        self.vectors = None
        self.vector_info = VectorInformationFrame()
        self.list = QListWidget()
        self.dialog = None

        self.buttons = QToolBar('Buttons')

        self.init_list()
        self.init_frame()

        self.list.itemClicked.connect(self.unsaved_dialog)
        self.vector_info.save_changes.clicked.connect(
            lambda: self.list.currentItem().setText(
                self.vector_info.currentVector.data.get("Name")))

    def init_frame(self):
        self.setFrameShape(QFrame.StyledPanel)
        self.init_buttons()

        self.layout.addWidget(self.list)
        self.layout.addWidget(self.vector_info)
        self.layout.addWidget(self.buttons)
        self.setMinimumSize(600, 400)

    def init_buttons(self):
        self.buttons.setOrientation(Qt.Vertical)
        self.buttons.setMovable(False)
        self.buttons.setStyleSheet("""
                    QToolBar {
                        spacing: 6px;
                        padding: 3px;
                    }
                """)

        # Buttons after this are set to the right side
        spacer = QWidget()
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.buttons.addWidget(spacer)

        b1 = QPushButton('Add Vector')
        self.buttons.addWidget(b1)
        b1.clicked.connect(self.add_vector)

        b2 = QPushButton('Delete Vector')
        self.buttons.addWidget(b2)
        b2.clicked.connect(self.delete_vector_dialog)

        spacer = QWidget()
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.buttons.addWidget(spacer)

        b3 = QPushButton('Close')
        self.buttons.addWidget(b3)
        b3.clicked.connect(self.check_status)

    def init_list(self):
        self.vectors = get_vector_list()

        if self.vectors:
            for vector in self.vectors:
                self.list.addItem(vector.get("Name"))
            self.list.setCurrentItem(self.list.itemAt(0, 0))
            self.vector_info.update_frame(self.list.currentItem())

    def add_vector(self):
        v = Vector()
        self.vectors.append(v.data)

        self.list.addItem(self.vectors[-1].get("Name"))
        self.list.setCurrentItem(self.list.item(self.list.count() - 1))
        self.vector_info.update_frame(self.list.currentItem())

    def delete_vector_dialog(self):
        self.dialog = GenericWindow(QGridLayout())
        dialog_delete = QPushButton("Delete")
        dialog_cancel = QPushButton("Cancel")

        self.dialog.layout.addWidget(QLabel("Delete current vector?"), 0, 1)
        self.dialog.layout.addWidget(dialog_delete, 1, 0)
        self.dialog.layout.addWidget(dialog_cancel, 1, 2)

        dialog_delete.clicked.connect(self.dialog_confirm_delete)
        dialog_cancel.clicked.connect(self.dialog_cancel)
        self.dialog.show()

    def unsaved_dialog(self, vector, closeParent=None):
        if self.vector_info.save_changes.isEnabled():
            self.dialog = GenericWindow(QGridLayout(), self)
            dialog_confirm = QPushButton("Continue")
            dialog_cancel = QPushButton("Cancel")

            self.dialog.layout.addWidget(
                QLabel(
                    "Changes to current vector are pending.\nContinue without saving?"
                ), 0, 1)
            self.dialog.layout.addWidget(dialog_confirm, 1, 0)
            self.dialog.layout.addWidget(dialog_cancel, 1, 2)

            if closeParent is not None:
                dialog_confirm.clicked.connect(self.dialog_confirm_exit)
            else:
                dialog_confirm.clicked.connect(self.dialog_confirm_change)

            dialog_cancel.clicked.connect(self.dialog_cancel)
            self.dialog.show()
        else:
            self.vector_info.update_frame(vector)

    def dialog_confirm_exit(self):
        self.dialog.close()
        self.parentWidget().close()

    def dialog_confirm_change(self):
        self.vector_info.update_frame(self.list.currentItem())
        self.dialog.close()

    def dialog_confirm_delete(self):
        del_object("Name",
                   self.list.takeItem(self.list.currentRow()).text(), "Vector")
        if self.list.count() > 0:
            self.list.setCurrentItem(self.list.itemAt(0, 0))
            self.vector_info.update_frame(self.list.currentItem())
        else:
            self.vector_info.reset_frame()
        self.dialog.close()

    def dialog_cancel(self):
        self.list.setCurrentItem(
            self.list.findItems(
                self.vector_info.currentVector.data.get("Name"),
                Qt.MatchExactly)[0])
        self.dialog.close()

    def check_status(self):
        if not self.vector_info.save_changes.isEnabled():
            self.parentWidget().close()
        else:
            self.unsaved_dialog(self.vector_info.currentVector, True)
Ejemplo n.º 2
0
    def __createToolbar(self):
        self.buttons = {}

        toolbar = QToolBar("bottom toolbar")
        toolbar.setOrientation(Qt.Horizontal)
        toolbar.setAllowedAreas(Qt.BottomToolBarArea)
        toolbar.setIconSize(QSize(32, 32))

        button1 = QPushButton("Show All")
        toolbar.addWidget(button1)
        toolbar.addSeparator()

        button2 = QPushButton("Play")
        toolbar.addWidget(button2)
        toolbar.addSeparator()

        button3 = QPushButton("Stop")
        toolbar.addWidget(button3)
        toolbar.addSeparator()

        button4 = QPushButton("Record")
        toolbar.addWidget(button4)
        toolbar.addSeparator()

        self.addToolBar(Qt.BottomToolBarArea, toolbar)
Ejemplo n.º 3
0
    def __init__(self, wallet_api: WalletAPI, parent: Optional['ElectrumWindow']=None):
        super().__init__(parent)

        self._context = ListContext(wallet_api, self)

        cards = ContactCards(self._context, self)
        self.setStyleSheet(contactcard_stylesheet)

        add_contact_action = QAction(self)
        add_contact_action.setIcon(read_QIcon("icons8-plus-blueui.svg"))
        add_contact_action.setToolTip(_("Add new contact"))
        add_contact_action.triggered.connect(self._on_add_contact_action)

        sort_action = QAction(self)
        sort_action.setIcon(read_QIcon("icons8-alphabetical-sorting-2-80-blueui.png"))
        sort_action.setToolTip(_("Sort"))
        sort_action.triggered.connect(self._on_sort_action)

        toolbar = QToolBar(self)
        toolbar.setMovable(False)
        toolbar.setOrientation(Qt.Vertical)
        toolbar.setToolButtonStyle(Qt.ToolButtonIconOnly)
        toolbar.addAction(add_contact_action)
        toolbar.addAction(sort_action)

        self._layout = QHBoxLayout()
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        self._layout.addWidget(cards)
        self._layout.addWidget(toolbar)
        self.setLayout(self._layout)

        self._cards = cards
        self._sort_action = sort_action
        self._sort_type = 1
Ejemplo n.º 4
0
    def __init__(self, wallet_api: WalletAPI, parent: QWidget) -> None:
        super().__init__(parent)

        self._context = ListContext(wallet_api, self)

        cards = Cards(self._context, self)

        sort_action = QAction(self)
        sort_action.setIcon(
            read_QIcon("icons8-alphabetical-sorting-2-80-blueui.png"))
        sort_action.setToolTip(_("Sort"))
        sort_action.triggered.connect(self._on_sort_action)
        sort_action.setEnabled(self._context.sortable_list)

        toolbar = QToolBar(self)
        toolbar.setMovable(False)
        toolbar.setOrientation(Qt.Vertical)
        toolbar.setToolButtonStyle(Qt.ToolButtonIconOnly)
        toolbar.addAction(sort_action)

        self._layout = QHBoxLayout()
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        self._layout.addWidget(cards)
        self._layout.addWidget(toolbar)
        self.setLayout(self._layout)

        self._cards = cards
        self._sort_action = sort_action
        self._sort_type = 1
Ejemplo n.º 5
0
    def _init_ui(self):
        color = QColor(255, 255, 255)
        palette = QPalette(color)

        main_box = QHBoxLayout(self)
        settings_tlbr = QToolBar(self)
        settings_tlbr.setOrientation(Qt.Vertical)
        tblr_font = QFont("Times", 14)
        settings_tlbr.setFont(tblr_font)
        main_box.addWidget(settings_tlbr)
        fuselage_act = QAction("Fuselage", self)
        fuselage_act.setObjectName("fuselage_act")
        fuselage_act.setCheckable(True)
        fuselage_act.setChecked(True)
        fuselage_act.triggered.connect(self._show_widget)
        settings_tlbr.addAction(fuselage_act)
        fuselage_tab = FuselageWidget(self)
        fuselage_tab.setObjectName("fuselage_tab")
        fuselage_tab.setPalette(palette)
        fuselage_tab.setAutoFillBackground(True)
        fuselage_tab.copter_changed.connect(self._copter_changed)
        self.current_action = fuselage_act
        self.main_widget = fuselage_tab
        main_box.addWidget(fuselage_tab)
        if self.copter.equal_engines:
            engine_act = QAction("Engines", self)
            engine_act.setObjectName("engine_act")
            engine_act.setCheckable(True)
            engine_act.setChecked(False)
            engine_act.triggered.connect(self._show_widget)
            settings_tlbr.addAction(engine_act)
            engine_tab = EngineWidget(self)
            engine_tab.setObjectName("engine_tab")
            engine_tab.setPalette(palette)
            engine_tab.setAutoFillBackground(True)
            engine_tab.copter_changed.connect(self._copter_changed)
            main_box.addWidget(engine_tab)
            engine_tab.hide()
        else:
            for i in range(self.copter.num_of_engines):
                engine_act = QAction("Engine {}".format(i + 1), self)
                engine_act.setObjectName("engine_act_{}".format(i))
                engine_act.setCheckable(True)
                engine_act.setChecked(False)
                engine_act.triggered.connect(self._show_widget)
                settings_tlbr.addAction(engine_act)
                engine_tab = EngineWidget(self, i)
                engine_tab.setObjectName("engine_tab_{}".format(i))
                engine_tab.setPalette(palette)
                engine_tab.setAutoFillBackground(True)
                engine_tab.copter_changed.connect(self._copter_changed)
                main_box.addWidget(engine_tab)
                engine_tab.hide()
        for action in settings_tlbr.actions():
            widget = settings_tlbr.widgetForAction(action)
            widget.setFixedWidth(115)
        self.setLayout(main_box)
        return
Ejemplo n.º 6
0
 def createToolBars(self):
     filetoolbar = QToolBar()
     if filetoolbar.iconSize().width() < 36:
         iconSize = QSize(36, 36)
         filetoolbar.setIconSize(iconSize)
     self.addToolBar(Qt.LeftToolBarArea, filetoolbar)
     filetoolbar.setOrientation(Qt.Vertical)
     filetoolbar.addAction(self.commitAct)
     filetoolbar.addAction(self.exitAct)
    def _init_ui(self):
        color = QColor(255, 255, 255)
        palette = QPalette(color)

        main_box = QHBoxLayout(self)
        settings_tlbr = QToolBar(self)
        settings_tlbr.setOrientation(Qt.Vertical)
        tblr_font = QFont("Times", 14)
        settings_tlbr.setFont(tblr_font)

        simulation_act = QAction("Simulation settings", self)
        simulation_act.setObjectName("simulation_act")
        simulation_act.setCheckable(True)
        simulation_act.setChecked(True)
        simulation_act.triggered.connect(self._show_widget)
        settings_tlbr.addAction(simulation_act)
        simulation_tab = SimSettingsWidget(self)
        simulation_tab.setObjectName("simulation_tab")
        simulation_tab.setPalette(palette)
        simulation_tab.setAutoFillBackground(True)
        simulation_tab.settings_changed.connect(self._settings_changed)
        self.current_action = simulation_act
        self.main_widget = simulation_tab

        copter_act = QAction("Start settings", self)
        copter_act.setObjectName("start_act")
        copter_act.setCheckable(True)
        copter_act.setChecked(False)
        copter_act.triggered.connect(self._show_widget)
        settings_tlbr.addAction(copter_act)
        copter_tab = SimSettingsStartWidget(self)
        copter_tab.setObjectName("start_tab")
        copter_tab.setPalette(palette)
        copter_tab.setAutoFillBackground(True)
        copter_tab.settings_changed.connect(self._settings_changed)
        copter_tab.hide()

        save_act = QAction("Save settings", self)
        save_act.setObjectName("save_act")
        save_act.setEnabled(False)
        save_act.triggered.connect(self._save_settings)
        settings_tlbr.addAction(save_act)

        main_box.addWidget(settings_tlbr)
        main_box.addWidget(simulation_tab)
        main_box.addWidget(copter_tab)
        for action in settings_tlbr.actions():
            widget = settings_tlbr.widgetForAction(action)
            widget.setFixedWidth(200)
        self.setLayout(main_box)
        return
Ejemplo n.º 8
0
	def __init__(self):
		QWidget.__init__(self)
		edit_boxes=QWidget()
		vbox=QVBoxLayout()

		self.lumo=equation_editor("lumo0.inp","LUMO")
		vbox.addWidget(self.lumo)
		
		self.h**o=equation_editor("homo0.inp","H**O")
		vbox.addWidget(self.h**o)
		
		
		edit_boxes.setLayout(vbox)

		hbox=QHBoxLayout()

		toolbar=QToolBar()
		toolbar.setIconSize(QSize(48, 48))
		toolbar.setOrientation(Qt.Vertical)
		add = QAction(QIcon(os.path.join(get_image_file_path(),"save.png")),  _("Save"), self)
		add.triggered.connect(self.callback_save)
		toolbar.addAction(add)

		hbox.addWidget(toolbar)

		self.LUMO_fig = Figure(figsize=(5,4), dpi=100)


		self.draw_graph_lumo()
		self.canvas_lumo = FigureCanvas(self.LUMO_fig)
		self.canvas_lumo.figure.patch.set_facecolor('white')

		self.LUMO_fig.tight_layout(pad=0.5)

		hbox.addWidget(self.canvas_lumo)


		hbox.addWidget(edit_boxes)
		
		self.setLayout(hbox)
		
		self.lumo.changed.connect(self.update_graph)
		self.h**o.changed.connect(self.update_graph)
Ejemplo n.º 9
0
    def __init__(self):
        QWidget.__init__(self)
        edit_boxes = QWidget()
        vbox = QVBoxLayout()

        self.lumo = equation_editor("lumo0.inp", "LUMO")
        vbox.addWidget(self.lumo)

        self.h**o = equation_editor("homo0.inp", "H**O")
        vbox.addWidget(self.h**o)

        edit_boxes.setLayout(vbox)

        hbox = QHBoxLayout()

        toolbar = QToolBar()
        toolbar.setIconSize(QSize(48, 48))
        toolbar.setOrientation(Qt.Vertical)
        add = QAction(QIcon_load("document-save-as"), _("Save"), self)
        add.triggered.connect(self.callback_save)
        toolbar.addAction(add)

        hbox.addWidget(toolbar)

        self.LUMO_fig = Figure(figsize=(5, 4), dpi=100)

        self.draw_graph_lumo()
        self.canvas_lumo = FigureCanvas(self.LUMO_fig)
        self.canvas_lumo.figure.patch.set_facecolor('white')

        self.LUMO_fig.tight_layout(pad=0.5)

        hbox.addWidget(self.canvas_lumo)

        hbox.addWidget(edit_boxes)

        self.setLayout(hbox)

        self.lumo.changed.connect(self.update_graph)
        self.h**o.changed.connect(self.update_graph)
Ejemplo n.º 10
0
class Record(object):
	def __init__(self):
		r = Record()
		r.foo = 'oof'
		setattr(r, 'bar', 'rab')
		r.foo
		'oof'
		r.bar
		'rab'
		names = 'id description price'.split()
		values = [666, 'duct tape', 3.45]
		s = Record()
		for name, value in zip(names, values):
			setattr(s, name, value)
		s.__dict__ # If you are suffering from dict withdrawal symptoms
		{'price': 3.45, 'id': 666, 'description': 'duct tape'}
		return self
	def appToolBar(self, QToolBar, cfg):
		'Create a Toolbar from configurations file'
		pxcfg = here+'z-data_/desktop.yaml'
		self.config = config.instruct(pxcfg).select(
								'docAddToolBar').override(cfg)#	||
		self.createToolBar()
		for button, cfg in self.config['buttons'].items():
			self.createButton(button, cfg)
	def createToolBar(self):
		self.toolbar = QToolBar()
		self.toolbar.setMovable(True)
		self.toolbar.setFloatable(True)
		self.toolbar.setOrientation(Qt.Vertical)
		return self
	def createButton(self, button, cfg):
		''
		toolbutton = QToolButton()
		toolbutton.setText(cfg['DisplayName'])
		toolbutton.setCheckable(cfg['checkable'])
		toolbutton.setAutoExclusive(cfg['setAutoExclusive'])
		self.toolbar.addWidget(toolbutton)
		return self
Ejemplo n.º 11
0
    def setup(self, toolbar_widget: QtWidgets.QToolBar):
        toolbar_widget.setOrientation(QtCore.Qt.Vertical)

        pan_icon = QtGui.QIcon(":/image/pan.png")
        pan = toolbar_widget.addAction(pan_icon, "Pan")
        pan.setCheckable(True)

        zoom_icon = QtGui.QIcon(":/image/zoom.png")
        zoom = toolbar_widget.addAction(zoom_icon, "Zoom")
        zoom.setCheckable(True)

        reset_icon = QtGui.QIcon(":/image/home.png")
        reset = toolbar_widget.addAction(reset_icon, "Reset")

        def f(checked, a):
            if checked:
                a.setChecked(False)

        pan.triggered.connect(self._onPan)
        zoom.triggered.connect(self._onZoom)
        reset.triggered.connect(self._onReset)

        self.pan_action = pan
        self.zoom_action = zoom
Ejemplo n.º 12
0
class TransCodaEditor(QWidget):
    encoder_changed = pyqtSignal('PyQt_PyObject', 'PyQt_PyObject')

    def __init__(self, caption="Trans:Coda Editor"):
        super().__init__()
        self.encoder = EncoderSelector()
        self.encoder_view = EncoderView()
        self.actions = QToolBar()
        self.caption = caption
        self.add_action = CommonUtils.create_action(
            tooltip="Add Encoder",
            icon=TransCoda.theme.ico_add_item,
            func=self.action_add,
            name="Add",
            parent=self)
        self.del_action = CommonUtils.create_action(
            tooltip="Delete Encoder",
            icon=TransCoda.theme.ico_clear,
            func=self.action_del,
            name="Delete",
            parent=self)
        self.mod_action = CommonUtils.create_action(
            tooltip="Edit Encoder",
            icon=TransCoda.theme.ico_edit,
            func=self.action_mod,
            name="Edit",
            parent=self)
        self.ref_action = CommonUtils.create_action(
            tooltip="Refresh Encoder",
            icon=TransCoda.theme.ico_refresh,
            func=self.action_ref,
            name="Refresh",
            parent=self)
        self._init_ui()

    def _init_ui(self):
        self.encoder.encoder_changed.connect(self._configure_toolbar)
        self.actions.setOrientation(Qt.Horizontal)
        self.actions.addActions([
            self.add_action, self.del_action, self.mod_action, self.ref_action
        ])
        self.actions.setContentsMargins(0, 0, 0, 0)
        q_size = QSize(16, 16)
        self.actions.setIconSize(q_size)
        self._configure_toolbar(None, None)

        h_layout = QHBoxLayout()
        h_layout.setContentsMargins(0, 0, 0, 0)
        h_layout.addWidget(QLabel(f"<u>{self.caption}</u>"), 1)
        h_layout.addWidget(self.actions)
        v_layout = QVBoxLayout()
        v_layout.setContentsMargins(0, 0, 0, 0)
        v_layout.addLayout(h_layout)
        v_layout.addWidget(self.encoder)
        self.setMinimumWidth(400)

        self.setLayout(v_layout)

    def action_add(self, _):
        self.encoder_view.update_view("Add Encoder")
        if self.encoder_view.exec() == QDialog.Accepted:
            media_type, encoder_group, name, command, executable, extension = self.encoder_view.get_details(
            )
            self.encoder.add_encoder(media_type, encoder_group, name, command,
                                     executable, extension)

    def action_del(self, _):
        path, _ = self.encoder.get_encoder()
        tokens = path.split(EncoderSelector.__PATH_SEPARATOR__)
        self.encoder.del_encoder(tokens[0], tokens[1], tokens[2])

    def action_mod(self, _):
        path, encoder = self.encoder.get_encoder()
        self.encoder_view.update_view("Modify Encoder",
                                      encoder_path=path,
                                      encoder=encoder)
        if self.encoder_view.exec() == QDialog.Accepted:
            media_type, encoder_group, name, command, executable, extension = self.encoder_view.get_details(
            )
            self.encoder.update_encoder(media_type, encoder_group, name,
                                        command, executable, extension)

    def action_ref(self, _):
        self.encoder.refresh_encoders()

    def select_encoder(self, encoder_name):
        return self.encoder.select_encoder(encoder_name)

    def _configure_toolbar(self, path, encoder):
        self.mod_action.setEnabled(True if encoder else False)
        self.del_action.setEnabled(True if encoder else False)
        if encoder:
            self.encoder_changed.emit(path, encoder)
Ejemplo n.º 13
0
    def createUi(self):
        self.setWindowTitle(QCoreApplication.applicationName())
        self.view = SceneView(self.scene)
        self.view.setSceneRect(-100, -100,
                               self.scene.width() + 200,
                               self.scene.height() + 200)
        self.view.setRenderHint(QPainter.RenderHint.Antialiasing)
        #connect(self.scene, SIGNAL(selectionChanged()), this, SLOT(sceneSelectionChanged()))
        #connect(self.scene, SIGNAL(itemAdded(QGraphicsItem*)), this, SLOT(sceneItemAdded(QGraphicsItem*)))
        #connect(self.scene, SIGNAL(sizeChanged(int,int)), this, SLOT(sceneSizeChanged(int, int)))
        #connect(self.scene, SIGNAL(itemRemoved(AnimationItem*)), this, SLOT(sceneItemRemoved(AnimationItem*)))
        #connect(self.scene, SIGNAL(animationResetted()), this, SLOT(reset()))
        w = QWidget()
        vbox = QVBoxLayout()
        hbox = QHBoxLayout()
        zoom = QComboBox()
        zoom.addItem("1:2")
        zoom.addItem("1:1")
        zoom.addItem("2:1")
        zoom.addItem("4:1")
        zoom.addItem("8:1")
        zoom.setCurrentIndex(1)
        zoom.currentIndexChanged.connect(self.changeZoom)
        vbox.addWidget(self.view)
        vbox.addLayout(hbox)
        hbox.addWidget(zoom)
        hbox.addStretch()
        w.setLayout(vbox)
        self.setCentralWidget(w)

        toolpanel = QToolBar()
        anActionGroup = QActionGroup(toolpanel)
        self.selectAct = QAction("Select", anActionGroup)
        self.selectAct.setIcon(QIcon(":/images/arrow.png"))
        self.selectAct.setCheckable(True)

        self.rectangleAct = QAction("Rectangle", anActionGroup)
        self.rectangleAct.setIcon(QIcon(":/images/rectangle.png"))
        self.rectangleAct.setCheckable(True)

        self.ellipseAct = QAction("Ellipse", anActionGroup)
        self.ellipseAct.setIcon(QIcon(":/images/ellipse.png"))
        self.ellipseAct.setCheckable(True)

        self.textAct = QAction("Text", anActionGroup)
        self.textAct.setIcon(QIcon(":/images/text.png"))
        self.textAct.setCheckable(True)

        self.bitmapAct = QAction("Bitmap", anActionGroup)
        self.bitmapAct.setIcon(QIcon(":/images/camera.png"))
        self.bitmapAct.setCheckable(True)

        self.svgAct = QAction("Vectorgraphic", anActionGroup)
        self.svgAct.setIcon(QIcon(":/images/svg.png"))
        self.svgAct.setCheckable(True)

        toolpanel.setOrientation(Qt.Vertical)
        toolpanel.addAction(self.selectAct)
        toolpanel.addAction(self.rectangleAct)
        toolpanel.addAction(self.ellipseAct)
        toolpanel.addAction(self.textAct)
        toolpanel.addAction(self.bitmapAct)
        toolpanel.addAction(self.svgAct)

        self.tooldock = QDockWidget("Tools", self)
        self.tooldock.setAllowedAreas(Qt.LeftDockWidgetArea
                                      | Qt.RightDockWidgetArea)
        self.tooldock.setWidget(toolpanel)
        self.tooldock.setObjectName("Tools")
        self.addDockWidget(Qt.LeftDockWidgetArea, self.tooldock)

        self.scenePropertyEditor = ScenePropertyEditor()
        self.scenePropertyEditor.setScene(self.scene)
        self.propertiesdock = QDockWidget("Properties", self)
        self.propertiesdock.setAllowedAreas(Qt.LeftDockWidgetArea
                                            | Qt.RightDockWidgetArea)
        self.propertiesdock.setWidget(self.scenePropertyEditor)
        self.propertiesdock.setObjectName("Properties")
        self.addDockWidget(Qt.RightDockWidgetArea, self.propertiesdock)

        self.selectAct.triggered.connect(self.setSelectMode)
        self.rectangleAct.triggered.connect(self.setRectangleMode)
        self.ellipseAct.triggered.connect(self.setEllipseMode)
        self.textAct.triggered.connect(self.setTextMode)
        self.bitmapAct.triggered.connect(self.setBitmapMode)
        self.svgAct.triggered.connect(self.setSvgMode)
Ejemplo n.º 14
0
 def toolBar(self):
     toolBar = QToolBar()
     toolBar.setOrientation(Qt.Vertical)
     toolBar.addAction("Sujet supplémentaire").triggered.connect(self.addItem)
     toolBar.addAction("Supprimer sujet").triggered.connect(self.removeItem)
     return toolBar
Ejemplo n.º 15
0
class VoiceEditor(QWidget):
    """ This class implements an editor capable to load, edit and save pages.
    """

    # signal emitted when asking to load the next voice
    loadNextVoice = pyqtSignal(name='loadNextVoice')

    def __init__(self, connection, diff):
        """ Object initialization.

        Parameters
        ----------
        self : QWidget
        connection : Connection
            Object managing the connection to the wiki.
        diff : Diff
            Diff widget to be used by this editor.
        """

        super().__init__()

        self.connection = connection
        self.diff = diff
        self.originalContent = ''

        ## ACTIONS

        # save voice
        saveVoiceAction = QAction(
                QIcon('icons/document-save'),
                'Save voice', self)
        saveVoiceAction.setStatusTip('Save the voice content in the wiki')
        saveVoiceAction.triggered.connect(self.savePageContent)
        # save voice and load next one
        saveAndNextAction = QAction(
                QIcon('icons/save-and-next.svg'),
                'Save and next', self)
        saveAndNextAction.setStatusTip('Save the voice and load next one')
        saveAndNextAction.triggered.connect(self.saveAndNextVoice)
        # load next voice discarding changes
        nextVoiceAction = QAction(
                QIcon('icons/arrow-right'),
                'Next', self)
        nextVoiceAction.setStatusTip('Load the next voice discarding changes')
        nextVoiceAction.triggered.connect(self.loadNextVoice.emit)
        # clean editor discarding changes
        clearAction = QAction(
                QIcon('icons/window-close'),
                'Clear', self)
        clearAction.setStatusTip('Clean the editor discarding changes')
        clearAction.triggered.connect(self.clear)
        # show diff
        diffAction = QAction(
                QIcon('icons/sort-presence'),
                'Show changes', self)
        diffAction.setStatusTip('Show changes for the current the edit')
        diffAction.triggered.connect(self.showDiff)

        ## TOOLBARS

        # Actions
        self.actionsToolbar = QToolBar('Actions')
        self.actionsToolbar.addActions([
            diffAction,
            saveVoiceAction,
            saveAndNextAction,
            nextVoiceAction,
            clearAction])
        self.actionsToolbar.setOrientation(Qt.Vertical)

        ## WIDGETS

        self.pageTitle = QLineEdit()
        self.pageTitle.setDisabled(True)
        titleLayout = QHBoxLayout()
        titleLayout.addWidget(QLabel('Title:'))
        titleLayout.addWidget(self.pageTitle)
        titleWidget = QWidget()
        titleWidget.setLayout(titleLayout)

        self.pageContent = QPlainTextEdit()
        self.pageContent.setTabChangesFocus(True)

        summaryLabel = QLabel('Summary:')
        self.summary = QLineEdit()
        summaryHBox = QHBoxLayout()
        summaryHBox.addWidget(summaryLabel)
        summaryHBox.addWidget(self.summary)
        summaryWidget = QWidget()
        summaryWidget.setLayout(summaryHBox)

        self.editToolbar = EditToolbar(self, self.pageContent)

        vbox = QVBoxLayout()
        vbox.addWidget(titleWidget)
        vbox.addWidget(self.editToolbar)
        vbox.addWidget(self.pageContent)
        vbox.addWidget(summaryWidget)

        hbox = QHBoxLayout()
        hbox.addLayout(vbox)
        hbox.addWidget(self.actionsToolbar)

        self.setLayout(hbox)

    def savePageContent(self):
        """ Save the page content making an edit in the wiki.
        """
        # ensure there is an opened voice
        if self.pageTitle.text() == '':
            return

        self.connection.edit(
                self.pageTitle.text(),
                self.pageContent.toPlainText(),
                self.summary.text())

    def saveAndNextVoice(self):
        """ Save the page content and load the next voice in the list.
        """
        # save current voice
        self.savePageContent()
        # ask to load next voice
        self.loadNextVoice.emit()

    def clear(self):
        """ Clear the editor content.
        """
        self.pageContent.setPlainText('')
        self.pageTitle.setText('')
        self.originalContent = ''

    def showDiff(self):
        """ Show the diff between the original text and the current text in
        the editor.
        """

        # ensure there is an opened voice
        if self.pageTitle.text() == '':
            return

        # show diff widget if disabled
        if not self.diff.isVisible():
            self.diff.setVisible(True)

        self.diff.showDiff(self.originalContent, self.pageContent.toPlainText())
Ejemplo n.º 16
0
class LibraryGroupingManager(CollapsibleWidget):
    def __init__(self):
        super().__init__("Library Tree Group Manager")
        self.source = QListWidget()
        self.target = QListWidget()
        self.action_toolbar = QToolBar()
        self.add_action = CommonUtils.create_toolbar_action(
            "Add selected key to grouping",
            QIcon.fromTheme("media-skip-forward"), self.add)
        self.sub_action = CommonUtils.create_toolbar_action(
            "Remove selected key to grouping",
            QIcon.fromTheme("media-skip-backward"), self.sub)
        self.reset_action = CommonUtils.create_toolbar_action(
            "Reset to library type default",
            QIcon.fromTheme("document-revert"), self.reset)
        self.apply_action = CommonUtils.create_toolbar_action(
            "Apply this view", QIcon.fromTheme("document-save"), self.save)
        self.icon = QIcon.fromTheme("folder")
        self._init_ui()

    def _init_ui(self):
        self.action_toolbar.setOrientation(Qt.Vertical)
        dummy = QWidget()
        dummy.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.action_toolbar.addWidget(dummy)
        self.action_toolbar.addActions([
            self.add_action, self.sub_action, self.reset_action,
            self.apply_action
        ])
        self.action_toolbar.setContentsMargins(0, 0, 0, 0)
        q_size = QSize(16, 16)
        self.action_toolbar.setIconSize(q_size)
        self.source.setIconSize(q_size)
        self.source.setMaximumHeight(120)
        self.target.setIconSize(q_size)
        self.target.setMaximumHeight(120)
        layout = QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        layout.addWidget(self.source)
        layout.addWidget(self.action_toolbar)
        layout.addWidget(self.target)
        self.set_content_layout(layout)

    def update_grouping(self, grouping):
        self.source.clear()
        for key in grouping:
            item = QListWidgetItem(self.icon, key)
            self.source.addItem(item)

    def add(self):
        self.swap_items(self.source, self.target)

    def sub(self):
        self.swap_items(self.target, self.source)

    def save(self):
        pass

    def reset(self):
        pass

    @staticmethod
    def swap_items(source, target):
        list_items = source.selectedItems()
        if not list_items:
            return
        for item in list_items:
            source.takeItem(source.row(item))
            target.addItem(item)
Ejemplo n.º 17
0
class ScriptEditor (QWidget):
    display_name = 'Script Editor'

    def __init__(self, datfile):
        super().__init__()
        self.grid = QGridLayout(self)
        self.f = datfile

        self.dropdown = QComboBox(self)
        self.populate_dropdown()
        self.grid.addWidget(self.dropdown, 0, 0)

        self.location_display = QLineEdit(self)
        self.grid.addWidget(self.location_display, 0, 1)
        self.location_display.setReadOnly(True)

        self.event_list = self.EventList(self)
        self.event_list.follow_clicked.connect(self.open_location)
        self.grid.addWidget(self.event_list, 1, 0, 1, 2)

        self.toolbar = QToolBar(self)
        self.toolbar.setOrientation(Qt.Vertical)
        self.toolbar.addAction(self.event_list.move_up)
        self.toolbar.addAction(self.event_list.move_down)
        self.toolbar.addAction(self.event_list.new)
        self.toolbar.addAction(self.event_list.delete)
        self.grid.addWidget(self.toolbar, 1, 2)

        self.apply_button = QPushButton('Apply', self)
        self.apply_button.pressed.connect(self.apply)
        self.grid.addWidget(self.apply_button, 2, 0, 1, 2)

        self.dropdown.currentIndexChanged.connect(
                lambda index: self.location_display.setText(
                        '' if self.dropdown.currentData() is None
                        else hex(self.dropdown.currentData())
                        )
                )

        self.location_display.textChanged.connect(self.load_script_from)

        self.dropdown.setCurrentIndex(1)

    def populate_dropdown(self):
        self.dropdown.clear()
        for i, sa in self.f.iter_subactions():
            name = hex(i) + ': ' + self.f.subaction_short_name(i)
#            print(name)
            self.dropdown.addItem(name,
                                  self.f.pointer(sa.script_pointer)
                                  )
        for offset in self.f.find_subroutines():
            if self.dropdown.findData(offset) == -1:
                name = 'Script at ' + hex(offset)
                self.dropdown.addItem(name, offset)

    def open_location(self, offset):
        offset = self.f.pointer(offset)
        index = self.dropdown.findData(offset)
        if index != -1:
            self.dropdown.setCurrentIndex(index)

    def load_script_from(self, offset_hex_text):
        self.event_list.clear()
        if not offset_hex_text:
            return
        offset = int(offset_hex_text, base=16)
        self.event_list.start_offset = offset
        for ev, offset in script.iter_script(self.f.script_at(offset), offset):
            self.event_list.add_event(ev, offset)

    def apply(self):
        self.f.replace_script_at(self.event_list.start_offset,
                                 self.event_list.get_script())
        pos = self.dropdown.currentIndex()
        self.populate_dropdown()
        self.dropdown.setCurrentIndex(pos)

    class EventList (QListWidget):
        follow_clicked = pyqtSignal(int)
        event_role = Qt.UserRole
        offset_role = Qt.UserRole + 1
        NOP = script.FighterEvent.from_hex('0xCC000000')

        def __init__(self, parent=None):
            super().__init__(parent)
            self.start_offset = None  # will be set by parent
            self.itemDoubleClicked.connect(
                    lambda item: self.popup_event_editor(self.row(item))
                    )

            self.setSelectionMode(self.ContiguousSelection)

            style = self.style()
            self.move_up = QAction(style.standardIcon(QStyle.SP_ArrowUp), 'Move Up', self)
            self.move_up.setShortcut(QKeySequence(Qt.Key_Minus))
            self.move_up.triggered.connect(lambda: self.shift(-1))
            self.addAction(self.move_up)

            self.move_down = QAction(style.standardIcon(QStyle.SP_ArrowDown), 'Move Down', self)
            self.move_down.setShortcut(QKeySequence(Qt.Key_Plus))
            self.move_down.triggered.connect(lambda: self.shift(+1))
            self.addAction(self.move_down)

            copy = QAction(self)
            copy.setShortcut(QKeySequence.Copy)
            copy.triggered.connect(self.copy)
            self.addAction(copy)

            paste = QAction(self)
            paste.setShortcut(QKeySequence.Paste)
            paste.triggered.connect(self.paste)
            self.addAction(paste)

            self.delete = QAction(style.standardIcon(QStyle.SP_TrashIcon), 'Delete', self)
            self.delete.setShortcut(QKeySequence.Delete)
            self.delete.triggered.connect(self.delete_selected)
            self.addAction(self.delete)

            self.new = QAction(style.standardIcon(QStyle.SP_FileIcon), 'Insert Event', self)
            self.new.triggered.connect(lambda: self.insert_event(self.currentRow(), self.NOP.copy()))
            self.addAction(self.new)

        def delete_selected(self):
            selected = sorted(self.selectedIndexes())
            if selected:
                self.setCurrentIndex(selected[0])
            row = self.currentIndex().row()
            for i in range(len(selected)):
                ev = self.takeItem(row)
                del ev

        def copy(self):
            s = ''
            for item in self.selectedItems():
                event_text = hex_display(hex(item.data(self.event_role)),
                                   show_0x=False
                                   )
                if len(event_text) % 2:
                    event_text = '0' + event_text
                s += event_text
            app.clipboard().setText(s)

        def paste(self):
            cb = app.clipboard()
            formats = cb.mimeData().formats()
            try:
                fmt_010 = r'application/x-qt-windows-mime;value="010 Editor Binary Data"'
                if fmt_010 in formats:
                    data = cb.mimeData().data(fmt_010)
                    # [:-2] because 010 appends \x00\x00
                    scr = script.script_from_bytes(data[:-2])
                    for ev in scr:
                        self.insert_event(max(self.currentRow(), 0), ev)
                # any other binary formats go here
                elif cb.text():
                    scr = script.script_from_hex_str(cb.text())
                    for ev in scr:
                        self.insert_event(max(self.currentRow(), 0), ev)
                self.selectionModel().clearSelection()
            except EOFError:
                mbox = QMessageBox(self)
                mbox.setText('Error interpreting pasted event data')
                mbox.exec_()

        def contextMenuEvent(self, e):
            row = self.currentRow()
            if self.item(row):
                event = self.item(row).data(Qt.UserRole)
                menu = QMenu(self)
                edit_action = menu.addAction(
                        self.style().standardIcon(QStyle.SP_FileDialogDetailedView),
                        'Edit'
                        )
                edit_action.triggered.connect(
                        lambda: self.popup_event_editor(row))
                menu.addAction(self.new)
#                insert_action = menu.addAction(
#                        self.style().standardIcon(QStyle.SP_FileIcon),
#                        'Insert Event'
#                        )
#                insert_action.triggered.connect(
#                        lambda: self.insert_event(self.currentRow(), self.NOP.copy())
#                        )
                if event.pointers:
                    follow_action = menu.addAction(
                            self.style().standardIcon(QStyle.SP_ArrowForward),
                            'Follow'
                            )
                    follow_action.triggered.connect(lambda: self.follow(row))
                menu.exec_(e.globalPos())

        def insert_event(self, pos, event):
            if self.item(pos) is None:
                offset = self.start_offset
            else:
                offset = self.item(pos).data(self.offset_role)
            self.insertItem(pos, self.item_from_event(event,offset))
            self.update_offsets()

        def popup_event_editor(self, row):
            ev = self.item(row).data(self.event_role)
            offset = self.item(row).data(self.offset_role)
            event_editor = EventEditor(ev, self)
            event_editor.applied.connect(
                    lambda ev: self.replace_event(row, ev, offset))
            event_editor.exec_()

        def replace_event(self, row, event, offset):
            self.insertItem(row + 1, self.item_from_event(event, offset))
            old = self.takeItem(row)
            del old
            self.update_offsets()

        def follow(self, row):
            target = self.item(row).data(self.event_role)['target']
            self.follow_clicked.emit(target)

        def add_event(self, event, offset):
            self.addItem(self.item_from_event(event, offset))

        @staticmethod
        def event_text(event, offset):
            if compact_event_display:
                return event.compact_str(offset=offset)
            else:
                return event.__str__(offset=offset)

        def item_from_event(self, event, offset):
            name = self.event_text(event, offset)
            new = QListWidgetItem(name)
            new.setData(self.event_role, event)
            new.setData(self.offset_role, offset)
            return new

        def get_script(self):
            return [self.item(row).data(self.event_role)
                    for row in range(self.count())]

        def update_offsets(self):
            offset = self.start_offset
            for row in range(self.count()):
                item = self.item(row)
                ev = item.data(self.event_role)
                item.setData(self.offset_role, offset)
                item.setText(self.event_text(ev, offset))
                offset += ev.length

        def shift(self, shift):
            # shift: 1 = down, -1 = up
            selected = sorted(self.selectedIndexes())
            if selected:
                if shift > 0:
                    # down
                    current = selected[-1]
                else:
                    # up
                    current = selected[0]
                self.setCurrentIndex(current)
            else:
                current = self.currentIndex()
            row = self.currentIndex().row()
            if not 0 <= row + shift < self.count():
                shift = 0
            for i in range(len(selected)):
                self.insertItem(row + (1-i)*shift, self.takeItem(row - i*shift))
                self.update_offsets()
            self.setCurrentRow(row + shift)
            self.selectionModel().clear()
            self.setCurrentIndex(
                    current.sibling(current.row() + shift, current.column()))
            for index in selected:
                self.selectionModel().select(
                        index.sibling(index.row() + shift, index.column()),
                        self.selectionModel().Select
                        )
Ejemplo n.º 18
0
class Ui_MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        # self.initUI()
        self.init_ui()
        self.generateData()
        self.UI_style()

    def init_ui(self):
        self.setFixedSize(1200, 700)
        self.setWindowTitle('STalking')
        self.setWindowIcon(QIcon("icon/stlogo.ico"))
        self.main_widget = QtWidgets.QWidget()  # 创建窗口主部件
        self.main_widget.setObjectName('main_widget')
        self.main_layout = QtWidgets.QGridLayout()  # 创建主部件的网格布局
        self.main_widget.setLayout(self.main_layout)  # 设置窗口主部件布局为网格布局

        self.left_widget = QtWidgets.QWidget()  # 创建左侧部件 左侧为功能按钮
        self.left_widget.setObjectName('left_widget')
        self.left_layout = QtWidgets.QGridLayout()  # 创建左侧部件的网格布局层
        self.left_widget.setLayout(self.left_layout)  # 设置左侧部件布局为网格

        self.center_Splitter = QSplitter(Qt.Horizontal)
        self.center_Splitter.setObjectName('center_Splitter')
        self.center_layout = QtWidgets.QGridLayout()
        self.center_Splitter.setLayout(self.center_layout)  # 设置右侧部件布局为网格

        self.main_layout.addWidget(self.left_widget, 0, 0, 16,
                                   3)  # 左侧部件在第0行第0列,占8行3列
        # self.main_layout.addWidget(self.center_QWidget, 0, 3, 16, 17)  # 左侧部件在第0行第3列,占8行3列
        self.main_layout.addWidget(self.center_Splitter, 0, 3, 16,
                                   17)  # 左侧部件在第0行第3列,占8行3列
        self.setCentralWidget(self.main_widget)  # 设置窗口主部件

        self.icon_button = QtWidgets.QToolButton()
        self.icon_button.setIcon(QtGui.QIcon('icon/stlogo.ico'))  # 设置按钮图标
        self.icon_button.setIconSize(QtCore.QSize(150, 100))  # 设置图标大小

        self.left_label_1 = QtWidgets.QPushButton("模型选择")
        self.left_label_1.setObjectName('left_label')
        self.left_label_2 = QtWidgets.QPushButton("保存与设置")
        self.left_label_2.setObjectName('left_label')
        self.left_label_3 = QtWidgets.QPushButton("其他")
        self.left_label_3.setObjectName('left_label')

        self.left_button_1 = QtWidgets.QPushButton(
            qtawesome.icon('fa.database', color='gray'), "选择GMM")
        self.left_button_1.setObjectName('left_button')
        self.left_button_2 = QtWidgets.QPushButton(
            qtawesome.icon('fa.file', color='gray'), "选择UBM")
        self.left_button_2.setObjectName('left_button')
        self.left_button_3 = QtWidgets.QPushButton(
            qtawesome.icon('fa.plus-circle', color='gray'), "选择视频")
        self.left_button_3.setObjectName('left_button')
        self.left_button_4 = QtWidgets.QPushButton(
            qtawesome.icon('fa.save', color='gray'), "保存模型")
        self.left_button_4.setObjectName('left_button')
        self.left_button_5 = QtWidgets.QPushButton(
            qtawesome.icon('fa.file', color='gray'), "模型路径")
        self.left_button_5.setObjectName('left_button')
        self.left_button_6 = QtWidgets.QPushButton(
            qtawesome.icon('fa.folder-open', color='gray'), "文件路径")
        self.left_button_6.setObjectName('left_button')
        self.left_button_7 = QtWidgets.QPushButton(
            qtawesome.icon('fa.comment', color='gray'), "使用向导")
        self.left_button_7.setObjectName('left_button')
        self.left_button_8 = QtWidgets.QPushButton(
            qtawesome.icon('fa.star', color='gray'), "版权说明")
        self.left_button_8.setObjectName('left_button')
        self.left_button_9 = QtWidgets.QPushButton(
            qtawesome.icon('fa.question', color='gray'), "关于我们")
        self.left_button_9.setObjectName('left_button')
        self.left_xxx = QtWidgets.QPushButton(" ")

        self.left_layout.addWidget(self.icon_button, 0, 0.5, 1, 3)
        self.left_layout.addWidget(self.left_label_1, 1, 0, 1, 3)
        self.left_layout.addWidget(self.left_button_1, 2, 0, 1, 3)
        self.left_layout.addWidget(self.left_button_2, 3, 0, 1, 3)
        self.left_layout.addWidget(self.left_button_3, 4, 0, 1, 3)
        self.left_layout.addWidget(self.left_label_2, 5, 0, 1, 3)
        self.left_layout.addWidget(self.left_button_4, 6, 0, 1, 3)
        self.left_layout.addWidget(self.left_button_5, 7, 0, 1, 3)
        self.left_layout.addWidget(self.left_button_6, 8, 0, 1, 3)
        self.left_layout.addWidget(self.left_label_3, 9, 0, 1, 3)
        self.left_layout.addWidget(self.left_button_7, 10, 0, 1, 3)
        self.left_layout.addWidget(self.left_button_8, 11, 0, 1, 3)
        self.left_layout.addWidget(self.left_button_9, 12, 0, 1, 3)

        self.model_list_widget = QtWidgets.QWidget()
        self.model_list_widget.setObjectName('model_widget')
        self.model_list_layout = QtWidgets.QGridLayout()  # 创建左侧部件的网格布局层
        self.model_list_widget.setLayout(self.model_list_layout)  # 设置左侧部件布局为网格

        self.model_list_label = QtWidgets.QLabel("模型列表")
        self.model_list_label.setObjectName('my_lable')

        self.model_view_list = QListWidget()  # 文件列表
        self.model_view_list.setObjectName('my_list')
        # self.model_view_list.setFixedWidth(200)
        self.right_Splitter = QSplitter(Qt.Vertical)
        self.right_Splitter.setObjectName('right_Splitter')

        self.model_list_layout.addWidget(self.model_list_label, 0, 0, 1, 1)
        self.model_list_layout.addWidget(self.model_view_list, 1, 0, 9, 1)

        self.center_Splitter.addWidget(self.model_list_widget)
        self.center_Splitter.addWidget(self.right_Splitter)
        self.center_Splitter.setStretchFactor(0, 2)
        self.center_Splitter.setStretchFactor(1, 8)

        self.result_label = QtWidgets.QLabel("数据分析")
        self.result_label.setFixedHeight(80)
        self.result_label.setObjectName('my_lable')

        self.right_html_page_TabWidget = QtWidgets.QTabWidget()
        self.right_html_page_TabWidget.setObjectName(
            'right_html_page_TabWidget')
        self.right_log_widget = QtWidgets.QWidget()  # log 框 = button + log
        self.right_log_widget.setObjectName('right_log_widget')
        self.right_log_layout = QtWidgets.QGridLayout()
        self.right_log_widget.setLayout(self.right_log_layout)  # 设置右侧部件布局为网格

        self.right_Splitter.addWidget(self.result_label)
        self.right_Splitter.addWidget(self.right_html_page_TabWidget)
        self.right_Splitter.addWidget(self.right_log_widget)
        self.right_Splitter.setStretchFactor(0, 1)
        self.right_Splitter.setStretchFactor(1, 9)
        self.right_Splitter.setStretchFactor(2, 1)

        self.right_log_toolbar = QToolBar()
        self.right_log_toolbar.setObjectName('right_log_toolbar')
        self.right_log_toolbar.setOrientation(Qt.Vertical)
        # self.right_button_layout.addWidget(self.toolbarGmm)
        delete_action = QAction(QIcon('icon/delete-gray.png'), '清空日志', self)
        self.right_log_toolbar.addAction(delete_action)
        export_action = QAction(QIcon('icon/save_m.png'), '导出日志', self)
        self.right_log_toolbar.addAction(export_action)
        # self.right_log_layout.setSpacing(0)
        self.right_log_contend = QListWidget()
        # self.right_log_contend.setFixedHeight(100)
        self.right_log_contend.setObjectName('my_list')
        self.right_log_layout.addWidget(self.right_log_toolbar, 0, 0, 1, 3)
        self.right_log_layout.addWidget(self.right_log_contend, 0, 1, 1, 18)

    # 定义 css
    def UI_style(self):
        self.main_widget.setStyleSheet('''
            QWidget#main_widget{
                background:#EBEBEB;
                border-top:1px solid #EBEBEB;
                border-bottom:1px solid #EBEBEB;
                border-left:1px solid #EBEBEB;
                border-top-left-radius:10px;
                border-bottom-left-radius:10px;
            }

        ''')
        self.result_label.setStyleSheet('''
            QLabel{
                border:none;
                background:#EBEBEB;
                font-size:20px;
                font-weight:900;
                font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
            }
        ''')
        self.model_list_label.setStyleSheet('''
                    QLabel{
                        border:none;
                        background:#EBEBEB;
                        font-size:20px;
                        font-weight:900;
                        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
                    }

                ''')
        self.icon_button.setStyleSheet('''
            QToolButton{
                border:none;
                background:#EBEBEB;
            }
        ''')
        self.main_widget.setStyleSheet('''
            QWidget#center_QWidget{
                color:#232C51;
                background:#EBEBEB;
                border-top:1px solid #EBEBEB;
                border-bottom:1px solid #EBEBEB;
                border-right:1px solid #EBEBEB;
                border-top-right-radius:10px;
                border-bottom-right-radius:10px;
            }
            QWidget#left_widget{
                        background:#EBEBEB;
                        border-top:1px solid #EBEBEB;
                        border-bottom:1px solid #EBEBEB;
                        border-left:1px solid #EBEBEB;
                        border-top-left-radius:10px;
                        border-bottom-left-radius:10px;
                    }
        ''')
        self.model_list_widget.setStyleSheet('''
            QListWidget#my_list{
                background:light white;
                border:none;
                width:300px;
                border-radius:10px;
                padding:2px 4px;
            }
        ''')
        self.left_widget.setStyleSheet('''
            QPushButton{border:none;color:gray;font-size:18px;font-weight:700;}
            QPushButton#left_label{
                    border:none;
                    border-bottom:1px solid dark gray;
                    font-size:20px;
                    font-weight:900;
                    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
            }
            QPushButton#left_button:hover{border-left:4px solid red;font-weight:700;}
        ''')
        self.center_Splitter.setStyleSheet('''
            QSplitter#center_Splitter{
                background:#EBEBEB;
            }
            QSplitter#right_Splitter{
                background:#EBEBEB;
            }
            QTabWidget#right_html_page_TabWidget{
                width:300px;
                border-radius:10px;
                padding:2px 4px;
                border:none;
                font-size:16px;
                font-weight:700;
                font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
            }
            }
            QLabel#my_lable{
                background-color:#EBEBEB;
                border:none;
                font-size:20px;
                font-weight:bold;
                font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
            }
             QToolBar#right_log_toolbar{
                border:none;
                background-color: #EBEBEB;
            }
            QListWidget#my_list{
                background:light white;
                border:none;
                width:300px;
                border-radius:10px;
                padding:2px 4px;
            }

        ''')
        self.model_list_label.setAlignment(Qt.AlignCenter)
        self.result_label.setAlignment(Qt.AlignCenter)
        self.model_list_label.setStyleSheet('''
            QLabel{
                background-color:light gray;
                border:none;
                font-size:20px;
                font-weight:bold;
                font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
            }
        ''')

        self.right_log_widget.setStyleSheet('''
            QListWidget#right_log_widget{
                width:300px;
                border-radius:10px;
                padding:2px 4px;
            }
            QToolBar#right_log_toolbar{
                border:none;
                background-color: light gray;
            }
            QListWidget#right_log_contend{
                background:#EBEBEB;
                border:none;
                border:1px solid gray;
                width:300px;
                border-radius:10px;
                padding:2px 4px;
            }
        ''')

        # self.setWindowOpacity(1)  # 设置窗口透明度
        # self.setAttribute(QtCore.Qt.WA_TranslucentBackground)  # 设置窗口背景透明
        # self.setWindowFlag(QtCore.Qt.FramelessWindowHint)  # 隐藏边框
        # self.main_layout.setSpacing(0)

    def generateData(self):
        for group in range(1, 100):
            self.model_view_list.addItem("model_{0}".format(group))
        for group in range(1, 100):
            self.right_log_contend.addItem(
                (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                 " : operation_{0}").format(group))
        for group in range(1, 4):
            self.tabItem = QTextBrowser()
            self.right_html_page_TabWidget.addTab(self.tabItem,
                                                  "page_{0}".format(group))
            self.tabItem.setHtml("""<table bgcolor=yellow>
        <tr><td>Groups:</td><td>comp.lang.python.announce</td></tr>
        <tr><td>From:</td><td>"Fuzzyman" &lt;[email protected]&gt;</td></tr>
        <tr><td>Subject:</td><td><b>[ANN] Movable Python 2.0.0 Final
        Available</b></td></tr>
        </table>

        <h3>Movable Python 2.0.0 Final</h3>
        <p>
        <a href="http://www.voidspace.org.uk/python/movpy/">
        http://www.voidspace.org.uk/python/movpy/</a>
        is now available.

        <p>
        The new binaries are available for download from the groups page :

        <p>Movable Python Groups Page
        <a href="http://voidspace.tradebit.com/groups.php">
        http://voidspace.tradebit.com/groups.php</a>
        <p>
        Binaries are uploaded for Python 2.2.3, 2.3.5, 2.4.4, 2.5 and the
        MegaPack
        <a href="http://www.voidspace.org.uk/python/movpy/megapack.html">
        http://www.voidspace.org.uk/python/movpy/megapack.html</a>.
        <p>
        There is also a fresh version of the free demo, based on Python 2.3.5:

        <p>Movable Python Trial Version
        <a href="http://voidspace.tradebit.com/files.php/7007">
        http://voidspace.tradebit.com/files.php/7007</a>

        <h3>What is Movable Python</h3>

        <p>
        <b><i>Movable Python</i></b> is a distribution of Python, for Windows,
        that can run without being installed. It means you can carry a full
        development environment round on a USB stick.

        <p>
        It is also useful for testing programs with a 'clean Python install',
        and testing programs with multiple versions of Python.

        <p>
        The GUI program launcher makes it a useful programmers tool, including
        features like :

        <ul>
        <li>Log the output of all Python scripts run
        <li>Enable Psyco for all scripts
        <li>Quick Launch buttons for commonly used programs
        <li>Configure multiple interpreters for use from a single interface
        </ul>
        <p>
        It comes with the Pythonwin IDE and works fine with other IDEs like
        SPE
        <a href="http://developer.berlios.de/projects/python/">
        http://developer.berlios.de/projects/python/</a>.
        <p>
        Plus many other features and bundled libraries.""")
Ejemplo n.º 19
0
    def __init__(self, parent=None, loglevel=logging.INFO):
        """**Constructor**"""
        super().__init__(loglevel=loglevel)
        QMainWindow.__init__(self)
        Ui_MainWindow.__init__(self)
        CmdBase.mode = CmdMode.GUI  #set GUI mode
        self.setupUi(self)

        if CmdBase.calcmode == CalcMode.singlethread:
            self.setWindowTitle('RepTate ' + self.version + ' ' + self.date +
                                ' - SINGLE THREAD!!')
        else:
            self.setWindowTitle('RepTate ' + self.version + ' ' + self.date)

        # Add Apps
        self.toolBarApps.addAction(self.actionMWD)
        tbut = QToolButton()
        tbut.setPopupMode(QToolButton.MenuButtonPopup)
        tbut.setDefaultAction(self.actionTTS)
        menu = QMenu()
        menu.addAction(self.actionTTSFactors)
        tbut.setMenu(menu)
        self.toolBarApps.addWidget(tbut)
        self.toolBarApps.addAction(self.actionLVE)
        self.toolBarApps.addAction(self.actionNLVE)
        self.toolBarApps.addAction(self.actionCrystal)
        self.toolBarApps.addAction(self.actionGt)
        self.toolBarApps.addAction(self.actionCreep)
        self.toolBarApps.addAction(self.actionSANS)
        self.toolBarApps.addAction(self.actionReact)
        self.toolBarApps.addAction(self.actionDielectric)
        # self.toolBarApps.addAction(self.actionDynamicStructureFactor)
        self.toolBarApps.addAction(self.actionLAOS)

        #help button
        icon = QIcon(':/Icon8/Images/new_icons/icons8-user-manual.png')
        #self.show_reptate_help = QAction(icon, 'RepTate Manual', self)
        #self.show_app_help = QAction(icon, 'Application Manual', self)
        #self.show_th_help = QAction(icon, 'Theory Manual', self)
        tbut = QToolButton()
        tbut.setPopupMode(QToolButton.MenuButtonPopup)
        tbut.setDefaultAction(self.actionShow_reptate_help)
        menu = QMenu()
        menu.addAction(self.actionShow_app_help)
        menu.addAction(self.actionShow_th_help)
        menu.addAction(self.actionShow_offline_help)
        tbut.setMenu(menu)
        #self.toolBarHelpAbout.insertWidget(self.actionAbout_Qt, tbut)
        self.toolBarHelpAbout.addWidget(tbut)
        self.toolBarHelpAbout.addSeparator()

        self.toolBarHelpAbout.addAction(self.actionShow_Logger)

        tbut = QToolButton()
        tbut.setPopupMode(QToolButton.MenuButtonPopup)
        tbut.setDefaultAction(self.actionAbout)
        menu = QMenu()
        menu.addAction(self.actionAbout_Qt)
        menu.addAction(self.actionAboutMatplotlib)
        menu.addAction(self.actionAboutNumpy)
        menu.addAction(self.actionAboutScipy)
        menu.addSeparator()
        menu.addAction(self.actionCite_RepTate)
        menu.addAction(self.actionCheckRepTateVersion)
        tbut.setMenu(menu)
        self.toolBarHelpAbout.addWidget(tbut)

        self.toolBarHelpAbout.insertSeparator(self.actionAbout_Qt)
        #self.toolBar.insertSeparator(self.actionQuit)
        self.toolBarProject.setContextMenuPolicy(Qt.PreventContextMenu)
        self.toolBarApps.setContextMenuPolicy(Qt.PreventContextMenu)
        self.toolBarHelpAbout.setContextMenuPolicy(Qt.PreventContextMenu)

        # # ApplicationXY button
        # #choose the button icon
        # icon = QIcon(':/Icon8/Images/new_icons/XY.png')
        # tool_tip = 'XY'  # text that appear on hover
        # self.actionXY = QAction(icon, tool_tip, self)
        # #insert the new button before the "MWD" button
        # self.toolBarApps.insertAction(self.actionMWD, self.actionXY)
        # #connect button
        # self.actionXY.triggered.connect(lambda: self.handle_new_app('XY'))

        # App tabs behaviour
        self.ApplicationtabWidget.setMovable(True)
        self.ApplicationtabWidget.setTabsClosable(True)
        self.ApplicationtabWidget.setUsesScrollButtons(True)

        # Connect actions
        self.actionOpenProject.triggered.connect(self.launch_open_dialog)
        self.actionSaveProject.triggered.connect(self.launch_save_dialog)

        # Generate action buttons from dict of available applications
        self.actionMWD.triggered.connect(lambda: self.handle_new_app('MWD'))
        self.actionTTS.triggered.connect(lambda: self.handle_new_app('TTS'))
        self.actionTTSFactors.triggered.connect(
            lambda: self.handle_new_app('TTSF'))
        self.actionLVE.triggered.connect(lambda: self.handle_new_app('LVE'))
        self.actionNLVE.triggered.connect(lambda: self.handle_new_app('NLVE'))
        self.actionCrystal.triggered.connect(
            lambda: self.handle_new_app('Crystal'))
        self.actionGt.triggered.connect(lambda: self.handle_new_app('Gt'))
        self.actionCreep.triggered.connect(
            lambda: self.handle_new_app('Creep'))
        self.actionSANS.triggered.connect(lambda: self.handle_new_app('SANS'))
        self.actionReact.triggered.connect(
            lambda: self.handle_new_app('React'))
        self.actionDielectric.triggered.connect(
            lambda: self.handle_new_app('Dielectric'))
        self.actionLAOS.triggered.connect(lambda: self.handle_new_app('LAOS'))
        # self.actionLAOS.triggered.connect(lambda: self.handle_app_coming_soon('LAOS'))
        # self.actionDynamicStructureFactor.triggered.connect(lambda: self.handle_app_coming_soon('DynamicStructureFactor'))

        self.ApplicationtabWidget.tabCloseRequested.connect(self.close_app_tab)
        self.ApplicationtabWidget.currentChanged.connect(self.tab_changed)

        self.actionAbout_Qt.triggered.connect(QApplication.aboutQt)
        self.actionAbout.triggered.connect(self.show_about)

        connection_id = self.ApplicationtabWidget.tabBarDoubleClicked.connect(
            self.handle_doubleClickTab)
        # help buttons
        self.actionShow_reptate_help.triggered.connect(
            self.handle_show_reptate_help)
        self.actionShow_app_help.triggered.connect(self.handle_show_app_help)
        self.actionShow_th_help.triggered.connect(self.handle_show_th_help)
        self.actionShow_offline_help.triggered.connect(
            self.handle_actionShow_offline_help)

        # additional about buttons
        self.actionAboutMatplotlib.triggered.connect(
            self.handle_about_matplotlib)
        self.actionAboutNumpy.triggered.connect(self.handle_about_numpy)
        self.actionAboutScipy.triggered.connect(self.handle_about_scipy)
        self.actionCite_RepTate.triggered.connect(self.handle_cite_RepTate)
        self.actionCheckRepTateVersion.triggered.connect(
            self.handle_check_RepTate_version)

        connection_id = self.LoggerdockWidget.visibilityChanged.connect(
            self.handle_loggerVisibilityChanged)
        connection_id = self.actionShow_Logger.triggered.connect(
            self.showLogger)

        tb = QToolBar()
        tb.setIconSize(QSize(24, 24))
        tb.setOrientation(Qt.Vertical)

        self.tbutlog = QToolButton()
        self.tbutlog.setPopupMode(QToolButton.MenuButtonPopup)
        menu = QMenu()
        menu.addAction(self.actionLogNotSet)
        menu.addAction(self.actionLogDebug)
        menu.addAction(self.actionLogInfo)
        menu.addAction(self.actionLogWarning)
        menu.addAction(self.actionLogError)
        menu.addAction(self.actionLogCritical)
        if loglevel == logging.NOTSET:
            self.tbutlog.setDefaultAction(self.actionLogNotSet)
        elif loglevel == logging.DEBUG:
            self.tbutlog.setDefaultAction(self.actionLogDebug)
        elif loglevel == logging.INFO:
            self.tbutlog.setDefaultAction(self.actionLogInfo)
        elif loglevel == logging.WARNING:
            self.tbutlog.setDefaultAction(self.actionLogWarning)
        elif loglevel == logging.ERROR:
            self.tbutlog.setDefaultAction(self.actionLogError)
        elif loglevel == logging.CRITICAL:
            self.tbutlog.setDefaultAction(self.actionLogCritical)
        self.tbutlog.setMenu(menu)
        tb.addWidget(self.tbutlog)

        tb.addAction(self.actionCopyLogText)
        self.LoggerdochorizontalLayout.addWidget(tb)

        self.logTextBox = QTextEditLogger(self)
        formatter = logging.Formatter(
            '<font color=blue>%(asctime)s</font> <b>%(name)s <font color=red>%(levelname)s</font></b>: %(message)s',
            "%Y%m%d %H%M%S")
        self.logTextBox.setFormatter(formatter)
        logging.getLogger('RepTate').addHandler(self.logTextBox)
        logging.getLogger('RepTate').setLevel(loglevel)
        import matplotlib
        matplotlib._log.addHandler(self.logTextBox)
        self.logTextBox.setLevel(loglevel)
        self.LoggerdochorizontalLayout.addWidget(self.logTextBox.widget)

        connection_id = self.actionLogNotSet.triggered.connect(self.logNotSet)
        connection_id = self.actionLogDebug.triggered.connect(self.logDebug)
        connection_id = self.actionLogInfo.triggered.connect(self.logInfo)
        connection_id = self.actionLogWarning.triggered.connect(
            self.logWarning)
        connection_id = self.actionLogError.triggered.connect(self.logError)
        connection_id = self.actionLogCritical.triggered.connect(
            self.logCritical)
        connection_id = self.actionCopyLogText.triggered.connect(
            self.copyLogText)

        #self.add_save_load_buttons()
        self.REPTATE_PROJ_JSON = 'reptate_project.json'  # json filename inside zip
        self.load_path = None

        # CONSOLE WINDOW (need to integrate it with cmd commands)
        #self.text_edit = Console(self)
        #this is how you pass in locals to the interpreter
        #self.text_edit.initInterpreter(locals())
        #self.verticalLayout.addWidget(self.text_edit)

        # Hide Logger Window
        self.LoggerdockWidget.hide()
class Ui_Dialog(QMainWindow):
    def setupUi(self, Dialog):
        self.calibrate = 0
        self.IMU_position = 0
        width = Dialog.frameGeometry().width()
        height = Dialog.frameGeometry().height()
        Dialog.setStyleSheet("background-color: rgb(36, 36, 36);")

        widget_width = width - 200
        widget_width2 = width + 200
        widget_height = height - 190
        widget_height2 = height + 155

        self.toolbarHor = QToolBar(Dialog)
        self.toolbarHor.setIconSize(QSize(40, 40))
        self.toolbarHor.setOrientation(QtCore.Qt.Horizontal)
        self.toolbarHor.setStyleSheet("QToolBar{spacing:200px;}")
        self.toolbarHor.setStyleSheet("QToolButton{padding-top:4px;}")
        self.toolbarHor.addSeparator()
        self.toolbarHor.addSeparator()
        self.toolbarHor.addSeparator()
        self.toolbarHor.addSeparator()
        self.toolbarHor.addSeparator()
        self.toolbarHor.addSeparator()
        self.toolbarHor.addSeparator()
        self.toolbarHor.addSeparator()
        self.toolbarHor.addSeparator()
        self.toolbarHor.addSeparator()

        Calibrate_action = QAction(QIcon('images/calibrate.png'), 'calibrate',
                                   self)
        Calibrate_action.triggered.connect(self.calibrating)
        self.toolbarHor.addAction(Calibrate_action)

        closeDevice_action = QAction(QIcon('images/Disconnect.png'),
                                     'Disconnect Devices', self)
        #        closecameras_action.triggered.connect(self.close_Cameras)
        self.toolbarHor.addAction(closeDevice_action)

        self.toolbar = QToolBar(Dialog)
        self.toolbar.setIconSize(QSize(40, 40))
        self.toolbar.setOrientation(QtCore.Qt.Vertical)

        connect_action = QAction(QIcon('images/connect.png'),
                                 'Connect Devices', self)
        connect_action.triggered.connect(self.Connect_Device)
        self.toolbar.addAction(connect_action)

        tool_action = QAction(QIcon('images/tools.png'), 'Settings', self)
        self.toolbar.addAction(tool_action)
        #        tool_action.triggered.connect(self.properties_window_A)

        exit_action = QAction(QIcon('images/exit.png'), 'exit', self)
        self.toolbar.addAction(exit_action)
        exit_action.triggered.connect(self.window_close)

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

        self.threeD_view()

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Markerless Mocap"))

    def threeD_view(
        self
    ):  #-----------------------------------------------------# 3D gui graphic
        self.width = Dialog.frameGeometry().width()
        self.height = Dialog.frameGeometry().height()

        self.widget_width2 = self.width + 200
        self.widget_height2 = self.height + 155

        self.w = gl.GLViewWidget(Dialog)
        self.w.opts['distance'] = 40
        self.w.setGeometry(500, 55, self.widget_width2, self.widget_height2)
        self.w.setBackgroundColor('k')

        gz = gl.GLGridItem()
        gz.translate(0, 0, 0)
        self.w.addItem(gz)

        self.ax = gl.GLAxisItem()
        self.ax.translate(0, 0, 0.5)
        self.ax.rotate(180, 0, 1, 0)
        self.ax.setSize(1, 1, 1)
        self.ax.show()
        self.w.addItem(self.ax)

    def Connect_Device(self):
        ports = list_ports.comports()
        PORT = "COM6"
        try:
            self.ard = serial.Serial(PORT, 115200, timeout=.1)

            verts = np.array([
                [1, 0, 0],  #0
                [0, 0, 0],  #1
                [0, 1, 0],  #2
                [0, 0, 1],  #3
                [1, 1, 0],  #4
                [1, 1, 1],  #5
                [0, 1, 1],  #6
                [1, 0, 1]
            ])  #7
            faces = np.array([[1, 0, 7], [1, 3, 7], [1, 2, 4], [1, 0, 4],
                              [1, 2, 6], [1, 3, 6], [0, 4, 5], [0, 7, 5],
                              [2, 4, 5], [2, 6, 5], [3, 6, 5], [3, 7, 5]])
            colors = np.array([[1, 0, 0, 1] for i in range(12)])

            self.m1 = gl.GLMeshItem(vertexes=verts,
                                    faces=faces,
                                    faceColors=colors,
                                    smooth=False)
            self.m1.translate(0, 0, 0)
            self.m1.setGLOptions('additive')
            self.w.addItem(self.m1)

            self.dataloopO = 0
            self.dataloopM = 0
            self.IMU1 = Thread(target=self.IMU_stream)
            self.IMU1.setDaemon(True)
            self.IMU1.start()

        except:
            pass

    def IMU_stream(self):
        while True:
            if (self.ard.isOpen() == True):
                try:
                    self.IMU_data = self.ard.readline().decode().strip('\r\n')
                    if "Orientation" in self.IMU_data:  #sensor orientation degrees
                        Data_Euler = self.IMU_data.split(" ")
                        if self.dataloopO == 0:
                            self.IMU1_Euler_X_temp1 = float(Data_Euler[1])
                            self.IMU1_Euler_Y_temp1 = float(Data_Euler[2])
                            self.IMU1_Euler_Z_temp1 = float(Data_Euler[3])
                            self.dataloopO = self.dataloopO + 1
                        else:
                            self.dataloopO = 0
                            self.IMU1_Euler_X_temp2 = float(Data_Euler[1])
                            self.IMU1_Euler_X_temp3 = math.floor(
                                self.IMU1_Euler_X_temp2) - math.floor(
                                    self.IMU1_Euler_X_temp1)
                            IMU1_Euler_X_res = self.IMU1_Euler_X_temp3

                            if IMU1_Euler_X_res == 180:
                                IMU1_Euler_X_res = IMU1_Euler_X_res
                            elif IMU1_Euler_X_res < 180:
                                IMU1_Euler_X_res = self.IMU1_Euler_X_temp3
                            elif self.IMU1_Euler_X_temp2 > self.IMU1_Euler_X_temp1:
                                IMU1_Euler_X_res = IMU1_Euler_X_res - 360
                            else:
                                IMU1_Euler_X_res = 360 - IMU1_Euler_X_res

                            self.IMU1_Euler_Y_temp2 = float(Data_Euler[2])
                            self.IMU1_Euler_Y_temp3 = self.IMU1_Euler_Y_temp2 - self.IMU1_Euler_Y_temp1
                            IMU1_Euler_Y_res = self.IMU1_Euler_Y_temp3

                            if IMU1_Euler_Y_res == 180:
                                IMU1_Euler_Y_res = IMU1_Euler_Y_res
                            elif IMU1_Euler_Y_res < 180:
                                self.IMU1_Euler_Y_temp3 = self.IMU1_Euler_Y_temp3
                            elif self.IMU1_Euler_Y_temp2 > self.IMU1_Euler_Y_temp1:
                                IMU1_Euler_Y_res = IMU1_Euler_Y_res - 360
                            else:
                                IMU1_Euler_Y_res = 360 - IMU1_Euler_Y_res

                            self.IMU1_Euler_Z_temp2 = float(Data_Euler[3])
                            self.IMU1_Euler_Z_temp3 = self.IMU1_Euler_Z_temp2 - self.IMU1_Euler_Z_temp1
                            IMU1_Euler_Z_res = self.IMU1_Euler_Z_temp3

                            if IMU1_Euler_Z_res == 180:
                                IMU1_Euler_Z_res = IMU1_Euler_Z_res
                            elif IMU1_Euler_Z_res < 180:
                                self.IMU1_Euler_Z_temp3 = self.IMU1_Euler_Z_temp3
                            elif self.IMU1_Euler_Z_temp2 > self.IMU1_Euler_Z_temp1:
                                IMU1_Euler_Z_res = IMU1_Euler_Z_res - 360
                            else:
                                IMU1_Euler_Z_res = 360 - IMU1_Euler_Z_res

                            IMU1_Euler_X_res = IMU1_Euler_X_res * 2
                            IMU1_Euler_Y_res = IMU1_Euler_Y_res * 2
                            IMU1_Euler_Z_res = IMU1_Euler_Z_res * 2

                            self.m1.rotate(
                                IMU1_Euler_X_res, 1, 0, 0, local=False
                            )  ###curenntly still flipping aroundS
                            self.m1.rotate(IMU1_Euler_Y_res,
                                           0,
                                           1,
                                           0,
                                           local=False)
                            self.m1.rotate(IMU1_Euler_Z_res,
                                           0,
                                           0,
                                           1,
                                           local=False)

                    if "Speed" in self.IMU_data:
                        Data_Speed = self.IMU_data.split(" ")
                        self.IMU1_Speed_X = float(Data_Speed[1])
                        self.IMU1_Speed_Y = float(Data_Speed[2])
                        self.IMU1_Speed_Z = float(Data_Speed[3])

                    if "Movement" in self.IMU_data:
                        Data_Movement = self.IMU_data.split(" ")
                        if self.dataloopM == 0:
                            self.IMU1_Movement_X_temp1 = float(
                                Data_Movement[1])
                            self.IMU1_Movement_Y_temp1 = float(
                                Data_Movement[2])
                            self.dataloopM = self.dataloopM + 1
                        else:
                            self.dataloopM = 0
                            self.IMU1_Movement_X_temp2 = float(
                                Data_Movement[1])
                            self.IMU1_Movement_Y_temp2 = float(
                                Data_Movement[2])
                            self.IMU1_Movement_X_res = math.floor(
                                self.IMU1_Movement_X_temp2) - math.floor(
                                    self.IMU1_Movement_X_temp1)
                            self.IMU1_Movement_Y_res = math.floor(
                                self.IMU1_Movement_Y_temp2) - math.floor(
                                    self.IMU1_Movement_Y_temp1)
                            self.m1.translate(self.IMU1_Movement_X_res,
                                              self.IMU1_Movement_Y_res, 0)

                    if "Acceleration" in self.IMU_data:  # m/s^2
                        Data_Acceleration = self.IMU_data.split(" ")
                        self.IMU1_Acceleration_X = float(Data_Acceleration[1])
                        self.IMU1_Acceleration_Y = float(Data_Acceleration[2])
                        self.IMU1_Acceleration_Z = float(Data_Acceleration[3])

                    if "Magnatometer" in self.IMU_data:  # uT
                        Data_Magnatometer = self.IMU_data.split(" ")
                        self.IMU1_Magnatometer_X = float(Data_Magnatometer[1])
                        self.IMU1_Magnatometer_Y = float(Data_Magnatometer[2])
                        self.IMU1_Magnatometer_Z = float(Data_Magnatometer[3])

                    if "Gyroscope" in self.IMU_data:
                        Data_Gyroscope = self.IMU_data.split(" ")  # rad/s
                        self.IMU1_Gyroscope_X = float(Data_Gyroscope[1])
                        self.IMU1_Gyroscope_Y = float(Data_Gyroscope[2])
                        self.IMU1_Gyroscope_Z = float(Data_Gyroscope[3])

                    if "LinearAcceleration" in self.IMU_data:  # m/s^2
                        Data_LinearAcceleration = self.IMU_data.split(" ")
                        self.IMU1_LinearAcceleration_X = float(
                            Data_LinearAcceleration[1])
                        self.IMU1_LinearAcceleration_Y = float(
                            Data_LinearAcceleration[2])
                        self.IMU1_LinearAcceleration_Z = float(
                            Data_LinearAcceleration[3])

                    if "Gravity" in self.IMU_data:  # m/s^2
                        Data_Gravity = self.IMU_data.split(" ")
                        self.IMU1_Gravity_X = float(Data_Gravity[1])
                        self.IMU1_Gravity_Y = float(Data_Gravity[2])
                        self.IMU1_Gravity_Z = float(Data_Gravity[3])

                    if "Calibration:" in self.IMU_data:
                        Data_Calibration = self.IMU_data.split(" ")
                        self.IMU1_Calibration_X = float(Data_Calibration[1])
                        self.IMU1_Calibration_Y = float(Data_Calibration[2])
                        self.IMU1_Calibration_Z = float(Data_Calibration[3])

                except:
                    pass

            else:
                break

    def calibrating(self):
        if (self.ard.isOpen() == True):
            try:
                for i in range(2):
                    self.IMU_data_calibrate = self.IMU_data
                    if "Orientation:" in self.IMU_data_calibrate:
                        Data_calibO = self.IMU_data_calibrate.split(" ")
                        self.IMU1_calib_oX = float(Data_calibO[1])
                        self.IMU1_calib_oY = float(Data_calibO[2])
                        self.IMU1_calib_oZ = float(Data_calibO[3])
                        self.calibrate = 1
            except:
                pass

    def window_close(self):
        try:
            self.ard.close()
        except:
            pass
        Dialog.close()
Ejemplo n.º 21
0
class Mylabs(QMainWindow):
    """
    -----------------------------------------------------------------
    Création de l'interface graphique et de ces fonctions d'analyses.
    -----------------------------------------------------------------
    """
    def __init__(self):
        # Initialisation de la fenêtre
        super().__init__()
        self.fichiers = list()
        self.initui()
        self.show()

    def initui(self):
        # Paramétrage des données principale de la fenêtre
        self.setWindowTitle("Mylabs")
        self.setGeometry(8, 30, 800, 600)
        self.setWindowIcon(QIcon("images/histo.png"))

        # Barre de menu
        self.nouveau = QAction(QIcon("images/new.png"), "&Nouveau", self)
        self.nouveau.triggered.connect(self.new)
        self.ouvrir = QAction(QIcon("images/ouvrir.png"), "&Ouvrir", self)
        self.ouvrir.triggered.connect(self.open)
        self.quitter = QAction(QIcon("images/exit.png"), "&Quitter", self)
        self.quitter.triggered.connect(self.close)
        self.recherche = QAction(QIcon("images/recherche.png"), "&Recherche",
                                 self)
        self.recherche.triggered.connect(self.search)

        # Création de la barre de menu
        self.menubar = self.menuBar()
        self.fichier = self.menubar.addMenu("Fichier")
        self.fichier.addAction(self.nouveau)
        self.fichier.addAction(self.quitter)
        self.edition = self.menubar.addMenu("Edition")
        self.outils = self.menubar.addMenu("Outils")
        self.outils.addAction(self.recherche)
        self.affichage = self.menubar.addMenu("Affichage")
        self.aide = self.menubar.addMenu("Aide ?")

        # Création de la barre d'outils
        self.toolbar = QToolBar()
        self.toolbar.setOrientation(QtCore.Qt.Vertical)
        self.toolbar.addAction(self.nouveau)
        self.toolbar.addAction(self.ouvrir)
        self.toolbar.addAction(self.recherche)
        self.toolbar.addAction(self.quitter)
        self.addToolBar(QtCore.Qt.LeftToolBarArea, self.toolbar)

        # Affichage de la barre de status
        self.statusBar().showMessage("Prêt !!!")

    def new(self):
        # Création d'un nouveau fichier d'analyse vide
        self.statusBar().showMessage("Création d'un nouveau fichier")

    def open(self):
        # Ouverture d'une fenêtre de recherche de fichier
        filename = QFileDialog.getOpenFileName(self, "open file", "*.*")
        self.statusBar().showMessage("Chargement du fichier " + filename[0])
        self.fichiers.append(Fichier(filename[0]))

    def search(self):
        print("Search")