예제 #1
0
 def updateFamily(self, currentItem, previousItem):
     """Update the family edit box and adjust the style and size options"""
     family = unicode(currentItem.text())
     self.familyEdit.setText(family)
     if self.familyEdit.hasFocus():
         self.familyEdit.selectAll()
     prevStyle = unicode(self.styleEdit.text())
     prevSize = unicode(self.sizeEdit.text())
     fontDb = QtGui.QFontDatabase()
     styles = [unicode(style) for style in fontDb.styles(family)]
     self.styleList.clear()
     self.styleList.addItems(styles)
     if prevStyle:
         try:
             num = styles.index(prevStyle)
         except ValueError:
             num = 0
         self.styleList.setCurrentRow(num)
         self.styleList.scrollToItem(self.styleList.currentItem())
     sizes = [repr(size) for size in fontDb.pointSizes(family)]
     self.sizeList.clear()
     self.sizeList.addItems(sizes)
     if prevSize:
         try:
             num = sizes.index(prevSize)
         except ValueError:
             num = 0
         self.sizeList.setCurrentRow(num)
         self.sizeList.scrollToItem(self.sizeList.currentItem())
         self.updateSample()
예제 #2
0
 def load(self):
     '''Called on when loading the plugin'''
     fdb = QtGui.QFontDatabase()
     fdb.addApplicationFont('../../style/Hack-Regular.ttf')
     fdb.addApplicationFont('../../style/Hack-Bold.ttf')
     fdb.addApplicationFont('../../style/Hack-RegularOblique.ttf')
     fdb.addApplicationFont('../../style/Hack-Oblique.ttf')
예제 #3
0
 def readFont(self):
     """Return the selected font or None"""
     family = unicode(self.familyEdit.text())
     style = unicode(self.styleEdit.text())
     size = unicode(self.sizeEdit.text())
     if family and style and size:
         return QtGui.QFontDatabase().font(family, style, int(size))
     return None
예제 #4
0
 def updateStyle(self, fontStyle):
     fontDatabase = QtGui.QFontDatabase()
     oldStrategy = self.displayFont.styleStrategy()
     self.displayFont = fontDatabase.font(self.displayFont.family(),
                                          fontStyle,
                                          self.displayFont.pointSize())
     self.displayFont.setStyleStrategy(oldStrategy)
     self.squareSize = max(
         24,
         QtGui.QFontMetrics(self.displayFont).xHeight() * 3)
     self.adjustSize()
     self.update()
예제 #5
0
    def findStyles(self, font):
        fontDatabase = QtGui.QFontDatabase()
        currentItem = self.styleCombo.currentText()
        self.styleCombo.clear()

        for style in fontDatabase.styles(font.family()):
            self.styleCombo.addItem(style)

        styleIndex = self.styleCombo.findText(currentItem)
        if styleIndex == -1:
            self.styleCombo.setCurrentIndex(0)
        else:
            self.styleCombo.setCurrentIndex(styleIndex)
예제 #6
0
    def draw(self, scene, painter, rect, highlight=False):
        pen = self.select_pen(highlight)
        font = QtGui.QFont(pen.fontname, 8)

        if 0:
            qfd = QtGui.QFontDatabase()
            for x in qfd.families():
                print(x)
            font.setStyleHint(QtGui.QFont.Courier, QtGui.QFont.PreferAntialias)

            # FIXME: always see strange fonts
            qfi = QtGui.QFontInfo(font)

            print(qfi.family())
            print(qfi.styleHint())

        fm = QtGui.QFontMetrics(font)

        w = fm.width(self.t)
        h = fm.height()
        

        x = self.x - w / 2
        y = self.y

        pp = QtGui.QPainterPath()
        pp.moveTo(x, y)
        pp.addText(x, y, font, self.t)
        #print("added text " + str(self.t))
        p = QtGui.QPen(pen.color)
        p.setWidth(pen.linewidth)
        p.setCosmetic(True)
        painter.setPen(p)
        painter.fillPath(pp, QtGui.QBrush(pen.fillcolor))
        

        if 0:  # DEBUG
            # show where dot thinks the text should appear
            print("text shape debug")
            painter.set_source_rgba(1, 0, 0, .9)
            if self.j == self.LEFT:
                x = self.x
            elif self.j == self.CENTER:
                x = self.x - 0.5 * self.w
            elif self.j == self.RIGHT:
                x = self.x - self.w
            painter.moveTo(x, self.y)
            painter.line_to(x + self.w, self.y)
            painter.stroke()
예제 #7
0
파일: dlgEditExe.py 프로젝트: mlabru/sipar
    def findStyles(self):

        fontDatabase = QtGui.QFontDatabase()
        currentItem = self.styleCombo.currentText()
        self.styleCombo.clear()

        for style in fontDatabase.styles(self.fontCombo.currentText()):
            self.styleCombo.addItem(style)

        index = self.styleCombo.findText(currentItem)
        if index == -1:
            self.styleCombo.setCurrentIndex(0)
        else:
            self.styleCombo.setCurrentIndex(index)

        self.characterWidget.updateStyle(self.styleCombo.currentText())
예제 #8
0
    def selectFont(self, combo):
        family = self.fontFamilyCombo.currentText()
        size, ok = self.fontSizeCombo.currentText().toInt()

        # If cells are selected, set their display font

        self.getSelectedRegion()

        if self.startSelectedRow > -1:
            fdb = QtGui.QFontDatabase()

            currentFont = self.table.cellRef(self.startSelectedRow, self.startSelectedColumn).font()

            font = fdb.font(family, fdb.styleString(currentFont), size)

            for i in range(self.startSelectedRow, self.endSelectedRow):
                for j in range(self.startSelectedColumn, self.endSelectedColumn):
                    self.table.cellRef(i, j).setFont(font)
예제 #9
0
 def setFont(self, font):
     """Set the font selector to the given font"""
     fontInfo = QtGui.QFontInfo(font)
     family = fontInfo.family()
     matches = self.familyList.findItems(family, QtCore.Qt.MatchExactly)
     if matches:
         self.familyList.setCurrentItem(matches[0])
         self.familyList.scrollToItem(matches[0],
                                      QtGui.QAbstractItemView.PositionAtTop)
     style = QtGui.QFontDatabase().styleString(fontInfo)
     matches = self.styleList.findItems(style, QtCore.Qt.MatchExactly)
     if matches:
         self.styleList.setCurrentItem(matches[0])
         self.styleList.scrollToItem(matches[0])
     size = repr(fontInfo.pointSize())
     matches = self.sizeList.findItems(size, QtCore.Qt.MatchExactly)
     if matches:
         self.sizeList.setCurrentItem(matches[0])
         self.sizeList.scrollToItem(matches[0])
예제 #10
0
    def setFontCombos(self, font):
        """
        Given a font, set the fontFamilyCombo to show it, set the fontSizeCombo
        to contain valid sizes for that font, and then show the correct font
        size.
        """
        # Set font family
        self.fontFamilyCombo.setEditText(font.family())

        fdb = QtGui.QFontDatabase()
        sizes = fdb.pointSizes(font.family())

        # Clear the sizes combo, fill it with valid sizes based in family

        self.fontSizeCombo.clear()

        if len(sizes) > 1:
            for pts in sizes:
                self.fontSizeCombo.insertItem(pts - 6, QtCore.QString.number(pts))

            self.fontSizeCombo.setEditText(QtCore.QString.number(font.pointSize()))
