Пример #1
0
    def initUIElements(self):
        self.activeFrame = Frame(self,padx=5,pady=5,borderwidth=1)
        dummy = self.container.dataMap[self.show]
        self.activeItemFrame = ItemFrame(self.activeFrame,dummy,True,\
                                         self,borderwidth=1)

        if isinstance(self.parent,Toplevel):
            options = {"usehullsize":1,\
                       "hull_width":560,\
                       "hull_height":400}
        elif isinstance(self.parent,ItemFrame):
            options = {"usehullsize":1,\
                       "hull_width":540,\
                       "hull_height":150}
        else:
            options = {"usehullsize":1,\
                       "hull_width":460,\
                       "hull_height":320}

        self.scrolledFrame = ScrolledFrame(self,**options)

        for item in self.container.__dict__[self.show]:
            self.frames.append(\
                    ItemFrame(self.scrolledFrame.interior(),item,False,self))

        if isinstance(self.parent,Toplevel):
            self.quit = Button(self,text="Close",command=self.parent.destroy)
Пример #2
0
    def popUp(self):
        self.pop = Toplevel()
        self.pop.title("Name mapping")
        self.frame = Frame(self.pop,padx=5,pady=5)
        self.listFrame = ScrolledFrame(self.frame)
        self.similars = self.getSimilarItems()
        
        row = 0
        Label(self.frame,text="From: ").grid(row=row,column=0,sticky="W")
        Label(self.frame,text="To: ").grid(row=row,column=2,sticky="W")

        self.buildList()
        self.listFrame.grid(sticky='W', row=1,column=0,columnspan=4)

        Button(self.frame,text="Save",command=self.onSave)\
               .grid(sticky='W',row=2,column=0)

        Label(self.frame,text="Copy From: ").grid(sticky='W',row=2,column=1)
        OptionMenu(self.frame,self.mapVar,*self.similars.keys()).grid(sticky='W',row=2,column=2)

        self.frame.pack()
        self.frame.update()
Пример #3
0
class ItemList(LabelFrame):
    def __init__(self,parent,container,show,active=False,*args,**kwargs):
        LabelFrame.__init__(self,parent,*args,**kwargs)
        # self.items = container.__dict__[show]
        self.active = active
        self.parent = parent
        self.frames = []
        self.show = show
        self.container = container

        self.analyzeData()
        self.initUIElements()
        self.gridUIElements()

    def toBottom(self):
        self.scrolledFrame.yview(mode="moveto",value=1.0)

    def analyzeData(self):
        pass

    def initUIElements(self):
        self.activeFrame = Frame(self,padx=5,pady=5,borderwidth=1)
        dummy = self.container.dataMap[self.show]
        self.activeItemFrame = ItemFrame(self.activeFrame,dummy,True,\
                                         self,borderwidth=1)

        if isinstance(self.parent,Toplevel):
            options = {"usehullsize":1,\
                       "hull_width":560,\
                       "hull_height":400}
        elif isinstance(self.parent,ItemFrame):
            options = {"usehullsize":1,\
                       "hull_width":540,\
                       "hull_height":150}
        else:
            options = {"usehullsize":1,\
                       "hull_width":460,\
                       "hull_height":320}

        self.scrolledFrame = ScrolledFrame(self,**options)

        for item in self.container.__dict__[self.show]:
            self.frames.append(\
                    ItemFrame(self.scrolledFrame.interior(),item,False,self))

        if isinstance(self.parent,Toplevel):
            self.quit = Button(self,text="Close",command=self.parent.destroy)

    def gridUIElements(self):
        r = 0

        self.activeItemFrame.grid()
        self.activeFrame.grid(sticky="WE",row=r,column=0)
        r += 1

        for i,frame in enumerate(self.frames):
            frame.grid(row=i,column=0,sticky="W",columnspan=2)

        self.scrolledFrame.grid(sticky = "WESN",row=r)

        r += 1
        if isinstance(self.parent,Toplevel):
            self.quit.grid(sticky="WE",row=r,column=0)
            self.grid()
            self.parent.grid()

    def grid(self,*args,**kwargs):
        LabelFrame.grid(self,*args,pady=2,**kwargs)

    def synchronize(self,container = None):
        if container:
            self.container = container
        #TODO: Thats lazy
        for i,item in enumerate(self.container.__dict__[self.show]):
            if not item in [frame.data for frame in self.frames]:
                frame = ItemFrame(self.scrolledFrame.interior(),\
                                  item,False,self)
                frame.grid(sticky="W")
                self.frames.append(frame)
        
        to_remove = []
        for f in self.frames:
            if not (f.data in self.container.__dict__[self.show]):
                to_remove.append(f)
        for f in to_remove:
            self.frames.remove(f)
            f.destroy()
        self.scrolledFrame.grid()
        self.grid()
        try:
            chimera.triggers.activateTrigger('configUpdated', None)
        except:
            print "No chimera config update!"
