Exemplo n.º 1
0
  def body(self, guiParent):

    # Ensure that the first row and column in popup expand
    guiParent.grid_rowconfigure(1, weight=1)
    guiParent.grid_columnconfigure(0, weight=1, minsize=200)
    frame = Frame(guiParent) # Body widgets can be put in this frame
    frame.grid(row=1, column=0, sticky='nsew')
    
    frame.grid_rowconfigure(0, weight=1)
    frame.grid_columnconfigure(0, weight=1, minsize=200)

    self.dangleFrame = DangleFrame(frame, self, project=self.project)
    self.dangleFrame.grid(row=0, column=0, sticky='nsew')

    # Dictionary to store popups opened by this application - e.g. need to close upon quit
    self.popups = {}
    
    # Default font
    self.font   = 'Helvetica 10'

    # Closing the window from the desktop environment calls the proper quit
    self.protocol('WM_DELETE_WINDOW', self.quit)

    self.mainMenu    = Menu(self)
    self.projectMenu = self.makeProjectMenu()
    self.viewMenu    = self.viewFileMenu()
    self.otherMenu   = self.makeAppearanceMenu()
    
    # Put the main menu 
    self.config(menu=self.mainMenu)

    self.initProject()
Exemplo n.º 2
0
class Separator(Frame):
  
  refresh  = 0

  def __init__(self, parent, orient = Tkinter.HORIZONTAL, relief='solid', color='black',
               bgColor = 'grey', *args, **kw):

    if (orient == Tkinter.HORIZONTAL):
      size = kw.get('height', 1)
    else:
      size = kw.get('width', 1)
      
    if relief =='solid':
      kw['relief'] = 'flat'
    else:
      kw['relief'] = relief
    
    
    kw['borderwidth'] = (size-1)/2
    
    apply(Frame.__init__, (self, parent) + args, kw)

    self.config(bg=color)
    self.relief = relief

    if self.relief in ('solid','flat'):
      color2 = bgColor
    else:
      color2 = color
 
    self.grid_columnconfigure(0, weight=1)
    self.grid_rowconfigure(0, weight=1)
    self.innerFrame = Frame(self, borderwidth=0, bg=color2)
    self.innerFrame.grid(sticky = Tkinter.NSEW)     
    self.innerFrame.grid_columnconfigure(0, weight=1)
    self.innerFrame.grid_rowconfigure(0, weight=1)
 
  # color is a tuple
  def setColor(self, color, bgColor='grey'):

    if type(color) is type(()) :
      (r,g,b) = color
      color   = hexRepr(r,g,b)
      
    if type(bgColor) is type(()) :
      (r,g,b) = bgColor
      bgColor = hexRepr(r,g,b)
    
    self.config(bg = color)
    
    if self.relief in ('solid','flat'):
      self.innerFrame.config(bg = bgColor)
    else:
      self.innerFrame.config(bg = color)
Exemplo n.º 3
0
class ScrolledFrame(Frame):
    def __init__(self,
                 parent,
                 xscroll=True,
                 yscroll=True,
                 width=500,
                 height=500,
                 doExtraConfig=True,
                 tipText=None,
                 *args,
                 **kw):

        Frame.__init__(self, parent, *args, **kw)

        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)

        self.doExtraConfig = doExtraConfig
        self.xscroll = xscroll
        self.yscroll = yscroll

        self.canvas = Tkinter.Canvas(self,
                                     borderwidth=0,
                                     bg=self.cget('bg'),
                                     highlightthickness=0,
                                     width=25,
                                     height=25)
        self.canvas.grid(row=0, column=0, sticky=Tkinter.NSEW)

        if (xscroll):
            self.xscrollbar = Tkinter.Scrollbar(self,
                                                orient=Tkinter.HORIZONTAL,
                                                borderwidth=1)
            self.xscrollbar.config(command=self.canvas.xview)
            self.canvas.config(xscrollcommand=self.xscrollbar.set)

        if (yscroll):
            self.yscrollbar = Tkinter.Scrollbar(self,
                                                orient=Tkinter.VERTICAL,
                                                borderwidth=1)
            self.yscrollbar.config(command=self.canvas.yview)
            self.canvas.config(yscrollcommand=self.yscrollbar.set)

        # reset the view (always do this if you don't use scrollbars)
        self.canvas.xview('moveto', 0)
        self.canvas.yview('moveto', 0)

        # create the frame
        self.frame = Frame(self.canvas, tipText=tipText)
        self.frame.grid(row=0, column=0, sticky=Tkinter.NSEW)
        self.frame.grid_rowconfigure(0, weight=1)
        self.frame.grid_columnconfigure(0, weight=1)
        self.waiting = 0

        # track changes to its size
        self.bind('<Configure>', self.configureCanvasAfter)

        # track changes to its contents
        self.frame.bind('<Configure>', self.configureFrame)

        # place the frame inside the canvas (this also
        # runs the __configure method)
        self.canvas.create_window(0, 0, window=self.frame, anchor='nw')
        #self.frameWidth  = self.frame.winfo_reqwidth()
        #self.frameHeight = self.frame.winfo_reqheight()
        self.frameWidth = 0
        self.frameHeight = 0

    def configureFrame(self, event):

        # frame contents have changed size, but make no change to displayed canvas size
        if (event.width != self.frameWidth) or (event.height !=
                                                self.frameHeight):

            # the size of the frame with widgets in the 'background'
            self.frameWidth = event.width
            self.frameHeight = event.height

            # the scrolled region is always the entire frame
            self.canvas.config(scrollregion="0 0 %s %s" %
                               (self.frameWidth, self.frameHeight))

            self.configureCanvasAfter()

    def configureCanvasAfter(self, event=None):

        if self.waiting:
            return

        else:
            self.waiting = 1
            self.after_idle(lambda: self.configureCanvas(event))

    def configureCanvas(self, event=None):

        d = 2 * int(self.cget('borderwidth'))
        if (event):
            # the canvas visible display size updates with the rezize event unless the axis is not scrolled
            canvasWidth = event.width - d
            canvasHeight = event.height - d

        else:
            # if no resize event the canvas size is unaltered
            canvasWidth = int(self.winfo_width()) - d
            canvasHeight = int(self.winfo_height()) - d

        if self.xscroll:
            if (self.frameWidth > 1):
                if (self.frameWidth > canvasWidth):
                    self.xscrollbar.grid(row=1, column=0, sticky=Tkinter.EW)
                else:
                    self.xscrollbar.grid_forget()
            else:
                self.xscrollbar.grid(row=1, column=0, sticky=Tkinter.EW)
        else:
            # display full width
            canvasWidth = self.frameWidth

        if self.yscroll:
            if (self.frameHeight > 1):
                if (self.frameHeight > canvasHeight):
                    self.yscrollbar.grid(row=0, column=1, sticky=Tkinter.NS)
                else:
                    self.yscrollbar.grid_forget()
            else:
                self.yscrollbar.grid(row=0, column=1, sticky=Tkinter.NS)
        else:
            # display full height
            canvasHeight = self.frameHeight

        if (self.doExtraConfig):
            # sometimes below seems to be needed and sometimes not
            # seems to depend on what else is there in widget besides scrolled frame
            # can sometimes wildly iterate if below is done
            self.canvas.config(width=canvasWidth, height=canvasHeight)
        self.waiting = 0
