示例#1
0
    def ListWithScrollbar(cls, master):
        '''Sample usage:
            from com.ui import ROOT    
            frame1 = Widget.Labelframe(ROOT,text = "sssss")
            frame1.rowconfigure(0,weight =1, minsize = 0)
            frame1.columnconfigure(0,weight =1, minsize = 0)
            Window.widg = frame1
            Window.Pack(side = "top", fill="both", expand="yes", padx = "0.2c")
                
            (l,x,y) = Components.ListWithScrollbar(frame1)
            elems = ["Don't speculate, measure", "Waste not, want not", "Early to bed and early to rise makes a man healthy, wealthy, and wise", "Ask not what your country can do for you, ask what you can do for your country", "I shall return", "NOT", "A picture is worth a thousand words", "User interfaces are hard to build", "Thou shalt not steal", "A penny for your thoughts", "Fool me once, shame on you;  fool me twice, shame on me", "Every cloud has a silver lining", "Where there's smoke there's fire", "It takes one to know one", "Curiosity killed the cat", "Take this job and shove it", "Up a creek without a paddle", "I'm mad as hell and I'm not going to take it any more", "An apple a day keeps the doctor away", "Don't look a gift horse in the mouth", "Measure twice, cut once"]
            l.insert(0,*elems)
            ROOT.mainloop()
        '''
        f = TkFont()
        lb = Widget.Listbox(master,
                            width=60,
                            height=24,
                            font=f.font,
                            setgrid=1)
        s_x = Widget.Scrollbar(master,
                               orient=Tkconstants.HORIZONTAL,
                               command=lb.xview)
        s_y = Widget.Scrollbar(master,
                               orient=Tkconstants.VERTICAL,
                               command=lb.yview)

        Window.widg = s_y
        Window.Pack(side="right", fill="y")

        Window.widg = s_x
        Window.Pack(side="bottom", fill="x")

        Window.widg = lb
        Window.Config(xscrollcommand=s_x.set, yscrollcommand=s_y.set)
        Window.Pack(side="top", fill="both", expand="yes")

        #         lb = Widget.Listbox(master, width = 20, height = 10, setgrid = 1)
        #         s_x = Widget.Scrollbar(master,orient = Tkconstants.HORIZONTAL, command = lb.xview)
        #         s_y = Widget.Scrollbar(master,orient = Tkconstants.VERTICAL, command = lb.yview)
        #
        #         Window.widg = lb
        #         Window.Config(xscrollcommand = s_x.set, yscrollcommand = s_y.set)
        #         Window.Grid(row =0, column = 0, rowspan = 1, columnspan = 1, sticky = Tkconstants.NSEW)
        #
        #         Window.widg = s_y
        #         Window.Grid(row =0, column = 1, rowspan = 1, columnspan = 1, sticky = Tkconstants.NSEW)
        #
        #         Window.widg = s_x
        #         Window.Grid(row =1, column = 0, rowspan = 1, columnspan = 1, sticky = Tkconstants.NSEW)

        return (lb, s_x, s_y)
示例#2
0
    def RadioWithLabelframe(cls, master, texts=[], values=[], command=None):
        '''Sample usage:
            from ui import ROOT    
            frame1 = Widget.Labelframe(ROOT,text = "XXXX")
            Window.widg = frame1        
            Window.Pack(side = "left", fill="both", expand="no", padx = "0.2c")
                    
            frame2 = None
            def test(a):
                print a
                if frame2:
                    frame2.config(text = var.get())
                    t.delete("1.0","end")
                    t.insert("end",var.get())
                
            var,rds = Components.RadioWithLabelframe(frame1, texts = [1,2,3,4,5], values = [1,2,3,4,5], command = lambda: test("if command has parameter; please use lambda.like this"))
            
            frame2 = Widget.Labelframe(ROOT,text = "YYYY")        
            Window.widg = frame2
            Window.Pack(side = "left", fill="both", expand="yes", padx = "0.2c")
            (t,x,y) = Components.TextWithScrollbar(frame2)
                    
            ROOT.mainloop()
        '''
        radios = []
        var = Tkinter.StringVar()
        radio_items = dict(zip(texts, values))
        for text, value in radio_items.items():
            Window.widg = Widget.Radiobutton(master, variable=var)
            Window.Config(text=text, value=value)
            if command:
                Window.Config(command=command)
            Window.Pack(side="top", fill="x", expand="yes", pady=2, anchor="w")
            radios.append(Window.widg)

        if radios:
            return var, radios