Пример #4
0
class MapFrame(Frame):
    def __init__(self,parent,mapping,active=False,copy=None,*args,**kwargs):
        Frame.__init__(self,parent,*args,**kwargs)
        self.active = active
        self.mapping = mapping
        self.mapVar = StringVar(self)
        self.mapVar.trace("w",lambda a,b,c:self.copyMapping())
        self.copy = copy
        self.subsetframes = {}

        if self.mapping.isEmpty():
            title = "No elements to map yet"
            message = "Please add some elements before mapping."
            tkMessageBox.showinfo(title,message,parent=self.master)
            return

        self.mapButton = Button(self,text="Map",command=self.popUp)
        self.mapButton.grid()
        self.grid()
    
    def formatKey(self,key):
        if len(key) > 60:
            key = key[:21] + '...' + key[-19:]
        return key
    
    def popUp(self):
        self.pop = Toplevel()
        self.pop.title("Name mapping")
        self.frame = Frame(self.pop,padx=5,pady=5)
        self.listFrame = ScrolledFrame(self.frame)
        self.similars = self.getSimilarItems()
        
        row = 0
        Label(self.frame,text="From: ").grid(row=row,column=0,sticky="W")
        Label(self.frame,text="To: ").grid(row=row,column=2,sticky="W")

        self.buildList()
        self.listFrame.grid(sticky='W', row=1,column=0,columnspan=4)

        Button(self.frame,text="Save",command=self.onSave)\
               .grid(sticky='W',row=2,column=0)

        Label(self.frame,text="Copy From: ").grid(sticky='W',row=2,column=1)
        OptionMenu(self.frame,self.mapVar,*self.similars.keys()).grid(sticky='W',row=2,column=2)

        self.frame.pack()
        self.frame.update()
        
    def getSimilarItems(self):
        ret = {"":None}
        if self.copy:
            ret = dict([(str(i),i) for i in self.mapping.getCopySources()])
        return ret

    def buildList(self):
        c = 0
        for i,key in enumerate(self.mapping.keys()):
            Label(self.listFrame.interior(),text=self.formatKey(key))\
                 .grid(row=i+c,column=0,pady=1,padx=3)
            ssf = SubsetFrame(self.listFrame.interior(),self.mapping.getSubset(key),limit=1)
            self.subsetframes[key] = ssf
            ssf.grid(sticky="w",row=i,column=1)

    def onSave(self):
        self.pop.destroy()
        for key,ssf in self.subsetframes.items():
            self.mapping[key] = ssf.subset
        chimera.triggers.activateTrigger('configUpdated', None)
        
    def copyMapping(self):
        copyFrom = self.similars[self.mapVar.get()].mapping
        self.mapping.copyFrom(copyFrom)
        self.buildList()
Пример #5
0
    def display_alarms(self):
        self.active_alarms = {}

        if not self.save_file_dict:
            tk.Label(self,
                     text='No Alarms',
                     bg='white',
                     fg=rgb(167, 167, 167),
                     font=('arial', 15)).pack(side=tk.TOP, anchor=tk.W)
            return
        scroll_bar = ScrolledFrame(self, hscrollmode='none', borderframe=0)
        scroll_bar.pack(fill='both', expand=1)
        scroll_frame = scroll_bar.interior()
        scroll_frame.configure(bg='white')
        for it, alarm in enumerate(self.save_file_dict):
            main_frame = tk.Frame(scroll_frame, bg='white')
            main_frame.bind(
                '<Enter>',
                lambda e, s=self, f=main_frame: s.set_frame_color(f))
            main_frame.bind(
                '<Leave>',
                lambda e, s=self, f=main_frame: s.set_frame_color(f, False))
            cur_file = self.save_file_dict[alarm]
            time = cur_file['alarm_time']
            ind = time.rfind(':')
            alarm_time = time[:ind] + ' ' + time[ind + 1:]

            text_frame = tk.Frame(main_frame, bg='white', width=350, height=70)
            text_frame.pack_propagate(0)
            tk.Label(text_frame,
                     text=alarm_time,
                     bg='white',
                     font=('arial', 15)).pack(side=tk.TOP, anchor=tk.W)
            name_label = tk.Label(text_frame,
                                  text=cur_file['alarm_name'],
                                  bg='white',
                                  font=('arial', 11, 'bold'))
            name_label.pack(side=tk.TOP, anchor=tk.W)
            tk.Label(text_frame,
                     text=cur_file['trim_repeat_days'],
                     bg='white',
                     font=('arial', 11)).pack(side=tk.TOP, anchor=tk.W)
            text_frame.pack(side=tk.LEFT)

            # check_button_frame = tk.Frame(main_frame, bg='white', width=60, height=70)
            # check_button_frame.pack_propagate(0)
            check_button_frame = tk.Frame(main_frame,
                                          bg='white',
                                          width=95,
                                          height=70)
            check_button_frame.pack_propagate(0)

            check_name = tk.StringVar()
            check_bool = tk.BooleanVar()
            check_bool.set(cur_file['active'])
            # check_button = tk.Checkbutton(check_button_frame, textvar=check_name, state=tk.NORMAL, bg='white', anchor=tk.W,
            #                variable=check_bool, takefocus=0)
            # check_button.bind('<Button-1>', lambda e, s=self, a=alarm: s.display(a))
            # check_button.pack(side=tk.RIGHT, ipadx=(40))
            check_button = TickButton(
                check_button_frame,
                on_off_text=('Off', 'On'),
                function=lambda s=self, a=alarm: s.specialised_button(a),
                textvar=check_name,
                variable=check_bool,
                bg='white')
            check_button.pack(side=tk.RIGHT, ipadx=(40))
            check_button_frame.pack(side=tk.RIGHT)
            self.active_alarms[alarm] = [
                time, name_label, check_name, check_bool
            ]
            self.display(alarm, True)
            #this applies mouse button event to all the widgets except for the checkbutton
            self.apply_binding_toall(
                main_frame,
                '<Button-1>',
                lambda x, s=self, a=alarm: s.show_alarm_details(a),
                [check_button])

            main_frame.pack(side=tk.TOP,
                            expand=False,
                            anchor=tk.N + tk.W,
                            fill=tk.Y,
                            pady=(0, 9))