Exemplo n.º 4
0
class MultiWidget(Frame):
    def __init__(self,
                 parent,
                 widgetClass,
                 options=None,
                 values=None,
                 callback=None,
                 minRows=3,
                 maxRows=None,
                 useImages=True,
                 *args,
                 **kw):

        Frame.__init__(self, parent, **kw)

        if not values:
            values = []
        if not options:
            options = []

        # Widget types currently: Entries, Pulldown, Checkbutton

        if useImages:
            gfxDir = path.join(getTopDirectory(), 'python', 'memops', 'gui',
                               'graphics')
            self.crossImage = Tkinter.PhotoImage(
                file=path.join(gfxDir, 'cross.gif'))
            self.tickImage = Tkinter.PhotoImage(
                file=path.join(gfxDir, 'tick.gif'))
            self.plusImage = Tkinter.PhotoImage(
                file=path.join(gfxDir, 'plus.gif'))
            self.minusImage = Tkinter.PhotoImage(
                file=path.join(gfxDir, 'minus.gif'))
        else:
            self.crossImage = None
            self.tickImage = None
            self.plusImage = None
            self.minusImage = None

        module = widgetClass.__module__
        self.widgetType = module.split('.')[-1]
        self.widgetClass = widgetClass
        self.callback = callback

        self.numRows = 0
        self.values = values
        self.options = options
        self.minRows = minRows
        self.maxRows = maxRows
        self.widgets = []
        self.labels = []
        self.grid_columnconfigure(1, weight=1)

        self.topFrame = Frame(self)
        self.topFrame.grid(row=0, column=0, columnspan=4, sticky=Tkinter.NSEW)
        self.topFrame.grid_columnconfigure(1, weight=1)
        self.topFrame.grid_rowconfigure(0, weight=1)

        self.addButton = None
        self.removeButton = None
        self.commitButton = None
        self.cancelButton = None

        self.set(self.values, self.options)

        self.updateButtons()

        self.bind('<KeyPress-Return>', self.commit)
        self.bind('<KeyPress-Escape>', self.cancel)

    def get(self):

        values = []

        if self.widgetType == 'PulldownMenu':
            for i in range(self.numRows):
                value = self.widgets[i].getSelected()
                if value is not None:
                    values.append(value)

        elif self.widgetType == 'PulldownList':
            for i in range(self.numRows):
                value = self.widgets[i].getObject()
                if value is not None:
                    values.append(value)

        else:
            for i in range(self.numRows):
                value = self.widgets[i].get()
                if (value is not None) and (value != ''):
                    values.append(value)

        return values

    def set(self, values=None, options=None):

        if values is not None:
            self.values = values
        if options is not None:
            self.options = options

        N = max(len(self.values), self.minRows)
        if self.maxRows is not None:
            N = min(N, self.maxRows)

        #N = max( min(len(self.values), self.maxRows), self.minRows)
        #N = len(self.values)
        if self.numRows < N:
            for i in range(self.numRows, N):
                self.addRow()

        elif self.numRows > N:
            for i in range(N, self.numRows):
                self.removeRow(doClear=1)

        for i in range(self.numRows):
            if i < len(self.values):
                value = self.values[i]
            else:
                value = None

            if i < len(self.options):
                option = self.options[i]
            else:
                option = None

            self.updateWidget(i, value, option)

    def setOptions(self, options):

        self.set(self.values, options)

    def setValues(self, values):

        self.set(values, self.options)

    def updateWidget(self, row, value, option):

        if self.labels:
            font = self.labels[0].cget('font')
        else:
            font = None

        widget = self.widgets[row]
        if self.widgetType in ('Entry', 'IntEntry', 'FloatEntry'):
            widget.set(value)
            label = self.labels[row]
            label.set(option or '')
            if font:
                label.config(font=font)

        elif self.widgetType == 'PulldownMenu':
            index = -1
            if value in self.options:
                index = self.options.index(value or self.options[0])
            widget.setup(self.options, index)

        elif self.widgetType == 'PulldownList':
            index = 0
            if value in self.options:
                index = self.options.index(value or self.options[0])
            widget.setup(self.options, self.options, index)

        elif self.widgetType == 'CheckButton':
            widget.set(value)
            label = self.labels[row]
            label.set(option or '')
            if font:
                label.config(font=font)

        else:
            raise 'Widget type %s not supported in MultiWidget' % self.widgetType

    def updateButtons(self):

        row = 1
        col = 0
        if self.widgetType != 'CheckButton':
            if (self.maxRows is None) or (self.numRows < self.maxRows):
                if not self.addButton:
                    if self.plusImage:
                        self.addButton = Button(self,
                                                image=self.plusImage,
                                                command=self.addRow,
                                                borderwidth=1)
                    else:
                        self.addButton = Button(self,
                                                text='+',
                                                command=self.addRow,
                                                borderwidth=1,
                                                bg=blueColor)

                self.addButton.grid(row=row, column=col, sticky=Tkinter.EW)
                col += 1

            elif self.addButton:
                self.addButton.grid_forget()

            if self.numRows > self.minRows:
                if not self.removeButton:
                    if self.minusImage:
                        self.removeButton = Button(self,
                                                   image=self.minusImage,
                                                   command=self.removeRow,
                                                   borderwidth=1)
                    else:
                        self.removeButton = Button(self,
                                                   text='-',
                                                   command=self.removeRow,
                                                   borderwidth=1,
                                                   bg=blueColor)
                self.removeButton.grid(row=row, column=col, sticky=Tkinter.EW)
                col += 1

            elif self.removeButton:
                self.removeButton.grid_forget()

        if self.callback:
            if not self.commitButton:
                if self.tickImage:
                    self.commitButton = Button(self,
                                               image=self.tickImage,
                                               command=self.commit,
                                               borderwidth=1)
                else:
                    self.commitButton = Button(self,
                                               text='OK',
                                               command=self.commit,
                                               borderwidth=1,
                                               bg=blueColor)

            self.commitButton.grid(row=row, column=col, sticky=Tkinter.EW)
            self.grid_columnconfigure(col, weight=1)
            col += 1

            if not self.cancelButton:
                if self.crossImage:
                    self.cancelButton = Button(self,
                                               image=self.crossImage,
                                               command=self.cancel,
                                               borderwidth=1)
                else:
                    self.cancelButton = Button(self,
                                               text='Cancel',
                                               command=self.cancel,
                                               borderwidth=1,
                                               bg=blueColor)

            self.cancelButton.grid(row=row, column=col, sticky=Tkinter.EW)
            self.grid_columnconfigure(col, weight=1)

    def addWidget(self, row, value=None):

        if self.widgetType in ('Entry', 'IntEntry', 'FloatEntry'):
            option = ''
            if row < len(self.options):
                option = self.options[row]

            label = Label(self.topFrame, text=option or '', anchor='w')
            label.grid(row=row, column=0, sticky=Tkinter.E)
            self.labels.append(label)

            widget = self.widgetClass(self.topFrame, text=value, width=12)
            widget.grid(row=row, column=1, sticky=Tkinter.EW)

            widget.bind('<KeyPress-Return>', self.commit)
            widget.bind('<KeyPress-Escape>', self.cancel)

        elif self.widgetType == 'PulldownList':
            index = -1
            if value in self.options:
                index = self.options.index(value or self.options[0])
            widget = self.widgetClass(self.topFrame)
            widget.setup(self.options, self.options, index)
            widget.grid(row=row, column=0, columnspan=2, sticky=Tkinter.W)

        elif self.widgetType == 'PulldownMenu':
            index = -1
            if value in self.options:
                index = self.options.index(value or self.options[0])
            widget = self.widgetClass(self.topFrame)
            widget.setup(self.options, index)
            widget.grid(row=row, column=0, columnspan=2, sticky=Tkinter.W)

        elif self.widgetType == 'CheckButton':
            widget = self.widgetClass(self.topFrame)
            widget.set(value)
            widget.grid(row=row, column=0, sticky=Tkinter.W)

            option = ''
            if row < len(self.options):
                option = self.options[row]

            label = Label(self.topFrame, text=option or '', anchor='w')
            label.grid(row=row, column=1, sticky=Tkinter.W)
            self.labels.append(label)

        else:
            raise 'Widget type %s not supported in MultiWidget' % self.widgetType

        return widget

    def commit(self, event=None):

        values = self.get()

        if self.callback:
            self.callback(values)

    def cancel(self, event=None):

        if self.callback:
            self.callback(None)

    def addRow(self):

        if (self.maxRows is None) or (self.numRows < self.maxRows):
            row = self.numRows
            self.numRows += 1

            if self.numRows > len(self.widgets):
                widget = self.addWidget(row)
                self.widgets.append(widget)

            else:
                widget = self.widgets[row]
                if self.widgetType in ('Entry', 'IntEntry', 'FloatEntry'):
                    label = self.labels[row]
                    label.grid(row=row, column=0, sticky=Tkinter.E)
                    widget.grid(row=row, column=1, sticky=Tkinter.EW)

                elif self.widgetType == 'CheckButton':
                    widget.grid(row=row, column=0, sticky=Tkinter.W)
                    label = self.labels[row]
                    label.grid(row=row, column=1, sticky=Tkinter.W)

                else:
                    widget.grid(row=row,
                                column=0,
                                columnspan=2,
                                sticky=Tkinter.W)

            if row == 0:
                self.topFrame.grid(row=0,
                                   column=0,
                                   columnspan=4,
                                   sticky=Tkinter.NSEW)

            self.updateButtons()

    def removeRow(self, doClear=0):

        if self.numRows > self.minRows:
            self.numRows -= 1
            row = self.numRows
            widget = self.widgets[row]
            widget.grid_forget()

            if self.widgetType == 'CheckButton':
                label = self.labels[row]
                label.grid_forget()

            elif self.widgetType in ('Entry', 'IntEntry', 'FloatEntry'):
                label = self.labels[row]
                label.grid_forget()

            if doClear:
                self.updateWidget(row, None, '')

            if self.numRows == 0:
                self.topFrame.grid_forget()

            self.updateButtons()
