def __init__(self, parent=None): QWidget.__init__(self, parent) self.calc = CalcCore() self.setWindowTitle('rpCalc') modPath = os.path.abspath(sys.path[0]) if modPath.endswith('.zip') or modPath.endswith('.exe'): modPath = os.path.dirname(modPath) # for py2exe/cx_freeze iconPathList = [iconPath, os.path.join(modPath, 'icons/'), os.path.join(modPath, '../icons')] self.icons = icondict.IconDict() self.icons.addIconPath(filter(None, iconPathList)) self.icons.addIconPath([path for path in iconPathList if path]) try: QApplication.setWindowIcon(self.icons['calc_lg']) except KeyError: pass self.setFocusPolicy(Qt.StrongFocus) self.helpView = None self.extraView = None self.regView = None self.histView = None self.memView = None self.altBaseView = None self.optDlg = None self.popupMenu = QMenu(self) self.popupMenu.addAction('Registers on &LCD', self.toggleReg) self.popupMenu.addSeparator() self.popupMenu.addAction('Show &Register List', self.viewReg) self.popupMenu.addAction('Show &History List', self.viewHist) self.popupMenu.addAction('Show &Memory List', self.viewMem) self.popupMenu.addSeparator() self.popupMenu.addAction('Show Other &Bases', self.viewAltBases) self.popupMenu.addSeparator() self.popupMenu.addAction('Show Help &File', self.help) self.popupMenu.addAction('&About rpCalc', self.about) self.popupMenu.addSeparator() self.popupMenu.addAction('&Quit', self.close) topLay = QVBoxLayout(self) self.setLayout(topLay) topLay.setSpacing(4) topLay.setContentsMargins(6, 6, 6, 6) lcdBox = LcdBox() topLay.addWidget(lcdBox) lcdLay = QGridLayout(lcdBox) lcdLay.setColumnStretch(1, 1) lcdLay.setRowStretch(3, 1) self.extraLabels = [QLabel(' T:',), QLabel(' Z:',), QLabel(' Y:',)] for i in range(3): lcdLay.addWidget(self.extraLabels[i], i, 0, Qt.AlignLeft) self.extraLcds = [Lcd(1.5, 13), Lcd(1.5, 13), Lcd(1.5, 13)] lcdLay.addWidget(self.extraLcds[2], 0, 1, Qt.AlignRight) lcdLay.addWidget(self.extraLcds[1], 1, 1, Qt.AlignRight) lcdLay.addWidget(self.extraLcds[0], 2, 1, Qt.AlignRight) if not self.calc.option.boolData('ViewRegisters'): for w in self.extraLabels + self.extraLcds: w.hide() self.lcd = Lcd(2.0, 13) lcdLay.addWidget(self.lcd, 3, 0, 1, 2, Qt.AlignRight) self.setLcdHighlight() self.updateLcd() self.updateColors() self.cmdLay = QGridLayout() topLay.addLayout(self.cmdLay) self.cmdDict = {} self.addCmdButton('x^2', 0, 0) self.addCmdButton('sqRT', 0, 1) self.addCmdButton('y^X', 0, 2) self.addCmdButton('xRT', 0, 3) self.addCmdButton('RCIP', 0, 4) self.addCmdButton('SIN', 1, 0) self.addCmdButton('COS', 1, 1) self.addCmdButton('TAN', 1, 2) self.addCmdButton('LN', 1, 3) self.addCmdButton('e^X', 1, 4) self.addCmdButton('ASIN', 2, 0) self.addCmdButton('ACOS', 2, 1) self.addCmdButton('ATAN', 2, 2) self.addCmdButton('LOG', 2, 3) self.addCmdButton('tn^X', 2, 4) self.addCmdButton('STO', 3, 0) self.addCmdButton('RCL', 3, 1) self.addCmdButton('R<', 3, 2) self.addCmdButton('R>', 3, 3) self.addCmdButton('x<>y', 3, 4) self.addCmdButton('SHOW', 4, 0) self.addCmdButton('CLR', 4, 1) self.addCmdButton('PLCS', 4, 2) self.addCmdButton('SCI', 4, 3) self.addCmdButton('DEG', 4, 4) self.addCmdButton('EXIT', 5, 0) self.addCmdButton('Pi', 5, 1) self.addCmdButton('EXP', 5, 2) self.addCmdButton('CHS', 5, 3) self.addCmdButton('<-', 5, 4) self.mainLay = QGridLayout() topLay.addLayout(self.mainLay) self.mainDict = {} self.addMainButton(0, 'OPT', 0, 0) self.addMainButton(Qt.Key_Slash, '/', 0, 1) self.addMainButton(Qt.Key_Asterisk, '*', 0, 2) self.addMainButton(Qt.Key_Minus, '-', 0, 3) self.addMainButton(Qt.Key_7, '7', 1, 0) self.addMainButton(Qt.Key_8, '8', 1, 1) self.addMainButton(Qt.Key_9, '9', 1, 2) self.addMainButton(Qt.Key_Plus, '+', 1, 3, 1, 0) self.addMainButton(Qt.Key_4, '4', 2, 0) self.addMainButton(Qt.Key_5, '5', 2, 1) self.addMainButton(Qt.Key_6, '6', 2, 2) self.addMainButton(Qt.Key_1, '1', 3, 0) self.addMainButton(Qt.Key_2, '2', 3, 1) self.addMainButton(Qt.Key_3, '3', 3, 2) self.addMainButton(Qt.Key_Enter, 'ENT', 3, 3, 1, 0) self.addMainButton(Qt.Key_0, '0', 4, 0, 0, 1) self.addMainButton(Qt.Key_Period, '.', 4, 2) self.mainDict[Qt.Key_Return] = \ self.mainDict[Qt.Key_Enter] # added for european keyboards: self.mainDict[Qt.Key_Comma] = \ self.mainDict[Qt.Key_Period] self.cmdDict['ENT'] = self.mainDict[Qt.Key_Enter] self.cmdDict['OPT'] = self.mainDict[0] self.entryStr = '' self.showMode = False statusBox = QFrame() statusBox.setFrameStyle(QFrame.Panel | QFrame.Sunken) statusBox.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)) topLay.addWidget(statusBox) statusLay = QHBoxLayout(statusBox) self.entryLabel = QLabel(statusBox) statusLay.addWidget(self.entryLabel) statusLay.setContentsMargins(1, 1, 1, 1) self.statusLabel = QLabel(statusBox) self.statusLabel.setAlignment(Qt.AlignRight) statusLay.addWidget(self.statusLabel) if self.calc.option.boolData('ExtraViewStartup'): self.viewReg() if self.calc.option.boolData('AltBaseStartup'): self.viewAltBases() xSize = self.calc.option.intData('MainDlgXSize', 0, 10000) ySize = self.calc.option.intData('MainDlgYSize', 0, 10000) if xSize and ySize: self.resize(xSize, ySize) self.move(self.calc.option.intData('MainDlgXPos', 0, 10000), self.calc.option.intData('MainDlgYPos', 0, 10000)) self.updateEntryLabel('rpCalc Version {0}'.format(__version__)) QTimer.singleShot(5000, self.updateEntryLabel)