예제 #11
0
    def findSizes(self, font):
        fontDatabase = QtGui.QFontDatabase()
        currentSize = self.sizeCombo.currentText()
        self.sizeCombo.blockSignals(True)
        self.sizeCombo.clear()

        if fontDatabase.isSmoothlyScalable(font.family(),
                                           fontDatabase.styleString(font)):
            for size in QtGui.QFontDatabase.standardSizes():
                self.sizeCombo.addItem(str(size))
                self.sizeCombo.setEditable(True)
        else:
            for size in fontDatabase.smoothSizes(
                    font.family(), fontDatabase.styleString(font)):
                self.sizeCombo.addItem(str(size))
                self.sizeCombo.setEditable(False)

        self.sizeCombo.blockSignals(False)

        sizeIndex = self.sizeCombo.findText(currentSize)
        if sizeIndex == -1:
            self.sizeCombo.setCurrentIndex(max(0, self.sizeCombo.count() / 3))
        else:
            self.sizeCombo.setCurrentIndex(sizeIndex)
예제 #12
0
    def setupTextActions(self):
        tb = QtGui.QToolBar(self)
        tb.setWindowTitle("Format Actions")
        self.addToolBar(tb)

        menu = QtGui.QMenu("F&ormat", self)
        self.menuBar().addMenu(menu)

        self.actionTextBold = QtGui.QAction(
            QtGui.QIcon.fromTheme('format-text-bold',
                                  QtGui.QIcon(rsrcPath + '/textbold.png')),
            "&Bold",
            self,
            priority=QtGui.QAction.LowPriority,
            shortcut=QtCore.Qt.CTRL + QtCore.Qt.Key_B,
            triggered=self.textBold,
            checkable=True)
        bold = QtGui.QFont()
        bold.setBold(True)
        self.actionTextBold.setFont(bold)
        tb.addAction(self.actionTextBold)
        menu.addAction(self.actionTextBold)

        self.actionTextItalic = QtGui.QAction(
            QtGui.QIcon.fromTheme('format-text-italic',
                                  QtGui.QIcon(rsrcPath + '/textitalic.png')),
            "&Italic",
            self,
            priority=QtGui.QAction.LowPriority,
            shortcut=QtCore.Qt.CTRL + QtCore.Qt.Key_I,
            triggered=self.textItalic,
            checkable=True)
        italic = QtGui.QFont()
        italic.setItalic(True)
        self.actionTextItalic.setFont(italic)
        tb.addAction(self.actionTextItalic)
        menu.addAction(self.actionTextItalic)

        self.actionTextUnderline = QtGui.QAction(
            QtGui.QIcon.fromTheme('format-text-underline',
                                  QtGui.QIcon(rsrcPath + '/textunder.png')),
            "&Underline",
            self,
            priority=QtGui.QAction.LowPriority,
            shortcut=QtCore.Qt.CTRL + QtCore.Qt.Key_U,
            triggered=self.textUnderline,
            checkable=True)
        underline = QtGui.QFont()
        underline.setUnderline(True)
        self.actionTextUnderline.setFont(underline)
        tb.addAction(self.actionTextUnderline)
        menu.addAction(self.actionTextUnderline)

        menu.addSeparator()

        grp = QtGui.QActionGroup(self, triggered=self.textAlign)

        # Make sure the alignLeft is always left of the alignRight.
        if QtGui.QApplication.isLeftToRight():
            self.actionAlignLeft = QtGui.QAction(
                QtGui.QIcon.fromTheme('format-justify-left',
                                      QtGui.QIcon(rsrcPath + '/textleft.png')),
                "&Left", grp)
            self.actionAlignCenter = QtGui.QAction(
                QtGui.QIcon.fromTheme(
                    'format-justify-center',
                    QtGui.QIcon(rsrcPath + '/textcenter.png')), "C&enter", grp)
            self.actionAlignRight = QtGui.QAction(
                QtGui.QIcon.fromTheme(
                    'format-justify-right',
                    QtGui.QIcon(rsrcPath + '/textright.png')), "&Right", grp)
        else:
            self.actionAlignRight = QtGui.QAction(
                QtGui.QIcon.fromTheme(
                    'format-justify-right',
                    QtGui.QIcon(rsrcPath + '/textright.png')), "&Right", grp)
            self.actionAlignCenter = QtGui.QAction(
                QtGui.QIcon.fromTheme(
                    'format-justify-center',
                    QtGui.QIcon(rsrcPath + '/textcenter.png')), "C&enter", grp)
            self.actionAlignLeft = QtGui.QAction(
                QtGui.QIcon.fromTheme('format-justify-left',
                                      QtGui.QIcon(rsrcPath + '/textleft.png')),
                "&Left", grp)

        self.actionAlignJustify = QtGui.QAction(
            QtGui.QIcon.fromTheme('format-justify-fill',
                                  QtGui.QIcon(rsrcPath + '/textjustify.png')),
            "&Justify", grp)

        self.actionAlignLeft.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_L)
        self.actionAlignLeft.setCheckable(True)
        self.actionAlignLeft.setPriority(QtGui.QAction.LowPriority)

        self.actionAlignCenter.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_E)
        self.actionAlignCenter.setCheckable(True)
        self.actionAlignCenter.setPriority(QtGui.QAction.LowPriority)

        self.actionAlignRight.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_R)
        self.actionAlignRight.setCheckable(True)
        self.actionAlignRight.setPriority(QtGui.QAction.LowPriority)

        self.actionAlignJustify.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_J)
        self.actionAlignJustify.setCheckable(True)
        self.actionAlignJustify.setPriority(QtGui.QAction.LowPriority)

        tb.addActions(grp.actions())
        menu.addActions(grp.actions())
        menu.addSeparator()

        pix = QtGui.QPixmap(16, 16)
        pix.fill(QtCore.Qt.black)
        self.actionTextColor = QtGui.QAction(QtGui.QIcon(pix),
                                             "&Color...",
                                             self,
                                             triggered=self.textColor)
        tb.addAction(self.actionTextColor)
        menu.addAction(self.actionTextColor)

        tb = QtGui.QToolBar(self)
        tb.setAllowedAreas(QtCore.Qt.TopToolBarArea
                           | QtCore.Qt.BottomToolBarArea)
        tb.setWindowTitle("Format Actions")
        self.addToolBarBreak(QtCore.Qt.TopToolBarArea)
        self.addToolBar(tb)

        comboStyle = QtGui.QComboBox(tb)
        tb.addWidget(comboStyle)
        comboStyle.addItem("Standard")
        comboStyle.addItem("Bullet List (Disc)")
        comboStyle.addItem("Bullet List (Circle)")
        comboStyle.addItem("Bullet List (Square)")
        comboStyle.addItem("Ordered List (Decimal)")
        comboStyle.addItem("Ordered List (Alpha lower)")
        comboStyle.addItem("Ordered List (Alpha upper)")
        comboStyle.addItem("Ordered List (Roman lower)")
        comboStyle.addItem("Ordered List (Roman upper)")
        comboStyle.activated.connect(self.textStyle)

        self.comboFont = QtGui.QFontComboBox(tb)
        tb.addWidget(self.comboFont)
        self.comboFont.activated[str].connect(self.textFamily)

        self.comboSize = QtGui.QComboBox(tb)
        self.comboSize.setObjectName("comboSize")
        tb.addWidget(self.comboSize)
        self.comboSize.setEditable(True)

        db = QtGui.QFontDatabase()
        for size in db.standardSizes():
            self.comboSize.addItem("%s" % (size))

        self.comboSize.activated[str].connect(self.textSize)
        self.comboSize.setCurrentIndex(
            self.comboSize.findText("%s" %
                                    (QtGui.QApplication.font().pointSize())))