Exemplo n.º 5
0
class PopupTemplate(BasePopup):

  def __init__(self, parent, project=None, *args, **kw):

    self.project = project
    self.parent  = parent
    self.objects = self.getObjects()
    self.object  = None
    
    BasePopup.__init__(self, parent=parent, title='Popup Template', **kw)
                       
    self.updateObjects()

  def body(self, mainFrame):

    mainFrame.grid_columnconfigure(1, weight=1, minsize=100)
    mainFrame.config(borderwidth=5, relief='solid')

    row = 0
    label = Label(mainFrame, text="Frame (with sub-widgets):")
    label.grid(row=row, column=0, sticky=Tkinter.E)

    frame = Frame(mainFrame, relief='raised', border=2, background='#8080D0')
    # Frame expands East-West
    frame.grid(row=row, column=1, sticky=Tkinter.EW)
    # Last column expands => Widgets pusted to the West
    frame.grid_columnconfigure(3, weight=1)
    
    # Label is within the sub frame
    label = Label(frame, text='label ')
    label.grid(row=0, column=0, sticky=Tkinter.W)
    
    entry = Entry(frame, text='Entry', returnCallback=self.showWarning)
    entry.grid(row=0, column=1, sticky=Tkinter.W)
    
    self.check = CheckButton(frame, text='Checkbutton', selected=True, callback=self.updateObjects)
    self.check.grid(row=0, column=2, sticky=Tkinter.W)
    
    # stick a button to the East wall
    button = Button(frame, text='Button', command=self.pressButton)
    button.grid(row=0, column=3, sticky=Tkinter.E)
  
    row += 1
    label = Label(mainFrame, text="Text:")
    label.grid(row=row, column=0, sticky=Tkinter.E)
    self.textWindow = Text(mainFrame, text='Initial Text\n', width=60, height=5)
    self.textWindow.grid(row=row, column=1, sticky=Tkinter.NSEW)
    
    row += 1
    label = Label(mainFrame, text="CheckButtons:")
    label.grid(row=row, column=0, sticky=Tkinter.E)

    entries = ['Alpha','Beta','Gamma','Delta']
    selected = entries[2:]
    self.checkButtons = CheckButtons(mainFrame, entries, selected=selected,select_callback=self.changedCheckButtons)
    self.checkButtons.grid(row=row, column=1, sticky=Tkinter.W)
  
    row += 1
    label = Label(mainFrame, text="PartitionedSelector:")
    label.grid(row=row, column=0, sticky=Tkinter.E)

    labels   = ['Bool','Int','Float','String']
    objects  = [type(0),type(1),type(1.0),type('a')]
    selected = [type('a')]
    self.partitionedSelector= PartitionedSelector(mainFrame, labels=labels,
                                                  objects=objects,
                                                  colors = ['red','yellow','green','#000080'],
                                                  callback=self.toggleSelector,selected=selected)
    self.partitionedSelector.grid(row=row, column=1, sticky=Tkinter.EW)

    row += 1
    label = Label(mainFrame, text="PulldownMenu")
    label.grid(row=row, column=0, sticky=Tkinter.E)
    
    entries = ['Frodo','Pipin','Merry','Sam','Bill','Gandalf','Strider','Gimli','Legolas']
    self.pulldownMenu = PulldownMenu(mainFrame, callback=self.selectPulldown,
                                     entries=entries, selected_index=2,
                                     do_initial_callback=False)
    self.pulldownMenu.grid(row=row, column=1, sticky=Tkinter.W)

    row += 1
    label = Label(mainFrame, text="RadioButtons in a\nScrolledFrame.frame:")
    label.grid(row=row, column=0, sticky=Tkinter.EW)
    
    frame = ScrolledFrame(mainFrame, yscroll = False, doExtraConfig = True, width=100)
    frame.grid(row=row, column=1, sticky=Tkinter.EW)
    frame.grid_columnconfigure(0, weight=1)

    self.radioButtons = RadioButtons(frame.frame, entries=entries,
                                     select_callback=self.checkRadioButtons,
                                     selected_index=1, relief='groove')
    self.radioButtons.grid(row=0, column=0, sticky=Tkinter.W)
    
    row += 1
    label = Label(mainFrame, text="LabelFrame with\nToggleLabels inside:")
    label.grid(row=row, column=0, sticky=Tkinter.E)

    labelFrame = LabelFrame(mainFrame, text='Frame Title')
    labelFrame.grid(row=row, column=1, sticky=Tkinter.NSEW)
    labelFrame.grid_rowconfigure(0, weight=1)
    labelFrame.grid_columnconfigure(3, weight=1)
    
        
    self.toggleLabel1 = ToggleLabel(labelFrame, text='ScrolledMatrix', callback=self.toggleFrame1)
    self.toggleLabel1.grid(row=0, column=0, sticky=Tkinter.W)
    self.toggleLabel1.arrowOn()

    self.toggleLabel2 = ToggleLabel(labelFrame, text='ScrolledGraph', callback=self.toggleFrame2)
    self.toggleLabel2.grid(row=0, column=1, sticky=Tkinter.W)

    self.toggleLabel3 = ToggleLabel(labelFrame, text='ScrolledCanvas', callback=self.toggleFrame3)
    self.toggleLabel3.grid(row=0, column=2, sticky=Tkinter.W)
    
    row += 1
    mainFrame.grid_rowconfigure(row, weight=1)

    label = Label(mainFrame, text="changing/shrinking frames:")
    label.grid(row=row, column=0, sticky=Tkinter.E)
    
    self.toggleRow = row
    self.toggleFrame = Frame(mainFrame)
    self.toggleFrame.grid(row=row, column=1, sticky=Tkinter.NSEW)
    self.toggleFrame.grid_rowconfigure(0, weight=1)
    self.toggleFrame.grid_columnconfigure(0, weight=1)
    
    # option 1
    
    self.intEntry = IntEntry(self, returnCallback = self.setNumber, width=8)
    
    self.multiWidget = MultiWidget(self, Entry, options=None, 
                                  values=None, callback=self.setKeywords,
                                  minRows=3, maxRows=5)

    editWidgets      = [None, None, self.intEntry,  self.multiWidget]
    editGetCallbacks = [None, None, self.getNumber, self.getKeywords]
    editSetCallbacks = [None, None, self.setNumber, self.setKeywords]
    
    headingList = ['Name','Color','Number','Keywords']
    self.scrolledMatrix = ScrolledMatrix(self.toggleFrame, headingList=headingList,
                                         editSetCallbacks=editSetCallbacks,
                                         editGetCallbacks=editGetCallbacks,
                                         editWidgets=editWidgets,
                                         callback=self.selectObject,
                                         multiSelect=False) 
                                         
    self.scrolledMatrix.grid(row=0, column=0, sticky=Tkinter.NSEW)

    # option 2
    self.scrolledGraph = ScrolledGraph(self.toggleFrame, width=400,
                                       height=300, symbolSize=5,
                                       symbols=['square','circle'],
                                       dataColors=['#000080','#800000'],
                                       lineWidths=[0,1] )

    self.scrolledGraph.setZoom(1.3)

    dataSet1 = [[0,0],[1,1],[2,4],[3,9],[4,16],[5,25]]
    dataSet2 = [[0,0],[1,3],[2,6],[3,9],[4,12],[5,15]]
    self.scrolledGraph.update(dataSets=[dataSet1,dataSet2],
                              xLabel = 'X axis label',
                              yLabel = 'Y axis label',
                              title  = 'Main Title')
    self.scrolledGraph.draw()

    # option 3
    self.scrolledCanvas = ScrolledCanvas(self.toggleFrame,relief = 'groove', borderwidth = 2, resizeCallback=None)
    canvas = self.scrolledCanvas.canvas
    font   = 'Helvetica 10'
    box    = canvas.create_rectangle(10,10,150,200, outline='grey', fill='grey90')
    line   = canvas.create_line(0,0,200,200,fill='#800000', width=2)
    text   = canvas.create_text(120,50, text='Text', font=font, fill='black')
    circle = canvas.create_oval(30,30,50,50,outline='#008000',fill='#404040',width=3)
     
    row += 1
    label = Label(mainFrame, text="FloatEntry:")
    label.grid(row=row, column=0, sticky=Tkinter.E)
    self.floatEntry = FloatEntry(mainFrame, text=3.14159265, returnCallback=self.floatEntryReturn)
    self.floatEntry.grid(row=row, column=1, sticky=Tkinter.W)
    
     
    row += 1
    label = Label(mainFrame, text="Scale:")
    label.grid(row=row, column=0, sticky=Tkinter.E)
    self.scale = Scale(mainFrame, from_=10, to=90, value=50, orient=Tkinter.HORIZONTAL)
    self.scale.grid(row=row, column=1, sticky=Tkinter.W)

    row += 1
    label = Label(mainFrame, text="Value Ramp:")
    label.grid(row=row, column=0, sticky=Tkinter.E)
    self.valueRamp = ValueRamp(mainFrame, self.valueRampCallback, speed = 1.5, delay = 50)
    self.valueRamp.grid(row=row, column=1, sticky=Tkinter.W)
  

    row += 1
    label = Label(mainFrame, text="ButtonList:")
    label.grid(row=row, column=0, sticky=Tkinter.E)
    
    texts    = ['Select File','Close','Quit']
    commands = [self.selectFile, self.close, self.quit]
    bottomButtons = ButtonList(mainFrame, texts=texts, commands=commands, expands=True) 
    bottomButtons.grid(row=row, column=1, sticky=Tkinter.EW)
  
    self.protocol('WM_DELETE_WINDOW', self.quit)

  def floatEntryReturn(self, event):
  
    value = self.floatEntry.get()
    self.textWindow.setText('%s\n' % value)

  def selectObject(self, object, row, col):
  
    self.object = object

  def getKeywords(self, object):
  
    if object :
      values = object.keywords
      self.multiWidget.set(values)
  
  def setKeywords(self, event):
  
    values = self.multiWidget.get()
    self.object.keywords = values
    self.updateObjects()

  def getNumber(self, object):

    if object :
      self.intEntry.set(object.quantity)

  def setNumber(self, event):

    value = self.intEntry.get()
    self.object.quantity = value
    self.updateObjects()

  def toggleFrame1(self, isHidden):
 
    if isHidden:
      self.scrolledMatrix.grid_forget()
      self.toggleFrame.grid_forget()
    else:
      self.scrolledGraph.grid_forget()
      self.scrolledCanvas.grid_forget()
      self.scrolledMatrix.grid(row=0, column=0, sticky=Tkinter.NSEW)
      self.toggleFrame.grid(row=self.toggleRow, column=1,sticky=Tkinter.NSEW)
      self.toggleLabel2.arrowOff()
      self.toggleLabel3.arrowOff()


  def toggleFrame2(self, isHidden):
 
    if isHidden:
      self.scrolledGraph.grid_forget()
      self.toggleFrame.grid_forget()
    else:
      self.scrolledMatrix.grid_forget()
      self.scrolledCanvas.grid_forget()
      self.scrolledGraph.grid(row=0, column=0, sticky=Tkinter.NSEW)
      self.toggleFrame.grid(row=self.toggleRow, column=1,sticky=Tkinter.NSEW)
      self.toggleLabel1.arrowOff()
      self.toggleLabel3.arrowOff()

  def toggleFrame3(self, isHidden):
 
    if isHidden:
      self.scrolledCanvas.grid_forget()
      self.toggleFrame.grid_forget()
    else:
      self.scrolledMatrix.grid_forget()
      self.scrolledGraph.grid_forget()
      self.scrolledCanvas.grid(row=0, column=0, sticky=Tkinter.NSEW)
      self.toggleFrame.grid(row=self.toggleRow, column=1,sticky=Tkinter.NSEW)
      self.toggleLabel1.arrowOff()
      self.toggleLabel2.arrowOff()

 
  def valueRampCallback(self, value):
  
    self.textWindow.setText('%s\n' % value)

  def checkRadioButtons(self, value):
  
    self.textWindow.setText('%s\n' % value)

  def selectPulldown(self, index, name):
  
    self.textWindow.setText('%d, %s\n' % (index, name))

  def toggleSelector(self, value):
  
    self.textWindow.setText('%s\n' % value)

  def changedCheckButtons(self, values):
  
    self.textWindow.setText(','.join(values) + '\n')

  def getObjects(self):
  
    objects = []
    
    objects.append( Fruit('Lemon',   '#FFFF00',1,keywords=['Bitter','Tangy'] ) )
    objects.append( Fruit('Orange',  '#FF8000',4 ) )
    objects.append( Fruit('Banana',  '#FFF000',5 ) )
    objects.append( Fruit('Pinapple','#FFD000',9 ) )
    objects.append( Fruit('Kiwi',    '#008000',12) )
    objects.append( Fruit('Lime',    '#00FF00',2 ) )
    objects.append( Fruit('Apple',   '#800000',5,keywords=['Crunchy'] ) )
    objects.append( Fruit('Pear',    '#408000',6 ) )
    objects.append( Fruit('Peach',   '#FFE0C0',2,keywords=['Sweet','Furry'] ) )
    objects.append( Fruit('Plumb',   '#800080',7 ) )
    
    return objects

  def updateObjects(self, event=None):

    textMatrix = []
    objectList = []
    colorMatrix = []
    
    for object in self.objects:
      datum = []
      datum.append( object.name )
      datum.append( None )
      datum.append( object.quantity )
      datum.append( ','.join(object.keywords) )
    
      colors = [None, object.color, None, None]
    
      textMatrix.append(datum)
      objectList.append(object)
      colorMatrix.append(colors)

    if self.check.get():
      self.scrolledMatrix.update(textMatrix=textMatrix, objectList=objectList)
    else:
      self.scrolledMatrix.update(textMatrix=textMatrix, objectList=objectList, colorMatrix=colorMatrix)

  def selectFile(self):

    fileSelectPopup = FileSelectPopup(self, title = 'Choose file', dismiss_text = 'Cancel',
                                      selected_file_must_exist = True)

    fileName = fileSelectPopup.getFile()

    self.textWindow.setText('File Selected: %s\n' % fileName)

  def showWarning(self, eventObject):
  
    self.textWindow.setText('Text Entry Return Pressed\n')
    showWarning('Warning Title','Warning Message')
    return

  def pressButton(self):
  
    self.textWindow.setText('Button Pressed\n')
    if showYesNo('Title','Prompt: Clear text window?'):
       self.textWindow.clear()
       
    return

  def quit(self):
  
    BasePopup.destroy(self)  
