示例#1
0
 def display(self):
     key = self.index[self.cursor]  # show record at index cursor
     self.keytext.set(key)  # change key in main box
     record = self.table[key]  # in dict, dbm, shelf, class
     if self.sameKeys(record):
         self.currform.title('PyForm - Key=' + repr(key))
         for (field, text) in self.currslots:
             text.set(repr(record[field]))  # same fields? reuse form
     else:  # repr(x) works like 2.X `x`
         if self.currform:
             self.currform.destroy()  # different fields?
         new = Toplevel()  # replace current box
         new.title('PyForm - Key=' + repr(key))  # new resizable window
         new.iconname('pform')
         left = frame(new, LEFT)
         right = frame(new, RIGHT)
         self.currslots = []  # list of (field, entry)
         for field in record.keys():
             label(left, TOP, repr(field))  # key,value to strings
             text = StringVar()  # we could sort keys here
             text.set(repr(record[field]))
             entry(right, TOP, text, width=40)
             self.currslots.append((field, text))
         self.currform = new
         new.protocol('WM_DELETE_WINDOW', lambda: 0)  # ignore destroy's
     self.selectlist()  # update listbox
示例#2
0
 def makeMainBox(self):
     frm = frame(self, TOP)
     frm.config(bd=2)
     button(frm, LEFT, 'next', self.onNext)  # next in list
     button(frm, LEFT, 'prev', self.onPrev)  # backup in list
     button(frm, LEFT, 'find', self.onFind)  # find from key
     frm = frame(self, TOP)
     self.keytext = StringVar()  # current record's key
     label(frm, LEFT, 'KEY=>')  # change before 'find'
     entry(frm, LEFT, self.keytext)
     frm = frame(self, TOP)
     frm.config(bd=2)
     button(frm, LEFT, 'store', self.onStore)  # updated entry data
     button(frm, LEFT, 'new', self.onNew)  # clear fields
     button(frm, LEFT, 'index', self.onMakeList)  # show key list
     button(frm, LEFT, 'delete', self.onDelete)  # show key list
     button(self, BOTTOM, 'quit', self.quit)  # from guimixin
示例#3
0
 def makeWidgets(self, *args):
     label(self, TOP, 'PyCalc Plus - Subclass')
     CalcGui.makeWidgets(self, *args)
     frm = frame(self, BOTTOM)
     extras = [('sqrt', 'sqrt(%s)'),
               ('x^2 ', '(%s)**2'),
               ('x^3 ', '(%s)**3'),
               ('1/x ', '1.0/(%s)')]
     for (lab, expr) in extras:
         button(frm, LEFT, lab, (lambda expr=expr: self.onExtra(expr)))
     button(frm, LEFT, ' pi ', self.onPi)
示例#4
0
 def onMakeCmdline(self):
     new = Toplevel()  # new top-level window
     new.title('PyCalc command line')  # arbitrary Python code
     frm = frame(new, TOP)  # only the Entry expands
     label(frm, LEFT, '>>>').pack(expand=NO)
     var = StringVar()
     ent = entry(frm, LEFT, var, width=40)
     onButton = (lambda: self.onCmdline(var, ent))
     onReturn = (lambda event: self.onCmdline(var, ent))
     button(frm, RIGHT, 'Run', onButton).pack(expand=NO)
     ent.bind('<Return>', onReturn)
     var.set(self.text.get())
示例#5
0
 def __init__(self, **args):
     Toplevel.__init__(self)
     label(self, TOP, 'PyCalc Plus - Container')
     self.calc = CalcGui(self, **args)
     frm = frame(self, BOTTOM)
     extras = [('sqrt', 'sqrt(%s)'),
               ('x^2 ',  '(%s)**2'),
               ('x^3 ',  '(%s)**3'),
               ('1/x ',  '1.0/(%s)')]
     for (lab, expr) in extras:
         button(frm, LEFT, lab, (lambda expr=expr: self.onExtra(expr)))
     button(frm, LEFT, ' pi ', self.onPi)