예제 #13
0
def init(version):
    global dbdir, conn, cur, misc
    global webstyle, webscript
    global windowIcon, styleSheet

    styleSheet = '''
		font-size: 10pt;
		font-family: ConsolasHigh,Meiryo;
		background-color: Black;
		color: DarkGray;
	'''
    if is_exe():
        img = QtGui.QPixmap()
        img.loadFromData(
            StringIO(win32api.LoadResource(0, u'CLOUD_PNG', 1)).getvalue())
        windowIcon = QtGui.QIcon(img)
        webstyle = win32api.LoadResource(0, u'STYLE_CSS', 2)
        webscript = win32api.LoadResource(0, u'SRC_JS', 3)
        QtGui.QFontDatabase().addApplicationFontFromData(
            StringIO(win32api.LoadResource(0, u'CONSOLASHIGH_TTF',
                                           4)).getvalue())
    else:
        windowIcon = QtGui.QIcon('resources/cloud.png')
        with open('resources/style.css', 'r') as fp:
            webstyle = fp.read()
        with open('resources/src.js', 'r') as fp:
            webscript = fp.read()
        QtGui.QFontDatabase().addApplicationFont('resources/ConsolasHigh.ttf')

    # init database
    dbdir = '%s\\LR2RR\\' % os.environ['APPDATA']
    if not os.path.exists(dbdir):
        os.makedirs(dbdir)
    conn = sqlite3.connect(dbdir + 'data.db', check_same_thread=False)
    conn.row_factory = sqlite3.Row
    cur = conn.cursor()
    with dbLock:
        try:
            cur.execute('''
				CREATE TABLE IF NOT EXISTS
				rivals(
					id INTEGER NOT NULL UNIQUE,
					name TEXT,
					lastupdate INTEGER NOT NULL,
					active INTEGER
				)''')
            cur.execute('''
				CREATE TABLE IF NOT EXISTS
				scores(
					hash TEXT NOT NULL,
					id INTEGER NOT NULL,
					clear INTEGER NOT NULL,
					notes INTEGER NOT NULL,
					combo INTEGER NOT NULL,
					pg INTEGER NOT NULL,
					gr INTEGER NOT NULL,
					minbp INTEGER NOT NULL,
					UNIQUE(hash, id)
				)''')
            cur.execute('''
				CREATE TABLE IF NOT EXISTS
				recent(
					hash TEXT NOT NULL,
					id INTEGER NOT NULL,
					title TEXT,
					lastupdate INTEGER NOT NULL,
					UNIQUE(hash, id)
				)''')
            cur.execute('''
				CREATE TABLE IF NOT EXISTS
				misc(
					key TEXT NOT NULL UNIQUE,
					value TEXT
				)''')
            cur.execute('REPLACE INTO misc VALUES("version",?)', (version, ))
            cur.execute('INSERT OR IGNORE INTO misc VALUES("lr2exepath","")')
            cur.execute(
                'INSERT OR IGNORE INTO misc VALUES("irlastupdate","Never")')
            cur.execute(
                'INSERT OR IGNORE INTO misc VALUES("difficultieslastupdate","Never")'
            )
            conn.commit()
            cur.execute('SELECT * FROM misc')
            for tt in cur.fetchall():
                misc[tt['key']] = tt['value']
        except:
            conn.rollback()
            sys.exit()
예제 #14
0
 def __init__(self, link, name):
     self.fontDB = QtGui.QFontDatabase()
     self.id = self.fontDB.addApplicationFont(link)
     family = self.fontDB.applicationFontFamilies(self.id).at(0)
     monospace = QtGui.QFont(family)
     self.font = QtGui.QFont(name, 18)