Exemplo n.º 6
0
    def body(self):

        frame = self.frame

        self.resultsResidueNumber = 1

        frame.expandGrid(5, 0)

        resultTopFrame = LabelFrame(frame, text='Which results to show')
        resultTopFrame.grid(row=0, column=0, sticky='ew')

        self.resultsResidueNumber = 3

        texts = [' < ']
        commands = [self.resultsPrevResidue]
        self.resultsPreviousButton = ButtonList(resultTopFrame,
                                                commands=commands,
                                                texts=texts)
        self.resultsPreviousButton.grid(row=0, column=1, sticky='nsew')

        tipText = 'The Number of the residue in the sequence to display results for'
        self.resultsResidueNumberEntry = IntEntry(
            resultTopFrame,
            grid=(0, 2),
            width=7,
            text=3,
            returnCallback=self.resultsUpdateAfterEntry,
            tipText=tipText)
        #self.resultsResidueNumberEntry.bind('<Leave>', self.resultsUpdateAfterEntry, '+')

        texts = [' > ']
        commands = [self.resultsNextResidue]
        self.resultsNextButton = ButtonList(resultTopFrame,
                                            commands=commands,
                                            texts=texts)
        self.resultsNextButton.grid(row=0, column=3, sticky='nsew')

        selectCcpCodes = ['residue'] + AMINO_ACIDS
        self.resultsSelectedCcpCode = 'residue'

        tipText = 'Instead of going through the sequence residue by residue, jump directly to next amino acid of a specific type.'
        resultsSelectCcpCodeLabel = Label(
            resultTopFrame,
            text='Directly jump to previous/next:',
            grid=(0, 4))
        self.resultsSelectCcpCodePulldown = PulldownList(
            resultTopFrame,
            callback=self.resultsChangeSelectedCcpCode,
            texts=selectCcpCodes,
            index=selectCcpCodes.index(self.resultsSelectedCcpCode),
            grid=(0, 5),
            tipText=tipText)

        self.selectedSolution = 1

        runLabel = Label(resultTopFrame, text='run:')
        runLabel.grid(row=0, column=6)

        texts = [' < ']
        commands = [self.resultsPrevSolution]
        self.resultsPreviousSolutionButton = ButtonList(resultTopFrame,
                                                        commands=commands,
                                                        texts=texts)
        self.resultsPreviousSolutionButton.grid(row=0, column=7, sticky='nsew')

        tipText = 'If you ran the algorithm more than once, you can select the solution given by the different runs.'
        self.resultsSolutionNumberEntry = IntEntry(
            resultTopFrame,
            grid=(0, 8),
            width=7,
            text=1,
            returnCallback=self.solutionUpdateAfterEntry,
            tipText=tipText)
        #self.resultsSolutionNumberEntry.bind('<Leave>', self.solutionUpdateAfterEntry, '+')

        texts = [' > ']
        commands = [self.resultsNextSolution]
        self.resultsNextSolutionButton = ButtonList(resultTopFrame,
                                                    commands=commands,
                                                    texts=texts)
        self.resultsNextSolutionButton.grid(row=0, column=9, sticky='nsew')

        self.energyLabel = Label(resultTopFrame, text='energy:')
        self.energyLabel.grid(row=0, column=10)

        texts = ['template for puzzling']
        commands = [self.adoptSolution]
        self.adoptButton = ButtonList(resultTopFrame,
                                      commands=commands,
                                      texts=texts)
        self.adoptButton.grid(row=0, column=11, sticky='nsew')

        # LabelFrame(frame, text='Spin Systems')
        resultsSecondFrame = Frame(frame)
        resultsSecondFrame.grid(row=2, column=0, sticky='nsew')

        resultsSecondFrame.grid_columnconfigure(0, weight=1)
        resultsSecondFrame.grid_columnconfigure(1, weight=1)
        resultsSecondFrame.grid_columnconfigure(2, weight=1)
        resultsSecondFrame.grid_columnconfigure(3, weight=1)
        resultsSecondFrame.grid_columnconfigure(4, weight=1)

        headingList = ['#', '%']

        tipTexts = [
            'Spinsystem number {} indicates serial of the spinsystem. If the spinsystem was already assigned to a residue, the residue number is shown aswell',
            'percentage of the solutions that connected this spinsystem to this residue'
        ]

        editWidgets = [None, None, None]

        self.displayResultsTables = []
        self.residueLabels = []

        for i in range(5):

            label = Label(resultsSecondFrame, text='residue')
            label.grid(row=0, column=i)

            #editGetCallbacks = [createCallbackFunction(i)]*3

            displayResultsTable = ScrolledMatrix(
                resultsSecondFrame,
                headingList=headingList,
                multiSelect=False,
                tipTexts=tipTexts,
                callback=self.selectSpinSystemForTable,
                passSelfToCallback=True)

            displayResultsTable.grid(row=2, column=i, sticky='nsew')
            displayResultsTable.sortDown = False

            self.residueLabels.append(label)
            self.displayResultsTables.append(displayResultsTable)

        # LabelFrame(frame, text='Sequence Fragment')
        resultsFirstFrame = Frame(resultsSecondFrame)
        resultsFirstFrame.grid(row=1, column=0, sticky='ew', columnspan=5)

        resultsFirstFrame.grid_rowconfigure(0, weight=1)
        resultsFirstFrame.grid_rowconfigure(1, weight=1)
        resultsFirstFrame.grid_columnconfigure(0, weight=1)

        texts = [
            ' res 1 ', ' links ', ' res 2 ', ' links ', ' res 3 ', ' links ',
            ' res 4 ', ' links ', ' res 5 '
        ]
        commands = [
            lambda: self.selectRelativeResidue(1, True),
            lambda: self.selectLink(1, True),
            lambda: self.selectRelativeResidue(2, True),
            lambda: self.selectLink(2, True),
            lambda: self.selectRelativeResidue(3, True),
            lambda: self.selectLink(3, True),
            lambda: self.selectRelativeResidue(4, True),
            lambda: self.selectLink(4, True),
            lambda: self.selectRelativeResidue(5, True)
        ]
        self.sequenceButtons = ButtonList(resultsFirstFrame,
                                          commands=commands,
                                          texts=texts)
        self.sequenceButtons.grid(row=0, column=0, sticky='nsew')

        for n, button in enumerate(self.sequenceButtons.buttons):

            if n % 2:

                button.grid(column=n, sticky='ns')

                self.sequenceButtons.grid_columnconfigure(n, weight=0)

            else:

                self.sequenceButtons.grid_columnconfigure(n, uniform=2)

        spacer = Spacer(resultsFirstFrame)
        spacer.grid(row=1, column=0, sticky='nsew')

        texts = [
            ' res 1 ', ' links ', ' res 2 ', ' links ', ' res 3 ', ' links ',
            ' res 4 ', ' links ', ' res 5 '
        ]
        commands = commands = [
            lambda: self.selectRelativeResidue(1, False),
            lambda: self.selectLink(1, False),
            lambda: self.selectRelativeResidue(2, False),
            lambda: self.selectLink(2, False),
            lambda: self.selectRelativeResidue(3, False),
            lambda: self.selectLink(3, False),
            lambda: self.selectRelativeResidue(4, False),
            lambda: self.selectLink(4, False),
            lambda: self.selectRelativeResidue(5, False)
        ]
        self.sequenceButtonsB = ButtonList(resultsFirstFrame,
                                           commands=commands,
                                           texts=texts)
        self.sequenceButtonsB.grid(row=2, column=0, sticky='nsew')

        for n, button in enumerate(self.sequenceButtonsB.buttons):

            if n % 2:

                button.grid(column=n, sticky='ns')

                self.sequenceButtonsB.grid_columnconfigure(n, weight=0)

            else:

                self.sequenceButtonsB.grid_columnconfigure(n, uniform=2)

        frame.grid_rowconfigure(3, weight=2)

        resultsThirdFrame = Frame(frame)
        resultsThirdFrame.grid(row=3, column=0, sticky='nsew')

        resultsThirdFrame.grid_rowconfigure(0, weight=1)
        resultsThirdFrame.grid_columnconfigure(0, weight=1)

        tabbedFrameB = TabbedFrame(resultsThirdFrame,
                                   options=['Peaks', 'Spin System'],
                                   callback=self.toggleTab,
                                   grid=(0, 0))
        #self.tabbedFrameB = tabbedFrame

        PeakFrame, SpinSystemFrame = tabbedFrameB.frames

        SpinSystemFrame.grid_rowconfigure(0, weight=1)
        PeakFrame.grid_rowconfigure(1, weight=1)

        SpinSystemFrame.grid_columnconfigure(0, weight=1)
        PeakFrame.grid_columnconfigure(0, weight=1)

        headingList = [
            'residue', 'assigned to in project', 'user defined sequence',
            'selected annealing result', '%'
        ]

        tipTexts = [None, None, None, None, None]

        editWidgets = [None, None, None, None, None]

        editGetCallbacks = [None, None, None, None, None]

        editSetCallbacks = [None, None, None, None, None]

        self.spinSysTable = ScrolledMatrix(SpinSystemFrame,
                                           headingList=headingList,
                                           editWidgets=editWidgets,
                                           multiSelect=False,
                                           editGetCallbacks=editGetCallbacks,
                                           editSetCallbacks=editSetCallbacks,
                                           tipTexts=tipTexts)
        self.spinSysTable.grid(row=0, column=0, sticky='nsew')

        buttonFrameinPeakFrame = Frame(PeakFrame)
        buttonFrameinPeakFrame.grid(sticky='ew')

        self.findButton = Button(
            buttonFrameinPeakFrame,
            text=' Go to Peak ',
            borderwidth=1,
            padx=2,
            pady=1,
            command=self.findPeak,
            tipText='Locate the currently selected peak in the specified window'
        )

        self.findButton.grid(row=0, column=0, sticky='e')

        label = Label(buttonFrameinPeakFrame, text='in window:')

        label.grid(row=0, column=1, sticky='w')

        self.windowPulldown = PulldownList(
            buttonFrameinPeakFrame,
            callback=self.selectWindowPane,
            tipText='Choose the spectrum window for locating peaks or strips')

        self.windowPulldown.grid(row=0, column=2, sticky='w')

        self.assignSelectedPeaksButton = Button(
            buttonFrameinPeakFrame,
            text='Assign Resonances to Peak(s)',
            borderwidth=1,
            padx=2,
            pady=1,
            command=self.assignSelectedPeaks,
            tipText=
            'Assign resonances to peak dimensions, this of course only works when the peak is found in the spectrum.'
        )

        self.assignSelectedPeaksButton.grid(row=0, column=3, sticky='ew')

        self.assignSelectedSpinSystemsToResiduesButton = Button(
            buttonFrameinPeakFrame,
            text='Assign Spinsystems to Residues',
            borderwidth=1,
            padx=2,
            pady=1,
            command=self.assignSelectedSpinSystemsToResidues,
            tipText='Assign spinsystems to residues')

        self.assignSelectedSpinSystemsToResiduesButton.grid(row=0,
                                                            column=4,
                                                            sticky='ew')

        headingList = [
            '#', 'spectrum', 'Dim1', 'Dim2', 'Dim3', 'c.s. dim1', 'c.s. dim2',
            'c.s. dim3', 'colabelling'
        ]

        tipTexts = [
            'Peak number, only present when the peak was actually found in the spectrum.',
            'Name of the spectrum',
            'Name of atomSet measured in this dimension. Dimension number corresponds to Ref Exp Dim as indicated by going in the main menu to Experiment-->Experiments-->Experiment Type',
            'Name of atomSet measured in this dimension. Dimension number corresponds to Ref Exp Dim as indicated by going in the main menu to Experiment-->Experiments-->Experiment Type',
            'Name of atomSet measured in this dimension. Dimension number corresponds to Ref Exp Dim as indicated by going in the main menu to Experiment-->Experiments-->Experiment Type',
            'Chemical Shift', 'Chemical Shift', 'Chemical Shift',
            'Colabbeling fraction over all nuclei that are on the magnetization transfer pathway during the experiment that gave rise to the peak, including visited nuclei that were not measured in any of the peak dimensions'
        ]

        #editWidgets = [None, None, None, None, None, None, None, None, None]

        editGetCallbacks = [
            None, None, None, None, None, None, None, None, None
        ]

        #editGetCallbacks = [self.selectPeak, self.selectPeak, self.selectPeak, self.selectPeak, self.selectPeak, self.selectPeak, self.selectPeak, self.selectPeak, self.selectPeak]

        editSetCallbacks = [
            None, None, None, None, None, None, None, None, None
        ]

        self.displayPeakTable = ScrolledMatrix(PeakFrame,
                                               headingList=headingList,
                                               multiSelect=True,
                                               tipTexts=tipTexts)
        #editWidgets=editWidgets, multiSelect=True,
        # editGetCallbacks=editGetCallbacks,
        # editSetCallbacks=editSetCallbacks,
        # tipTexts=tipTexts)
        self.displayPeakTable.grid(row=1, column=0, sticky='nsew')

        self.windowPane = None
        self.updateWindows()