Пример #6
0
    def __init__(self, configobj):
        self.window = Toplevel()
        # self.window.option_add("*Background", "white")
        self.window.protocol('WM_DELETE_WINDOW', self.cancel)

        f0 = Frame(self.window)
        f0.pack(side='top', anchor='w', expand=False, fill='x')
        t = _(
            'Note that most changes become effective only after restarting the program.'
        )
        text = Text(f0, height=len(t) // 80 + 1, width=80, wrap='word')
        text.insert(1.0, _(t))
        text.config(state='disabled')
        text.pack(side='left', expand=True, fill='x')
        Button(f0, text=_('Save'), command=self.save,
               bg='lightgreen').pack(side='right', anchor='e')
        Button(f0, text=_('Cancel'), command=self.cancel,
               bg='orange').pack(side='right', anchor='e')

        self.configobj = configobj
        self.variables = {
        }  # will store the Tkinter variables containing the values
        special_values = [
            '# -----',
            '# section',
            '# label',
            '# editable',
            '# values',
        ]

        sf = ScrolledFrame(self.window, usehullsize=1, hull_height=500)
        sf.pack(side='top', anchor='w', expand=True, fill='both')
        f = sf.interior()
        ctr = -1

        for prop in configobj['options']:
            comments = configobj['options'].comments[prop]

            # new "section"?
            sec = self.retrieve('# section:', comments)
            if sec:
                ctr += 1
                Label(f,
                      text=_(sec),
                      justify='left',
                      bg='#eeeeee',
                      font=('Helvetica', 14, 'bold')).grid(row=ctr,
                                                           column=0,
                                                           columnspan=3,
                                                           sticky='we',
                                                           pady=10)

            if '# editable' in comments:
                ctr += 1

                label = self.retrieve('# label:', comments) or prop
                label = label.strip()
                values = self.retrieve('# values:', comments)
                if values:
                    values = values.split(', ')
                else:
                    values = []
                help_text = ' '.join(
                    x[1:].strip() for x in comments
                    if not any(x.startswith(v)
                               for v in special_values)).strip()

                if 'BOOLEAN' in values:
                    self.variables[prop] = BooleanVar()
                else:
                    self.variables[prop] = StringVar()

                if '--' in values and configobj['options'][prop] == '':
                    self.variables[prop].set('--')
                else:
                    self.variables[prop].set(configobj['options'][prop])

                if 'BOOLEAN' in values:
                    Checkbutton(f,
                                text=_(label),
                                indicatoron=1,
                                variable=self.variables[prop]).grid(
                                    row=ctr, column=1, sticky='nw', pady=5)
                elif values and not 'INT' in values:
                    Label(f, text=_(label), justify='left').grid(row=ctr,
                                                                 column=0,
                                                                 sticky='nw',
                                                                 pady=5)
                    Combobox(
                        f,
                        justify='left',
                        textvariable=self.variables[prop],
                        values=values,
                    ).grid(row=ctr, column=1, sticky='nw', pady=5)
                else:
                    Label(f, text=_(label), justify='left').grid(row=ctr,
                                                                 column=0,
                                                                 sticky='nw',
                                                                 pady=5)
                    Entry(f, width=20,
                          textvariable=self.variables[prop]).grid(row=ctr,
                                                                  column=1,
                                                                  sticky='nw',
                                                                  pady=5)
                if help_text:
                    ht = _(help_text)
                    text = Text(f,
                                height=len(ht) // 60 + 1,
                                width=60,
                                borderwidth=0,
                                wrap='word')
                    text.insert(1.0, _(help_text))
                    text.config(state='disabled')
                    text.grid(row=ctr, column=2, sticky='nsew', pady=5)

        self.window.update_idletasks()

        self.window.focus()
        self.window.grab_set()
        self.window.wait_window()