예제 #15
0
    def __init__(self, app, parent=None):
        super(MainWindow, self).__init__()
        self.setWindowTitle(u'UpMachine Project')
        # ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")

        self.app = app
        self.getSetting()
        self.setWindowOpacity(1)  # 初始透明度
        self.setWindowIcon(QtGui.QIcon('./icon.ico'))  # 窗口图标
        self.isMaxShow = 0

        # 窗口样式表文件读取
        sshFile = "./three.qss"
        with open(sshFile, "r") as fh:
            self.setStyleSheet(fh.read())
        #-----------------------------------------------------------------------------
        self.serial = SerialDev()
        # self.soundThread = SoundThread()
        # self.soundThread.run()
        # 左窗口-----------------------------------------------------------------------
        self.leftWidget = QtGui.QWidget()
        # self.leftWidget.setMaximumSize(200,700)
        self.leftWidget.setMaximumSize(200, 4000)
        # self.leftWidget.resize(200,650)
        # self.leftWidget.setStyleSheet("""border:1px solid red""")
        # 使用QSS样式表设置背景颜色
        self.leftWidget.setStyleSheet("""
            .QWidget{
                background:rgb(143,143,143)
            }
            .QLabel{
                background:rgb(143,143,143)
            }
            """)
        # self.leftWidget.setStyleSheet(".QWidget{background:rgb(212,212,212)}")

        # self.leftWidget.testButton = QtGui.QPushButton(u'刷新串口',self.leftWidget)
        self.leftWidget.testButton = PushButton(u'刷新串口', self.leftWidget)

        self.leftWidget.testButton.clicked.connect(self.updateSerial)
        self.leftWidget.linkButton = PushButton(u'连接串口', self.leftWidget)
        self.leftWidget.linkButton.clicked.connect(self.connectSerial)

        self.leftWidget.stopUpdataVoltageDataButton = PushButton(
            u'电压表暂停刷新', self.leftWidget)
        self.leftWidget.stopUpdataGalvanicDataButton = PushButton(
            u'电流表暂停刷新', self.leftWidget)
        self.leftWidget.stopUpdataGalvanicDataButton.clicked.connect(
            self.stopUpdataGalvanicData)
        self.leftWidget.stopUpdataVoltageDataButton.clicked.connect(
            self.stopUpdataVoltageData)
        # 串口选择框
        self.comboBox = QtGui.QComboBox(self.leftWidget)

        # 识别可用的串口
        # for i in self.serial.getPort():
        #     self.comboBox.addItem(i)

        # 波特率选择框
        self.baudrateComboBox = QtGui.QComboBox()
        index = 0
        for i in (2400, 4800, 9600, 19200, 115200):
            self.baudrateComboBox.addItem(str(i))
            if str(i) == self.baudrate:
                self.baudrateComboBox.setCurrentIndex(index)
            index += 1
        self.baudrateLabel = QtGui.QLabel(u' 波特率选择')
        # 数据位数选择框
        self.bytesizeComboBox = QtGui.QComboBox()
        index = 0
        for i in range(len(SerialDev.BYTESIZES)):
            self.bytesizeComboBox.addItem(str(SerialDev.BYTESIZES[i]))
            if SerialDev.BYTESIZES[i] == SerialDev.SETTING.EIGHTBITS:
                index = i
            if SerialDev.BYTESIZES[i] == self.bytesize:
                index = i
        self.bytesizeComboBox.setCurrentIndex(index)
        self.bytesizeComboBox.setEnabled(False)
        self.bytesizeLabel = QtGui.QLabel(u' 数据位选择')
        # 停止位选择框
        self.stopbitsComboBox = QtGui.QComboBox()
        for i in range(len(SerialDev.STOPBITS)):
            self.stopbitsComboBox.addItem(str(SerialDev.STOPBITS[i]))
            if SerialDev.STOPBITS[i] == SerialDev.SETTING.STOPBITS_ONE:
                index = i
            if SerialDev.STOPBITS[i] == self.stopbits:
                index = i
        self.stopbitsComboBox.setCurrentIndex(index)
        self.stopbitsComboBox.setEnabled(False)
        self.stopbitsLabel = QtGui.QLabel(u' 停止位选择')

        # 左下角提示Label
        self.tipLabel = QtGui.QLabel(u'          ')
        self.statusLabel = QtGui.QLabel(u'          ')
        # self.tipLabel = QtGui.QLabel(u'Hello World')

        # 左边边框布局
        self.grid = QtGui.QGridLayout()
        self.verticalLayout = QtGui.QVBoxLayout(self.leftWidget)

        # 左上关于按钮
        self.aboutPushButton = labelBtn(u'about', self.leftWidget)
        self.aboutPushButton.setMaximumSize(200, 101)
        self.aboutPushButton.resize(200, 101)
        self.aboutPushButton.setPixmap(QtGui.QPixmap(r'./aboutNormal.png'))
        self.aboutPushButton.Entered.connect(self.buttonEnterFunc)
        self.aboutPushButton.Leaved.connect(self.buttonLeavedFunc)

        self.verticalLayout.addWidget(self.aboutPushButton, 0)  #列
        self.verticalLayout.addLayout(self.grid)

        # 输入框  ---------------------------------
        # VoltageLayout_one  = QtGui.QHBoxLayout()
        # GalvanicLayout_one = QtGui.QHBoxLayout()

        # self.leftWidget.sendVoltageDataButton  = PushButton(u'电压指令',self.leftWidget)
        # self.leftWidget.sendGalvanicDataButton = PushButton(u'电流指令',self.leftWidget)

        # self.leftWidget.sendVoltageDataLineEdit  = QtGui.QDoubleSpinBox(self.leftWidget)
        # self.leftWidget.sendGalvanicDataLineEdit = QtGui.QDoubleSpinBox(self.leftWidget)

        # self.leftWidget.sendVoltageDataLineEdit.setMinimumHeight(40)
        # self.leftWidget.sendVoltageDataLineEdit.setStyleSheet("""
        #     background:transparent;
        #     border: 0px solid red;
        #     font-size:40px;
        #     color:rgb(0,220,0);
        #     selection-color:rgb(0,220,0);
        #     selection-background-color: rgb(143,143,143);
        #     """)
        # self.leftWidget.sendVoltageDataLineEdit.setButtonSymbols(QtGui.QAbstractSpinBox.NoButtons)

        # self.leftWidget.sendGalvanicDataLineEdit.setMinimumHeight(40)
        # self.leftWidget.sendGalvanicDataLineEdit.setStyleSheet("""
        #     background:transparent;
        #     border: 0px solid red;
        #     font-size:40px;
        #     color:rgb(0,220,0);
        #     selection-color:rgb(0,220,0);
        #     selection-background-color: rgb(143,143,143);
        #     """)
        # self.leftWidget.sendGalvanicDataLineEdit.setButtonSymbols(QtGui.QAbstractSpinBox.NoButtons)

        # VoltageLayout_one.addWidget(self.leftWidget.sendVoltageDataLineEdit )
        # VoltageLayout_one.addWidget(self.leftWidget.sendVoltageDataButton )
        # GalvanicLayout_one.addWidget(self.leftWidget.sendGalvanicDataLineEdit)
        # GalvanicLayout_one.addWidget(self.leftWidget.sendGalvanicDataButton)

        # VoltageLayout_one.setContentsMargins(3,0,0,0)
        # GalvanicLayout_one.setContentsMargins(3,0,0,0)

        # self.verticalLayout.addLayout(VoltageLayout_one )
        # self.verticalLayout.addLayout(GalvanicLayout_one)
        # 输入框 Over ---------------------------------

        # 连接按钮
        self.verticalLayout.addWidget(self.leftWidget.linkButton)
        # 暂停按钮
        self.verticalLayout.addWidget(
            self.leftWidget.stopUpdataVoltageDataButton)
        self.verticalLayout.addWidget(
            self.leftWidget.stopUpdataGalvanicDataButton)

        # 输入框  ---------------------------------
        VoltageLayout_one = QtGui.QHBoxLayout()
        GalvanicLayout_one = QtGui.QHBoxLayout()
        startStopLayout = QtGui.QHBoxLayout()

        self.leftWidget.sendVoltageDataButton = PushButton(
            u'电压指令', self.leftWidget)
        self.leftWidget.sendGalvanicDataButton = PushButton(
            u'电流指令', self.leftWidget)

        # 可调范围 0 ~ 500
        self.leftWidget.sendVoltageDataLineEdit = QtGui.QDoubleSpinBox(
            self.leftWidget)
        self.leftWidget.sendVoltageDataLineEdit.setRange(0, 500)
        self.leftWidget.sendVoltageDataLineEdit.setDecimals(0)  # 小数位数
        # 可调范围 0 ~ 20
        self.leftWidget.sendGalvanicDataLineEdit = QtGui.QDoubleSpinBox(
            self.leftWidget)
        self.leftWidget.sendGalvanicDataLineEdit.setRange(0, 20)
        self.leftWidget.sendGalvanicDataLineEdit.setDecimals(0)  # 小数位数

        self.leftWidget.sendVoltageDataLineEdit.setMinimumHeight(40)
        self.leftWidget.sendVoltageDataLineEdit.setStyleSheet("""
            background:transparent;
            border: 0px solid red;
            font-size:40px;
            color:rgb(0,220,0);
            selection-color:rgb(0,220,0);
            selection-background-color: rgb(143,143,143);
            """)
        self.leftWidget.sendVoltageDataLineEdit.setButtonSymbols(
            QtGui.QAbstractSpinBox.NoButtons)

        self.leftWidget.sendGalvanicDataLineEdit.setMinimumHeight(40)
        self.leftWidget.sendGalvanicDataLineEdit.setStyleSheet("""
            background:transparent;
            border: 0px solid red;
            font-size:40px;
            color:rgb(0,220,0);
            selection-color:rgb(0,220,0);
            selection-background-color: rgb(143,143,143);
            """)
        self.leftWidget.sendGalvanicDataLineEdit.setButtonSymbols(
            QtGui.QAbstractSpinBox.NoButtons)

        VoltageLayout_one.addWidget(self.leftWidget.sendVoltageDataLineEdit)
        VoltageLayout_one.addWidget(self.leftWidget.sendVoltageDataButton)
        GalvanicLayout_one.addWidget(self.leftWidget.sendGalvanicDataLineEdit)
        GalvanicLayout_one.addWidget(self.leftWidget.sendGalvanicDataButton)

        VoltageLayout_one.setContentsMargins(3, 0, 0, 0)
        GalvanicLayout_one.setContentsMargins(3, 0, 0, 0)
        # startStopLayout.setContentsMargins(3,0,0,0)

        self.verticalLayout.addLayout(startStopLayout)
        self.verticalLayout.addLayout(VoltageLayout_one)
        self.verticalLayout.addLayout(GalvanicLayout_one)

        # 输入框 Over ---------------------------------
        # 启动暂停按钮
        self.startButton = PushButton(u'启动', self.leftWidget)
        self.stopButton = PushButton(u'暂停', self.leftWidget)
        self.startButton.clicked.connect(self.requestStartData)
        self.stopButton.clicked.connect(self.requestStopData)
        startStopLayout.addWidget(self.startButton)
        startStopLayout.addWidget(self.stopButton)
        # 启动暂停按钮 Over

        self.verticalLayout.addWidget(self.tipLabel)
        self.verticalLayout.addWidget(self.statusLabel)
        self.verticalLayout.setContentsMargins(3, 2, 3, 3)

        # 窗口伸缩控件
        self.verticalLayout.addItem(
            QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                              QtGui.QSizePolicy.Expanding))
        self.verticalLayout.addWidget(QtGui.QSizeGrip(self))

        self.leftWidget.setLayout(self.verticalLayout)

        self.grid.addWidget(self.leftWidget.testButton, 0, 1)  # 行 列
        self.grid.addWidget(self.comboBox, 0, 0)
        self.grid.addWidget(self.baudrateComboBox, 1, 0)
        self.grid.addWidget(self.baudrateLabel, 1, 1)
        self.grid.addWidget(self.bytesizeComboBox, 2, 0)
        self.grid.addWidget(self.bytesizeLabel, 2, 1)
        self.grid.addWidget(self.stopbitsComboBox, 3, 0)
        self.grid.addWidget(self.stopbitsLabel, 3, 1)

        self.grid.setContentsMargins(5, 10, 5, 5)  # 显示边距

        # ----------------------------------------------------------------------------

        self.content_splitter = QtGui.QSplitter()
        self.content_splitter.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                            QtGui.QSizePolicy.Expanding)
        self.content_splitter.setOrientation(QtCore.Qt.Horizontal)
        self.content_splitter.setHandleWidth(1)
        self.content_splitter.setStyleSheet(
            "QSplitter.handle{background:lightgray}")
        # self.content_splitter.setStyleSheet("""border:1px solid red""")

        # 容纳主部件的 widget
        self.contentWidget = QtGui.QMainWindow()
        self.content_splitter.addWidget(self.leftWidget)
        self.content_splitter.addWidget(self.contentWidget)
        # 主 Layout
        self.main_layout = QtGui.QVBoxLayout()
        # self.content_splitter.setStyleSheet("""border:1px solid red""")
        # self.main_layout.addWidget(self.titlebar)
        self.main_layout.addWidget(self.content_splitter)
        self.main_layout.setSpacing(0)  # 间距     # layout.addStretch() 弹簧
        self.main_layout.setContentsMargins(10, 7, 10, 7)
        # 主窗口底层
        self.widget = QtGui.QWidget()
        self.setCentralWidget(self.widget)
        self.widget.setLayout(self.main_layout)

        # 窗口伸缩问题
        # self.main_layout.addWidget(QtGui.QSizeGrip(self));

        # 窗口属性
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
        self.desktop = QtGui.QApplication.desktop()
        self.LeftButtonPreesed = 0
        self.resize(1000, 650)
        self.center(1)  # 居中显示

        # 表格界面
        self.PlotWidget = pyqtgraph.GraphicsWindow()  # QtGui.QWidget()
        self.PlotWidget.setWindowOpacity(0)
        self.contentWidget.setCentralWidget(self.PlotWidget)

        # 黑色前景色
        # pyqtgraph.setConfigOption('foreground',(255,255,255))
        # useOpenGL
        # pyqtgraph.setConfigOption('useOpenGL',True)
        # 抗锯齿
        # pyqtgraph.setConfigOption('antialias',True)

        # http://www.pyqtgraph.org/documentation/functions.html#pyqtgraph.mkPen
        # 画笔 颜色 宽度 美化?
        # self.greenPen = pyqtgraph.mkPen((0,220,0), width=1.2,cosmetic=True,style=QtCore.Qt.SolidLine)
        self.greenPen = pyqtgraph.mkPen((0, 220, 0),
                                        width=1.2,
                                        cosmetic=False,
                                        style=QtCore.Qt.SolidLine)

        # 上层第一个电压图表
        # http://localhost:7464/pyqtgraph.graphicsItems.PlotItem.PlotItem.html
        self.upPlot = self.PlotWidget.addPlot()
        # self.upPlot.setLimits(xMax=350) # X轴显示最大值
        self.upPlot.showGrid(x=True, y=True)  #网格

        self.data = np.random.normal(size=300)
        self.lastestData = 0

        # self.upCurve = self.upPlot.plot(self.data, pen=self.greenPen)
        self.upPlot.setLabel('bottom',
                             text=u'时间',
                             units='s',
                             unitPrefix='test')
        self.upPlot.setLabel('left', text=u'电压', units='V')
        self.upPlot.setTitle(u'电压信号图')
        # self.upPlot.setRange(xRange=[0, 350])   #坐标默认显示的区间

        # 换行画图
        self.PlotWidget.nextRow()

        # 下层第二个电流图表
        self.downPlot = self.PlotWidget.addPlot()
        self.downPlot.showGrid(x=True, y=True)
        # antialias抗锯齿
        # self.downCurve = self.downPlot.plot(self.data, pen=self.greenPen)#antialias=True)
        self.downPlot.setLabel('bottom', text=u'时间', units='s')
        self.downPlot.setLabel('left', text=u'电流', units='A')
        self.downPlot.setTitle(u'电流信号图')
        self.downPlot.setRange(yRange=[0, 30])

        # self.PlotWidget.setBackground((252,252,252))#QtGui.QBrush(QtGui.QColor(255,255,255,255)))

        # -------------------------------------------------------------------------------
        self.galvanicData = []  # 电流数据
        self.voltageData = []  # 电压数据
        self.lastestGalvanicData = 0  # 最新电流数据
        self.lastestVoltageData = 0  # 最新电压数据
        self.serialDataString = ""  # 所有的数据字符串
        self.serialDataCursor = 0  # 数据指针
        self.serialDataList = []  # 数据存储列表
        self.stopUpdateGalvanicDataFlag = 1  # 电流暂停标志
        self.stopUpdateVoltageDataFlag = 1  # 电压暂停标志
        # 输出系统信息 ----------------------------------------------------------------------
        print pyqtgraph.systemInfo()

        # 窗口按钮 Grid 此布局利用QtDesign设计代码移入-----------------------------------
        self.gridLayout = QtGui.QGridLayout(self.PlotWidget)
        self.gridLayout.setMargin(0)  # 间距
        self.gridLayout.setSpacing(0)  # 间距
        # 最大化按钮
        self.maxPushButton = labelBtn(u'max', self.PlotWidget)
        self.maxPushButton.setPixmap(QtGui.QPixmap(r'./maxNormal.png'))
        self.maxPushButton.Entered.connect(self.buttonEnterFunc)
        self.maxPushButton.Leaved.connect(self.buttonLeavedFunc)
        self.maxPushButton.Clicked.connect(self.maxFunc)
        self.gridLayout.addWidget(self.maxPushButton, 0, 2, 1, 1)
        # 关闭按钮
        self.closePushButton = labelBtn(u'close', self.PlotWidget)
        self.closePushButton.setPixmap(QtGui.QPixmap(r'./closeNormal.png'))
        self.closePushButton.Entered.connect(self.buttonEnterFunc)
        self.closePushButton.Leaved.connect(self.buttonLeavedFunc)
        self.closePushButton.Clicked.connect(self.closeFunc)
        self.gridLayout.addWidget(self.closePushButton, 0, 3, 1, 1)

        spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                                       QtGui.QSizePolicy.Expanding)  # 两个弹簧控件
        self.gridLayout.addItem(spacerItem, 1, 3, 1, 1)  # 行 列
        spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                                        QtGui.QSizePolicy.Minimum)
        self.gridLayout.addItem(spacerItem2, 0, 0, 1, 1)
        # 最小化按钮
        self.minPushButton = labelBtn(u'min', self.PlotWidget)
        self.minPushButton.Entered.connect(self.buttonEnterFunc)
        self.minPushButton.Leaved.connect(self.buttonLeavedFunc)
        self.minPushButton.Clicked.connect(self.minFunc)
        self.minPushButton.setPixmap(QtGui.QPixmap(r'./minNormal.png'))
        self.gridLayout.addWidget(self.minPushButton, 0, 1, 1, 1)
        # 窗口按钮Over ------------------------------------------------------------------
        # QtDesign设计的两个lable布局-------------------------------------------------------------------------------

        self.gridLayout2 = QtGui.QGridLayout()

        spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                                       QtGui.QSizePolicy.Expanding)
        self.gridLayout2.addItem(spacerItem, 6, 1, 1, 1)
        self.label = QtGui.QLabel(u'     ', self.PlotWidget)
        self.gridLayout2.addWidget(self.label, 1, 0, 1, 1)
        spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                                        QtGui.QSizePolicy.Expanding)
        self.gridLayout2.addItem(spacerItem1, 2, 1, 1, 1)
        self.label_3 = QtGui.QLabel(self.PlotWidget)
        self.gridLayout2.addWidget(self.label_3, 0, 0, 1, 1)
        self.label_2 = QtGui.QLabel(u'     ', self.PlotWidget)
        self.gridLayout2.addWidget(self.label_2, 4, 0, 1, 1)
        self.label_4 = QtGui.QLabel(self.PlotWidget)
        self.gridLayout2.addWidget(self.label_4, 3, 0, 1, 1)
        spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                                        QtGui.QSizePolicy.Minimum)
        self.gridLayout2.addItem(spacerItem2, 3, 1, 1, 1)

        self.gridLayout.addLayout(self.gridLayout2, 1, 0, 1, 1)

        self.label.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.label.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
        self.label_2.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.label_2.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
        self.label_3.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.label_3.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)
        self.label_4.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.label_4.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)

        self.font = QtGui.QFont()
        self.font.setPixelSize(60)  #设置字号32,以像素为单位

        print self.font.family()
        QtGui.QFontDatabase.addApplicationFont("MiuiEx-Light.ttf")
        self.font.setFamily("MIUI EX")
        print self.font.family()
        for i in QtGui.QFontDatabase.families(QtGui.QFontDatabase()):
            # print i.toUtf8()
            pass

        # self.font.setFamily("SimSun") #设置字体
        # self.font.setWeight(1)     #设置字型,不加粗

        self.label.setStyleSheet("color:rgb(0,220,0)")
        self.label.setFont(self.font)
        self.label_2.setStyleSheet("color:rgb(0,220,0)")
        self.label_2.setFont(self.font)

        # --------------------------------------------------------------------------------
        # Connect Event 串口接收信号与槽连接-----------------------------------------------------------------
        self.connect(self.serial.qObj, QtCore.SIGNAL('SerialRecvData'),
                     self.recvSerialData)
        '''电压指令'''
        self.leftWidget.sendVoltageDataButton.clicked.connect(
            self.requestVoltageData)
        '''电流指令'''
        self.leftWidget.sendGalvanicDataButton.clicked.connect(
            self.requestGalvanicData)

        # Timer To ADD AblePort
        self.timer = QtCore.QTimer()
        self.timer.setSingleShot(True)
        self.timer.timeout.connect(self.timerTaskForSearchSeries)
        self.timer.start(0)  # Start Now

        # self.setFocusProxy()
        self.setFocus()