Exemplo n.º 7
0
    def setEntries(self, entries, docKeys=None, tipTexts=None):

        if entries == self.entries:
            return

        nentries = len(entries)
        if not docKeys:
            docKeys = [None] * nentries

        if not tipTexts:
            tipTexts = [None] * nentries

        if self.entries:
            for b in self.buttons:
                b.destroy()

        self.entries = entries
        self.buttons = nentries * [None]
        self.frames = nentries * [None]

        for n, entry in enumerate(entries):

            frame = Frame(self, borderwidth=self.borderwidth)

            entryText = entry
            m = self.min_text_width - len(entryText)
            if m > 0:
                entryText = entryText + m * ' '

            bgColor = self.cget('bg')
            callback = lambda entry=entry, callback=self.selectCallback: callback(
                entry)
            button = RadioButton(frame,
                                 bg=bgColor,
                                 text=entryText,
                                 callback=callback,
                                 highlightbackground=bgColor,
                                 highlightcolor=bgColor,
                                 activebackground='#D0B0A0',
                                 activeforeground='white',
                                 variable=self.var,
                                 font=self.font,
                                 value=n,
                                 docKey=docKeys[n],
                                 tipText=tipTexts[n])

            if self.selectcolor:
                button.config(selectcolor=self.selectcolor)

            if self.direction == Tkinter.HORIZONTAL:
                frame.grid(row=0,
                           pady=0,
                           column=n,
                           sticky=Tkinter.NSEW,
                           padx=self.padding)
                self.grid_columnconfigure(n, weight=1)
            else:
                frame.grid(row=n,
                           padx=0,
                           sticky=Tkinter.NSEW,
                           pady=self.padding)
                self.grid_rowconfigure(n, weight=1)

            frame.grid_rowconfigure(0, weight=1)
            frame.grid_columnconfigure(0, weight=1)
            button.grid(sticky='nw')

            self.buttons[n] = button
            self.frames[n] = frame

        self.setOptions()