示例#3
0
    def TextWithScrollbar(cls, master):
        '''Sample usage:
            from com.ui import ROOT    
            frame1 = Widget.Labelframe(ROOT,text = "XXXX")
            Window.widg = frame1        
            Window.Pack(side = "top", fill="both", expand="yes", padx = "0.2c")
            
            (t,x,y) = Components.TextWithScrollbar(frame1)    
            t.insert("end","0.ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n")
            t.insert("end","1.sdf\n")    
            ROOT.mainloop()
        '''
        f = TkFont()
        # wrap -->设置当一行文本的长度超过width选项设置的宽度时,是否换行; "none"不自动换行, "char"按字符自动换行, "word"按单词自动换行
        # undo -->设置文本 是否可以 撤销 和 恢复; 默认值是  0 或者 False,表示没有开启
        tx = Widget.Text(master,
                         width=60,
                         height=24,
                         font=f.font,
                         wrap="word",
                         setgrid=1,
                         undo=True,
                         background="white")
        s_x = Widget.Scrollbar(master,
                               orient=Tkconstants.HORIZONTAL,
                               command=tx.xview)
        s_y = Widget.Scrollbar(master,
                               orient=Tkconstants.VERTICAL,
                               command=tx.yview)

        Window.widg = s_y
        Window.Pack(side="right", fill="y")

        Window.widg = s_x
        Window.Pack(side="bottom", fill="x")

        Window.widg = tx
        Window.Config(xscrollcommand=s_x.set, yscrollcommand=s_y.set)
        Window.Pack(side="top", fill="both", expand="yes")

        return (tx, s_x, s_y)
示例#4
0
    def TreeviewWithScrollbar(cls, master, head_names):
        '''Sample usage:
            from com.ui import ROOT    
            heads = [u"第一列", u"第二列"]
            datas = [("Argentina","Buenos Aires"),("Australia","Canberra"),("Brazil","Brazilia"),("Canada","Ottawa"),("China","Beijing"),("France","Paris")]    
            tree = Components.TreeviewWithScrollbar(ROOT,heads)[0]
            # Add
            items_list = []
            for data in datas:
                items_list.append(tree.insert("", "end", values = data))
            print "all items: ", items_list
                    
            # Select
            print tree.column('col0')
            
            tree.selection_set("I001")
            print "current selection: ", tree.selection()
            print "current index: ", tree.index("I001")
            
            tree.tag_configure("t_tag", font = u"宋体   12 normal italic", foreground="red")
            tree.item('I001',tags = "t_tag")
            
            item_info = tree.item('I001')
            print "item info: ", item_info
            
            # Update
            c_value = ("Oh", "Handsome boy.")
            tree.item('I001',values = c_value)
            print "%s changing to %s" %(datas[tree.index("I001")], c_value)       
            
            print "item value dict: %s" %tree.set("I002")
            print "column value: %s" %tree.set("I002","col0")
            print "set column value to 'HaLo'"
            tree.set("I002","col0","Halo")
            
            # Delete
            tree.delete("I006")
            print "deleted France item."
            
            ROOT.mainloop()   
        '''

        columns = []
        for i in range(len(head_names)):
            columns.append("col%d" % i)
        columns_and_headnames = zip(columns, head_names)

        t = Widget.Treeview(master, columns=columns, show="headings")
        for (col, text) in columns_and_headnames:
            t.column(col, width=100, anchor="center")
            t.heading(col, text=text)

        s_x = Widget.Scrollbar(master,
                               orient=Tkconstants.HORIZONTAL,
                               command=t.xview)
        s_y = Widget.Scrollbar(master,
                               orient=Tkconstants.VERTICAL,
                               command=t.yview)

        Window.widg = s_y
        Window.Pack(side="right", fill="y")

        Window.widg = s_x
        Window.Pack(side="bottom", fill="x")

        Window.widg = t
        Window.Config(xscrollcommand=s_x.set, yscrollcommand=s_y.set)
        Window.Pack(side="top", fill="both", expand="yes", pady=2, padx=2)

        return (t, s_x, s_y)