예제 #16
0
    def __init__(self, p=None, name=None):
        """
        Construct the Spreadsheet object.  Creates a QMainWindow with a menu
        and toolbar, a QicsTable, and connects the appropriate slots to load
        and manipulate data.
        """
        QtGui.QMainWindow.__init__(self)

        self._currency = QicsDataItemCurrencyFormatter()

        #self.setCaption("Excellent Spreadsheet Demo")

        # Pulldown Menu

        # File
        file = QtGui.QMenu("&File", self)
	# Formating menu File with connect to Python function
	## New

	self._New = QtGui.QAction("&New", self)
    #self._New.setShortcut(QtGui.QKeySequence("Ctrl+N"))

	## Shortcut keys

	self._New.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_N
	file.addAction(self._New)

	## Connect to self.fileNew Python func

	self.connect(self._New, QtCore.SIGNAL("triggered()"), self.fileNew)

	## Open
	self._Open = QtGui.QAction("&Open", self)
	## Shortcut keys
	self._Open.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_O
	file.addAction(self._Open)
	## Connect to self.openFile Python func
	self.connect(self._Open, QtCore.SIGNAL("triggered()"), self.openFile)

	## Save
	self._Save = QtGui.QAction("&Save", self)
	## Shortcut keys
	self._Save.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_S
	file.addAction(self._Save)
	## Connect to self.saveFile Python func
	self.connect(self._Save, QtCore.SIGNAL("triggered()"), self.saveFile)

	## Save As
	self._SaveAs = QtGui.QAction("S&ave As", self)
    ## Shortcut keys
    #self._Save.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_S
	file.addAction(self._SaveAs)
	## Connect to self.saveFile Python func
	self.connect(self._SaveAs, QtCore.SIGNAL("triggered()"), self.saveFileAs)

	## Exit
	self._Exit = QtGui.QAction("E&xit", self)
	## Shortcut keys
	self._Save.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_X
	file.addAction(self._Exit)
	## Connect to self.saveFile Python func
	self.connect(self._Exit,QtCore.SIGNAL("triggered()"), Qt.qApp, QtCore.SLOT("closeAllWindows()"))
	# Show File menu in menubar

	self.menuBar().addMenu(file)

    # Edit
	edit = QtGui.QMenu("&Edit", self)
	self._Copy = QtGui.QAction("&Copy", self)
	## Shortcut keys
	self._Copy.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_C
	edit.addAction(self._Copy)
	## Connect to self.fileNew Python func
	self.connect(self._Copy, QtCore.SIGNAL("triggered()"), self.copy)

	# Paste
	self._Paste = QtGui.QAction("&Paste", self)
	## Shortcut keys
	self._Paste.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_C
	edit.addAction(self._Paste)
    ## Connect to self.fileNew Python func
	self.connect(self._Paste, QtCore.SIGNAL("triggered()"), self.paste)
	self.menuBar().addMenu(edit)

	## View
	view = QtGui.QMenu("View", self)
	self._View = QtGui.QAction("&View", self)
	## Shortcut keys
	self._View.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_V
	view.addAction(self._View)
    #self.connect(self._View, QtCore.SIGNAL("triggered()"), self.view)
	self.menuBar().addMenu(view)

	## Insert
	insert = QtGui.QMenu("Insert", self)
	self._InsertRow = QtGui.QAction("&Row", self)
	## Shortcut keys
	insert.addAction(self._InsertRow)
	self.connect(self._InsertRow, QtCore.SIGNAL("triggered()"), self.insertRow)
	self._InsertCol = QtGui.QAction("Co&lumn", self)
	## Shortcut keys
	insert.addAction(self._InsertCol)
	self.connect(self._InsertCol, QtCore.SIGNAL("triggered()"), self.insertColumn)
	self.menuBar().addMenu(insert)

	## Format

        format = QtGui.QMenu("Format", self)
        self.menuBar().addMenu(format)

        rowFormat = QtGui.QMenu("Row", self)
        format.addMenu(rowFormat)
        format.addSeparator()

        self._Foreground = QtGui.QAction("Fore&ground...", self)
        format.addAction(self._Foreground)
        self.connect(self._Foreground, QtCore.SIGNAL("triggered()"), self.formatForegroundColor)

        self._Background = QtGui.QAction("&Background...", self)
        format.addAction(self._Background)
        self.connect(self._Background, QtCore.SIGNAL("triggered()"), self.formatBackgroundColor)

        self._Font = QtGui.QAction("&Font...", self)
        format.addAction(self._Font)
        self.connect(self._Font, QtCore.SIGNAL("triggered()"), self.formatFont)


        # Tools
        tools = QtGui.QMenu("&Tools", self)
        self.menuBar().addMenu(tools)

        self.showQSAAction = QtGui.QAction(self.tr("Script Editor"), self)
        self.connect(self.showQSAAction, QtCore.SIGNAL("triggered()"), self.showQSAWorkbench)
        tools.addAction(self.showQSAAction)

        self.scriptTestAction = QtGui.QAction(self.tr("Script Test"), self)
        self.connect(self.scriptTestAction, QtCore.SIGNAL("triggered()"), self.testScripts)
        tools.addAction(self.scriptTestAction)

        self.saveScriptAction = QtGui.QAction(self.tr("Save Script"), self)
        self.connect(self.saveScriptAction, QtCore.SIGNAL("triggered()"), self.saveScripts)
        tools.addAction(self.saveScriptAction)

        # Data
        data = QtGui.QMenu("&Data", self)
        self.menuBar().addMenu(data)

        self.sortAscAction = QtGui.QAction(self.tr("&Ascendingt"), self)
        self.connect(self.sortAscAction, QtCore.SIGNAL("triggered()"), self.sortAscending)
        data.addAction(self.sortAscAction)

        self.sortDescAction = QtGui.QAction(self.tr("&Descendingt"), self)
        self.connect(self.sortDescAction, QtCore.SIGNAL("triggered()"), self.sortDescending)
        data.addAction(self.sortDescAction)

        # Spans
        spans = QtGui.QMenu("Spans", self)
        self.menuBar().addMenu(spans)

        self.addSpanAction = QtGui.QAction(self.tr("Add Span"), self)
        self.connect(self.addSpanAction, QtCore.SIGNAL("triggered()"), self.addSpan)
        spans.addAction(self.addSpanAction)

        self.removeSpanAction = QtGui.QAction(self.tr("Remove Span"), self)
        self.connect(self.removeSpanAction, QtCore.SIGNAL("triggered()"), self.removeSpan)
        spans.addAction(self.removeSpanAction)        

        # Toolbars

        # File operation toolbar

        fileTools = QtGui.QToolBar("File tools", self)

        #QtGui.QToolButton(_getIconSet("filenew.xpm"), "New", QtCore.QString, self.fileNew, fileTools)
        self.fileNewButton = QtGui.QToolButton()

        self.fileNewAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/filenew.xpm")), self.tr("&New"), self)
        self.connect(self.fileNewAct, QtCore.SIGNAL("triggered()"), self.fileNew)
        fileTools.addAction(self.fileNewAct)

        self.fileOpenAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/fileopen.xpm")), self.tr("&Open"), self)
        self.connect(self.fileOpenAct, QtCore.SIGNAL("triggered()"), self.openFile)
        fileTools.addAction(self.fileOpenAct)

        self.fileSaveAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/filesave.xpm")), self.tr("&Save"), self)
        self.connect(self.fileSaveAct, QtCore.SIGNAL("triggered()"), self.saveFile)
        fileTools.addAction(self.fileSaveAct)

        fileTools.addSeparator()

        # Edit operations
        self.cutAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/editcut.xpm")), self.tr("&Cut"), self)
        self.connect(self.cutAct, QtCore.SIGNAL("triggered()"), self.cut)
        fileTools.addAction(self.cutAct)

        self.copyAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/editcopy.xpm")), self.tr("&Copy"), self)
        self.connect(self.copyAct, QtCore.SIGNAL("triggered()"), self.copy)
        fileTools.addAction(self.copyAct)

        self.pasteAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/editpaste.xpm")), self.tr("&Paste"), self)
        self.connect(self.pasteAct, QtCore.SIGNAL("triggered()"), self.paste)
        fileTools.addAction(self.pasteAct)

        fileTools.addSeparator()

        # Sort

        self.sortAscendingAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/sortasc.xpm")), self.tr("Sort Ascending"), self)
        self.connect(self.sortAscendingAct, QtCore.SIGNAL("triggered()"), self.sortAscending)
        fileTools.addAction(self.sortAscendingAct)

        self.sortDescendingAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/sortdesc.xpm")), self.tr("Sort Descending"), self)
        self.connect(self.sortDescendingAct, QtCore.SIGNAL("triggered()"), self.sortDescending)
        fileTools.addAction(self.sortDescendingAct)

        fileTools.addSeparator()

        self.addToolBar(fileTools)

        # Font name and point size

        fontTools = QtGui.QToolBar("Font tools", self)

        self.fontFamilyCombo = QtGui.QComboBox(fontTools)
        self.fontSizeCombo = QtGui.QComboBox(fontTools)

        fontTools.addWidget(self.fontFamilyCombo)
        fontTools.addWidget(self.fontSizeCombo)

        self.connect(self.fontFamilyCombo, QtCore.SIGNAL("activated(int)"), self.selectFont)
        self.connect(self.fontSizeCombo, QtCore.SIGNAL("activated(int)"), self.selectFont)

        fdb = QtGui.QFontDatabase()
        families = fdb.families()
        self.fontFamilyCombo.insertItems(0, families)

        # Font format operations

        self.boldAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/textbold.xpm")), self.tr("Bold"), self)
        self.connect(self.boldAction, QtCore.SIGNAL("triggered()"), self.textBold)
        fontTools.addAction(self.boldAction)
        self.boldAction.setCheckable(True)

        self.italicAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/textitalic.xpm")), self.tr("Italic"), self)
        self.connect(self.italicAction, QtCore.SIGNAL("triggered()"), self.textItalic)
        fontTools.addAction(self.italicAction)
        self.italicAction.setCheckable(True)

        self.underlineAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/textunder.xpm")), self.tr("Underline"), self)
        self.connect(self.underlineAction, QtCore.SIGNAL("triggered()"), self.textUnderline)
        fontTools.addAction(self.underlineAction)
        self.underlineAction.setCheckable(True)

        fontTools.addSeparator()

        # Text Alignment

        self.textLeftAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/textleft.xpm")), self.tr("Align Left"), self)
        self.connect(self.textLeftAction, QtCore.SIGNAL("triggered()"), self.textAlignLeft)
        fontTools.addAction(self.textLeftAction)
        self.textLeftAction.setCheckable(True)

        self.textCenterAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/textcenter.xpm")), self.tr("Align Center"), self)
        self.connect(self.textCenterAction, QtCore.SIGNAL("triggered()"), self.textAlignCenter)
        fontTools.addAction(self.textCenterAction)
        self.textCenterAction.setCheckable(True)

        self.textRightAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/textright.xpm")),"Align Right", self)
        self.connect(self.textRightAction, QtCore.SIGNAL("triggered()"), self.textAlignRight)
        fontTools.addAction(self.textRightAction)
        self.textRightAction.setCheckable(True)

        fontTools.addSeparator()

        # Formatters

        currencyTB = QtGui.QToolButton(fontTools)
        currencyTB.setText("$")
        self.connect(currencyTB, QtCore.SIGNAL("clicked()"), self.setCurrencyFormatter)

        fontTools.addWidget(currencyTB)

        fontTools.addSeparator()

        # Colors

        self.formatForegroundColorAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/fontcolor.xpm")), self.tr("Font Color"), self)
        self.connect(self.formatForegroundColorAction, QtCore.SIGNAL("triggered()"), self.formatForegroundColor)
        fontTools.addAction(self.formatForegroundColorAction)

        self.addToolBar(fontTools)

        # Table

        vbox = QtGui.QWidget(self)
        vboxLayout = QtGui.QVBoxLayout();
        cellrow = QtGui.QWidget(vbox)
        cellrowLayout = QtGui.QHBoxLayout()
        cellrowLayout.setMargin(2)
        cellrowLayout.addWidget(QtGui.QLabel("Cell value = "))

        self.cellLineEdit = QtGui.QLineEdit()
        cellrowLayout.addWidget(self.cellLineEdit)
        cellrow.setLayout(cellrowLayout)

        self.connect(self.cellLineEdit, QtCore.SIGNAL("returnPressed()"), self.cellLineUpdate)

        lastRow = 10
        lastCol = 50

        # Create the data model
        self.dm = QicsDataModelDefault(lastRow, lastCol)

        # Create the table, using the data model we created above
        self.table = QicsTable(self.dm)
        # self.table.setViewport(Qics.QicsRegion(0, 0, 50, 50))
        vboxLayout.addWidget(cellrow)
        vboxLayout.addWidget(self.table)
        vbox.setLayout(vboxLayout)

        self.connect(self.table, QtCore.SIGNAL("selectionListChanged(bool)"), self.updateSelection)

        # Set some visual resources on the table
        self.table.rowHeader().setAlignment(QtCore.Qt.AlignHCenter)
        self.table.columnHeader().setAlignment(QtCore.Qt.AlignHCenter)
        self.table.rowHeader().column(0).setWidthInChars(3)
        self.table.mainGridRef().setBackgroundColor(QtCore.Qt.white)
        
        # Set row sorting mode to non-distractive sord

        self.table.show()

        self.setFontCombos(self.table.font())

        self.setCentralWidget(vbox)

        self.statusBar().showMessage("Ready", -1)

        self.fileName = QtCore.QString("")