Exemplo n.º 8
0
    def body(self, guiFrame):

        guiFrame.grid_columnconfigure(0, weight=1)

        row = 0

        frame = Frame(guiFrame)
        frame.grid(row=row, column=0, sticky='nsew')
        frame.grid_columnconfigure(3, weight=1)

        label = Label(frame, text='Shift List:')
        label.grid(row=0, column=0, sticky='w')

        self.shiftListPulldown = PulldownMenu(frame,
                                              callback=self.setShiftList)
        self.shiftListPulldown.grid(row=0, column=1, sticky='w')

        label = Label(frame, text='Sequential Link Type:')
        label.grid(row=0, column=2, sticky='w')

        entries = ['-1', '-1,+1', '+1']
        self.linkPulldown = PulldownMenu(frame,
                                         callback=self.setLink,
                                         entries=entries,
                                         do_initial_callback=False,
                                         selected_index=entries.index(
                                             self.link))
        self.linkPulldown.grid(row=0, column=3, sticky='w')

        row += 1
        frame = LabelFrame(guiFrame, text='Link Atoms:')
        frame.grid(row=row, column=0, sticky='nsew')
        frame.grid_columnconfigure(0, weight=1)
        frame.grid_rowconfigure(0, weight=1)

        labels = ['C', 'CA', 'CB', 'CG', 'CD', 'H', 'HA', 'HB', 'HG', 'HD']
        selected = ['CA', 'CB']
        self.atomSelector = PartitionedSelector(frame,
                                                objects=labels,
                                                labels=labels,
                                                selected=selected,
                                                toggledBg='#808080',
                                                callback=self.changeAtoms,
                                                maxRowObjects=10)
        self.atomSelector.grid(row=0, column=0, sticky='ew')

        row += 1
        guiFrame.grid_rowconfigure(row, weight=1)

        frame = LabelFrame(guiFrame, text='Predicted Residue Assignments')
        frame.grid(row=row, column=0, sticky='nsew')
        frame.grid_columnconfigure(0, weight=1)
        frame.grid_rowconfigure(0, weight=1)

        headingList = [
            '#', 'Predicted\nResidue', 'Prob.', 'Links', 'CA', 'CA -1', 'CB',
            'CB -1'
        ]
        self.spinSystemMatrix = ScrolledMatrix(frame,
                                               headingList=headingList,
                                               callback=self.selectSpinSystem,
                                               multiSelect=1)
        self.spinSystemMatrix.grid(row=0, column=0, sticky='nsew')

        row += 1
        texts = ['Link Selected', 'Link All', 'Commit Assignment']
        commands = [
            self.linkSelectedSpinSystems, self.linkAllSpinSystems,
            self.commitAssignments
        ]
        buttonList = UtilityButtonList(guiFrame,
                                       texts=texts,
                                       commands=commands,
                                       helpUrl=self.help_url)
        buttonList.grid(row=row, column=0, sticky='ew')

        self.buttons = buttonList.buttons

        for func in ('__init__', 'delete'):
            for clazz in ('ccp.nmr.Nmr.ShiftList', ):
                self.registerNotify(self.updateShiftLists, clazz, func)

        for func in ('__init__', 'delete', 'setNmrChains', 'setResidue',
                     'setResonances', 'addResonance', 'removeResonance'):
            self.registerNotify(self.updateSpinSystemsAfter,
                                'ccp.nmr.Nmr.ResonanceGroup', func)

        self.updateShiftLists()