示例#6
0
    def makeWidgets(self, fg, bg, font):  # 7 frames plus text-entry
        self.entry = entry(self, TOP, self.text)  # font, color configurable
        self.entry.config(font=font)  # 3.0: make display larger
        self.entry.config(justify=RIGHT)  # 3.0: on right, not left
        for row in self.Operands:
            frm = frame(self, TOP)
            for char in row:
                button(frm,
                       LEFT,
                       char,
                       lambda op=char: self.onOperand(op),
                       fg=fg,
                       bg=bg,
                       font=font)

        frm = frame(self, TOP)
        for char in self.Operators:
            button(frm,
                   LEFT,
                   char,
                   lambda op=char: self.onOperator(op),
                   fg=bg,
                   bg=fg,
                   font=font)

        frm = frame(self, TOP)
        button(frm, LEFT, 'dot ', lambda: self.onOperand('.'))
        button(frm, LEFT, ' E+ ',
               lambda: self.text.set(self.text.get() + 'E+'))
        button(frm, LEFT, ' E- ',
               lambda: self.text.set(self.text.get() + 'E-'))
        button(frm, LEFT, 'cmd ', self.onMakeCmdline)
        button(frm, LEFT, 'help', self.help)
        button(frm, LEFT, 'quit', self.quit)  # from guimixin

        frm = frame(self, BOTTOM)
        button(frm, LEFT, 'eval ', self.onEval)
        button(frm, LEFT, 'hist ', self.onHist)
        button(frm, LEFT, 'clear', self.onClear)
示例#7
0
 def makeToolBar(self):
     '''
     make button bar at bottom, if any
     expand=no, fill=x so same width on resize
     this could support images too
     '''
     if self.toolBar:
         toolbar = widgets.frame(self,
                                 cursor='hand2',
                                 relief=SUNKEN,
                                 bd=2,
                                 side=BOTTOM)
         for (name, action, where) in self.toolBar:
             b = Button(toolbar, text=name, command=action)
             b.config(bd=2)
             b.pack(side=where['side'], expand=NO, fill=X)
示例#8
0
    def makeMenuBar(self):
        '''
        make menu bar at the top
        expand=no fill=x so same width on resize
        '''
        menubar = widgets.frame(self, relief=SUNKEN, bd=2)

        for (name, key, items) in self.menuBar:
            mbutton = Menubutton(menubar, text=name, underline=key)
            mbutton.pack(side=LEFT)
            pulldown = Menu(mbutton)
            self.addMenuItems(pulldown, items)
            mbutton.config(menu=pulldown)

        if self.helpButton:
            widgets.button(menubar,
                           text='Help',
                           cursor='gumby',
                           relief=FLAT,
                           command=self.help,
                           side=RIGHT)
示例#9
0
    def onMakeList(self):
        if self.listbox: return  # already up?
        new = Toplevel()  # new resizable window
        new.title('PyForm - Key Index')  # select keys from a listbox
        new.iconname('pindex')

        frm = frame(new, TOP)
        scroll = Scrollbar(frm)
        list = Listbox(frm, bg='white')

        scroll.config(command=list.yview, relief=SUNKEN)
        list.config(yscrollcommand=scroll.set, relief=SUNKEN)
        scroll.pack(side=RIGHT, fill=BOTH)
        list.pack(side=LEFT, expand=YES, fill=BOTH)  # pack last, clip first

        for key in self.index:  # add to list-box
            list.insert(END, key)  # or: sort list first
        list.config(selectmode=SINGLE, setgrid=1)  # select,resize modes
        list.bind('<Double-1>', self.onList)  # on double-clicks
        self.listbox = list
        if self.index and self.cursor >= 0:  # highlight position
            self.selectlist()
        new.protocol('WM_DELETE_WINDOW', lambda: 0)  # ignore destroy's