예제 #17
0
    def __init__(self, printData, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.printData = printData
        self.outputFont = self.printData.getOutputFont()
        self.currentFont = self.printData.getOptionPrintFont()
        if not self.currentFont:
            self.currentFont = self.outputFont

        topLayout = QtGui.QVBoxLayout(self)
        self.setLayout(topLayout)
        defaultBox = QtGui.QGroupBox(_('Default Font'))
        topLayout.addWidget(defaultBox)
        defaultLayout = QtGui.QVBoxLayout(defaultBox)
        self.outputCheck = QtGui.QCheckBox(_('Use &Data Output font'))
        defaultLayout.addWidget(self.outputCheck)
        self.outputCheck.setChecked(globalref.options.
                                    boolData('PrintUseOutputFont'))
        self.connect(self.outputCheck, QtCore.SIGNAL('clicked(bool)'),
                     self.setFontSelectAvail)

        self.fontBox = QtGui.QGroupBox(_('Select Font'))
        topLayout.addWidget(self.fontBox)
        fontLayout = QtGui.QGridLayout(self.fontBox)
        spacing = fontLayout.spacing()
        fontLayout.setSpacing(0)

        label = QtGui.QLabel(_('&Font'))
        fontLayout.addWidget(label, 0, 0)
        label.setIndent(2)
        self.familyEdit = QtGui.QLineEdit()
        fontLayout.addWidget(self.familyEdit, 1, 0)
        self.familyEdit.setReadOnly(True)
        self.familyList = SmallListWidget()
        fontLayout.addWidget(self.familyList, 2, 0)
        label.setBuddy(self.familyList)
        self.familyEdit.setFocusProxy(self.familyList)
        fontLayout.setColumnMinimumWidth(1, spacing)
        families = [unicode(fam) for fam in QtGui.QFontDatabase().families()]
        families.sort(lambda x,y: cmp(x.lower(), y.lower()))
        self.familyList.addItems(families)
        self.connect(self.familyList,
                     QtCore.SIGNAL('currentItemChanged(QListWidgetItem*, '\
                                   'QListWidgetItem*)'), self.updateFamily)

        label = QtGui.QLabel(_('Font st&yle'))
        fontLayout.addWidget(label, 0, 2)
        label.setIndent(2)
        self.styleEdit = QtGui.QLineEdit()
        fontLayout.addWidget(self.styleEdit, 1, 2)
        self.styleEdit.setReadOnly(True)
        self.styleList = SmallListWidget()
        fontLayout.addWidget(self.styleList, 2, 2)
        label.setBuddy(self.styleList)
        self.styleEdit.setFocusProxy(self.styleList)
        fontLayout.setColumnMinimumWidth(3, spacing)
        self.connect(self.styleList,
                     QtCore.SIGNAL('currentItemChanged(QListWidgetItem*, '\
                                   'QListWidgetItem*)'), self.updateStyle)

        label = QtGui.QLabel(_('&Size'))
        fontLayout.addWidget(label, 0, 4)
        label.setIndent(2)
        self.sizeEdit = QtGui.QLineEdit()
        fontLayout.addWidget(self.sizeEdit, 1, 4)
        self.sizeEdit.setFocusPolicy(QtCore.Qt.ClickFocus)
        validator = QtGui.QIntValidator(1, 512, self)
        self.sizeEdit.setValidator(validator)
        self.sizeList = SmallListWidget()
        fontLayout.addWidget(self.sizeList, 2, 4)
        label.setBuddy(self.sizeList)
        self.connect(self.sizeList,
                     QtCore.SIGNAL('currentItemChanged(QListWidgetItem*, '\
                                   'QListWidgetItem*)'), self.updateSize)

        fontLayout.setColumnStretch(0, 38)
        fontLayout.setColumnStretch(2, 24)
        fontLayout.setColumnStretch(4, 10)

        sampleBox = QtGui.QGroupBox(_('Sample'))
        topLayout.addWidget(sampleBox)
        sampleLayout = QtGui.QVBoxLayout(sampleBox)
        self.sampleEdit = QtGui.QLineEdit()
        sampleLayout.addWidget(self.sampleEdit)
        self.sampleEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.sampleEdit.setText('AaBbCcDdEeFfGg...TtUuVvWvXxYyZz')
        self.sampleEdit.setFixedHeight(self.sampleEdit.sizeHint().height() * 2)

        self.setFontSelectAvail()