Exemplo n.º 9
0
    def createLink(self, role, clazz):

        title_label = Label(self.parent_frame)
        class_label = ToggleLabel(self.parent_frame,
                                  text=role.clazz.name,
                                  callback=self.gridWidgets,
                                  isArrowClosed=True)
        class_label.label.config(anchor=Tkinter.W)
        name_label = Label(self.parent_frame,
                           text=role.name,
                           anchor=Tkinter.W,
                           bg=name_bg)
        value_label = Label(self.parent_frame)
        type_label = Label(self.parent_frame,
                           text=clazz.name,
                           anchor=Tkinter.W)
        card_label = Label(self.parent_frame,
                           text=self.getCardinality(role),
                           anchor=Tkinter.W)
        note_label = Label(self.parent_frame,
                           text=self.getNote(role),
                           anchor=Tkinter.W)

        link_frame = Frame(self.parent_frame)
        link_frame.grid_rowconfigure(0, weight=1)
        link_frame.grid_columnconfigure(table_col, weight=1)

        # table must be created first
        table = ObjectTable(link_frame, clazz, initialRows=3)

        texts = ['Goto']
        commands = [lambda: self.gotoObject(table, clazz)]

        if (role.hierarchy == child_hierarchy):

            texts.extend(['Create', 'Delete'])
            commands.extend([
                lambda: self.createChild(clazz),
                lambda: self.deleteChild(table)
            ])

        elif (not role.isDerived
              and (not self.editMode or (role.changeability == changeable and
                                         (role.locard != role.hicard)))):

            if (role.hicard == 1):
                texts.extend(['Set', 'Unset'])
                commands.extend([
                    lambda: self.setLink(role, clazz),
                    lambda: self.unsetLink(role)
                ])
            else:
                texts.extend(['Add', 'Remove'])
                commands.extend([
                    lambda: self.addLink(role, clazz),
                    lambda: self.removeLink(table, role)
                ])

        buttons = ButtonList(link_frame,
                             texts=texts,
                             commands=commands,
                             direction=Tkinter.VERTICAL)

        self.widget_dict[(role,
                          clazz)] = (title_label, class_label, name_label,
                                     value_label, type_label, card_label,
                                     note_label, link_frame, buttons, table)

        table.callback = lambda obj, row, col: self.setButtonState(
            table, role, clazz, buttons)
