text
stringlengths 1
93.6k
|
|---|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
#
|
import math
|
import sys
|
from PyQt5 import QtCore
|
from PyQt5.QtWidgets import (QApplication, QToolButton, QDialog, QGridLayout,
|
QLineEdit, QLayout, QSizePolicy)
|
def nyi():
|
print('Not yet implemented')
|
class Button(QToolButton):
|
def __init__(self, text, parent=None):
|
super(Button, self).__init__(parent)
|
self.setSizePolicy(QSizePolicy.Minimum,
|
QSizePolicy.Preferred)
|
self.setText(text)
|
def sizeHint(self):
|
size = super(Button, self).sizeHint()
|
size.setHeight(size.height())
|
size.setWidth(max(size.width(), size.height()))
|
return size
|
class Calculator(QDialog):
|
"""RPN calculator styled after the one in CoCreate SolidDesigner CAD."""
|
mem = ''
|
keip = False # Flag set when keyboard entry is in progress
|
needrup = False # Flag signaling need to rotate up with next keyboard entry
|
NumDigitButtons = 10
|
def __init__(self, parent=None):
|
super(Calculator, self).__init__(parent)
|
self.caller = parent
|
self.setWindowTitle("RPN Calculator")
|
self.x = 0
|
self.y = 0
|
self.z = 0
|
self.t = 0
|
self.xdisplay = self.display()
|
self.ydisplay = self.display()
|
self.zdisplay = self.display()
|
self.tdisplay = self.display()
|
myblue1 = 'steelblue'
|
myblue2 = 'darkslateblue' # hsv(240,200,160)
|
mygray = 'rgb(120,120,120)' # dimgray
|
mygreen = 'green'
|
myred = 'hsv(0,255,180)'
|
mygold = 'goldenrod'
|
self.mainLayout = QGridLayout()
|
self.mainLayout.setSpacing(0)
|
self.mainLayout.setSizeConstraint(QLayout.SetFixedSize)
|
# Grid is 36 columns across
|
self.butn('T', 0, 0, lambda state, r='t': self.pr(r), colspan=4)
|
self.butn('Z', 1, 0, lambda state, r='z': self.pr(r), colspan=4)
|
self.butn('Y', 2, 0, lambda state, r='y': self.pr(r), colspan=4)
|
self.butn('X', 3, 0, lambda state, r='x': self.pr(r), colspan=4)
|
self.mainLayout.addWidget(self.tdisplay, 0, 4, 1, 26)
|
self.mainLayout.addWidget(self.zdisplay, 1, 4, 1, 26)
|
self.mainLayout.addWidget(self.ydisplay, 2, 4, 1, 26)
|
self.mainLayout.addWidget(self.xdisplay, 3, 4, 1, 26)
|
self.butn('pi', 0, 30, self.pi, colspan=6)
|
self.butn('1/x', 1, 30, lambda state, op='1/x': self.func(op), colspan=6)
|
self.butn('2x', 2, 30, lambda state, op='x*2': self.func(op), colspan=6)
|
self.butn('x/2', 3, 30, lambda state, op='x/2': self.func(op), colspan=6)
|
self.butn('mm -> in', 4, 0, self.mm2in, colspan=12)
|
self.butn('in -> mm', 4, 12, self.in2mm, colspan=12)
|
self.butn('STO', 4, 24, self.storex, clr=mygreen, colspan=6)
|
self.butn('RCL', 4, 30, self.recallx, clr=mygreen, colspan=6)
|
self.butn('7', 5, 0, lambda state, c='7': self.keyin(c), clr=myblue1)
|
self.butn('8', 5, 6, lambda state, c='8': self.keyin(c), clr=myblue1)
|
self.butn('9', 5, 12, lambda state, c='9': self.keyin(c), clr=myblue1)
|
self.butn('+', 5, 18, lambda state, op='+': self.calculate(op), clr=myblue2)
|
self.butn('R up', 5, 24, self.rotateup, clr=mygreen, colspan=6)
|
self.butn('R dn', 5, 30, self.rotatedn, clr=mygreen, colspan=6)
|
self.butn('4', 6, 0, lambda state, c='4': self.keyin(c), clr=myblue1)
|
self.butn('5', 6, 6, lambda state, c='5': self.keyin(c), clr=myblue1)
|
self.butn('6', 6, 12, lambda state, c='6': self.keyin(c), clr=myblue1)
|
self.butn('-', 6, 18, lambda state, op='-': self.calculate(op), clr=myblue2)
|
self.butn('<-', 6, 24, self.trimx, clr=myred, colspan=4)
|
self.butn('X<>Y', 6, 28, self.swapxy, clr=mygreen, colspan=8)
|
self.butn('1', 7, 0, lambda state, c='1': self.keyin(c), clr=myblue1)
|
self.butn('2', 7, 6, lambda state, c='2': self.keyin(c), clr=myblue1)
|
self.butn('3', 7, 12, lambda state, c='3': self.keyin(c), clr=myblue1)
|
self.butn('*', 7, 18, lambda state, op='*': self.calculate(op), clr=myblue2)
|
self.butn('CL X', 7, 24, self.clearx, clr=myred)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.