Exemple #1
0
    def apply(self):
        #修改MainPlugin的中的值
        self.MainPlugin.unit_pixel = self.ui.unit_pixel.value()
        self.MainPlugin.unit = self.ui.unit.currentIndex()
        self.MainPlugin.font_size = self.ui.font_size.value()
        self.MainPlugin.background_color = self.ui.background_color.text()
        self.MainPlugin.line_width = self.ui.line_width.value()
        #保存到配置文件中
        self.MainPlugin.saveSetting()

        #调用Board接口修改背景色
        #这一句会调用setStyleSheet 所以会重绘
        ExInterFace.setBackgroundColor(self.MainPlugin.background_color)
Exemple #2
0
    def __init__(self, name):
        super().__init__(name)
        self.__drawerItem = DrawerItem("绘图")
        self.__allContentItem = []  #方便循环调用

        #实例化drawerContentItem 即用于侧边栏的按钮
        self.__lineContenItem = DrawerContentItem(
            "直线(&Q)",
            parent=self.__drawerItem,
            icon=QIcon(":/paintshape_res/img/line.png"))
        self.__allContentItem.append(self.__lineContenItem)

        self.__arcContenItem = DrawerContentItem(
            "圆弧(&W)",
            parent=self.__drawerItem,
            icon=QIcon(":/paintshape_res/img/arc.png"))
        self.__allContentItem.append(self.__arcContenItem)

        self.__circleContenItem = DrawerContentItem(
            "圆(&E)",
            parent=self.__drawerItem,
            icon=QIcon(":/paintshape_res/img/circle.png"))
        self.__allContentItem.append(self.__circleContenItem)

        self.__handContenItem = DrawerContentItem(
            "Hand(&R)",
            parent=self.__drawerItem,
            icon=QIcon(":/paintshape_res/img/hand.png"))
        self.__allContentItem.append(self.__handContenItem)

        self.__selectContenItem = DrawerContentItem(
            "选择(&T)",
            parent=self.__drawerItem,
            icon=QIcon(":/paintshape_res/img/select.png"))
        self.__allContentItem.append(self.__selectContenItem)

        #添加到drawerItem
        self.__drawerItem.addContentItems(self.__allContentItem)

        #创建属性dockwidget
        self.propertyDock = ShapePropertyDockWidget("图形属性")
        self.propertyDock.setMinimumWidth(300)

        #菜单
        self.paintShapeMenu = QMenu("绘图")

        self.lineAction = QAction(QIcon(":/paintshape_res/img/line.png"),
                                  "直线(&Q)",
                                  self.paintShapeMenu)  #讲道理 这里可以用eval简化写法
        self.lineAction.setCheckable(True)
        self.lineAction.triggered.connect(self.lineActionToggled)
        self.lineAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.lineAction)

        self.arcAction = QAction(QIcon(":/paintshape_res/img/arc.png"),
                                 "圆弧(&W)", self.paintShapeMenu)
        self.arcAction.setCheckable(True)
        self.arcAction.triggered.connect(self.arcActionToggled)
        self.arcAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.arcAction)

        self.circleAction = QAction(QIcon(":/paintshape_res/img/circle.png"),
                                    "圆(&E)", self.paintShapeMenu)
        self.circleAction.setCheckable(True)
        self.circleAction.triggered.connect(self.circleActionToggled)
        self.circleAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.circleAction)

        self.handAction = QAction(QIcon(":/paintshape_res/img/hand.png"),
                                  "Hand(&R)", self.paintShapeMenu)
        self.handAction.setCheckable(True)
        self.handAction.triggered.connect(self.handActionToggled)
        self.handAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.handAction)

        self.selectAction = QAction(QIcon(":/paintshape_res/img/select.png"),
                                    "选择(&T)", self.paintShapeMenu)
        self.selectAction.setCheckable(True)
        self.selectAction.triggered.connect(self.selectActionToggled)
        self.selectAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.selectAction)

        self.deleteAction = QAction(QIcon(":/paintshape_res/img/delete.png"),
                                    "删除选中(&Delete)", self.paintShapeMenu)
        self.deleteAction.triggered.connect(self.deleteActionTrigger)
        self.deleteAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.deleteAction)

        self.revokeAction = QAction(QIcon(":/paintshape_res/img/revoke.png"),
                                    "撤销(ctr+Z)", self.paintShapeMenu)
        self.revokeAction.triggered.connect(self.revokeActionTrigger)
        self.revokeAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.revokeAction)

        self.forwardAction = QAction(QIcon(":/paintshape_res/img/forward.png"),
                                     "前进(ctr+X)", self.paintShapeMenu)
        self.forwardAction.triggered.connect(self.forwardActionTrigger)
        self.forwardAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.forwardAction)

        self.showPropertyDockAction = QAction(
            QIcon(":/paintshape_res/img/show.png"), "显示属性窗口",
            self.paintShapeMenu)
        self.showPropertyDockAction.triggered.connect(self.propertyDock.show)
        self.showPropertyDockAction.triggered.connect(self.actionChanged)
        self.paintShapeMenu.addAction(self.showPropertyDockAction)

        #连接contentItem的点击信号
        for item in self.__allContentItem:
            item.clickedSignal.connect(self.drawerItemChanged)

        self.__settingWidget = PaintShapSettingWidget(MainPlugin)

        #读取配置文件
        MainPlugin.conf.read(MainPlugin.conf_path)

        MainPlugin.background_color = MainPlugin.conf.get(
            "setting", "background_color")
        MainPlugin.unit_pixel = MainPlugin.conf.getint("setting", "unit_pixel")
        MainPlugin.unit = MainPlugin.conf.getint("setting", "unit")
        MainPlugin.font_size = MainPlugin.conf.getint("setting", "font_size")
        MainPlugin.line_width = MainPlugin.conf.getint("setting", "line_width")

        #为widget赋值
        self.__settingWidget.ui.background_color.setText(
            MainPlugin.background_color)
        self.__settingWidget.ui.unit.setCurrentIndex(MainPlugin.unit)
        self.__settingWidget.ui.unit_pixel.setValue(MainPlugin.unit_pixel)
        self.__settingWidget.ui.font_size.setValue(MainPlugin.font_size)
        self.__settingWidget.ui.line_width.setValue(MainPlugin.line_width)

        #调用接口设置
        ExInterFace.setBackgroundColor(MainPlugin.background_color)