Exemplo n.º 10
0
    def setEntries(self, entries):

        if (entries == self.entries):
            return

        if (self.entries):
            for b in self.buttons:
                b.destroy()

        self.entries = entries
        self.buttons = len(entries) * [0]
        self.frames = len(entries) * [0]

        for n in range(len(entries)):

            frame = Frame(self, borderwidth=self.borderwidth)

            entry = entries[n]

            entryText = entry
            m = self.min_text_width - len(entryText)
            if m > 0:
                entryText = entryText + m * ' '

            bgColor = self.cget('bg')
            button = Tkinter.Radiobutton(frame,
                                         bg=bgColor,
                                         text=entryText,
                                         highlightbackground=bgColor,
                                         highlightcolor=bgColor,
                                         variable=self.var,
                                         font=self.font,
                                         value=n)

            command = lambda entry=entry, callback=self.selectCallback: callback(
                entry)
            button.config(command=command)

            if (self.selectcolor):
                button.config(selectcolor=self.selectcolor)

            if (self.direction == Tkinter.HORIZONTAL):
                frame.grid(row=0,
                           pady=0,
                           column=n,
                           sticky=Tkinter.NSEW,
                           padx=self.padding)
                self.grid_columnconfigure(n, weight=1)
            else:
                frame.grid(row=n,
                           padx=0,
                           sticky=Tkinter.NSEW,
                           pady=self.padding)
                self.grid_rowconfigure(n, weight=1)

            frame.grid_rowconfigure(0, weight=1)
            frame.grid_columnconfigure(0, weight=1)
            button.grid(sticky='nw')

            self.buttons[n] = button
            self.frames[n] = frame

        self.setOptions()