Ejemplo n.º 1
0
    def __init__(self):
        l = """An arrow and a vertical scale are
        displayed below.  If you click or drag
        mouse button 1 in the scale, you can
        change the size of the arrow."""
        DemoWindow.__init__(self, l, demo_path('vscale.py'))

        self.frame = Frame(self, width=300, height=500)
        self.frame.pack(expand=Y, fill=BOTH)

        self.scale = Scale(self.frame,
                           orient='vertical',
                           length=300,
                           from_=0,
                           to_=250,
                           tickinterval=50,
                           command=self.scale_callback)

        self.scale.pack(side=LEFT, expand=Y, fill=Y, padx=30, pady=30)
        self.canvas = Canvas(self.frame, height=300, width=200)
        self.canvas.pack(side=LEFT, expand=Y, fill=BOTH)
        options = {'fill': 'cyan', 'outline': 'darkblue'}
        self.arrow = self.canvas.create_polygon(*self.arrow_points(50))
        self.canvas.itemconfigure(self.arrow, options)
        self.scale.set(50)
Ejemplo n.º 2
0
    def __init__(self):

        l = """This window displays all of Tk's built-in bitmaps,
        along with the names you can use for them in  scripts.
        """

        DemoWindow.__init__(self, l, demo_path('bitmap.py'))

        frame = Frame(self)
        frame.pack(expand=YES, fill=BOTH, pady=10)

        list = ('error', 'gray12', 'gray25', 'gray50', 'gray75', 'hourglass',
                'info', 'question', 'questhead', 'warning')

        row = 0
        column = 0
        for b in list:
            f = Frame(frame)
            l1 = Label(f, bitmap=b)
            l1.pack(side=TOP)
            l2 = Label(f, text=b)
            l2.pack(side=BOTTOM)
            f.grid(row=row, column=column, sticky='ns', padx=10)
            column = column + 1
            if column >= len(list) / 2:
                row = row + 1
                column = 0
Ejemplo n.º 3
0
    def __init__( self ):
        l="""
        Choose the icon and type option of the message box.
        Then press the \"Message Box\" button to see the message box.
        """
        DemoWindow.__init__(self,l,demo_path('msgbox.py'))

        frame=Frame(self);frame.pack(expand=Y, fill=BOTH)

        #create the two option panels
        middleframe=Frame(frame); middleframe.pack(side=TOP,fill=X)
        p1 = OptionPanel(middleframe,'Icon',
                         'error', 'window', 'question', 'warning')
        p1.set('error')
        p1.pack(side=LEFT, expand=YES, fill=BOTH, padx=10, pady=10)
        p2 = OptionPanel(middleframe,'Type',
                         'abortretryignore', 'ok', 'okcancel',
                         'retrycancel', 'yesno' )
        p2.set('ok')
        p2.pack(side=RIGHT, expand=YES, fill=BOTH, padx=10,pady=10)

        b = Button(frame,text='Open Dialog', command=self.opendialog_callback )
        b.pack(side=TOP,fill=X, padx=10)
        
        self.p1, self.p2 = p1,p2 # needed by the callback
Ejemplo n.º 4
0
    def __init__(self):
        l="""Enter a file name in the entry box or click on the
        \"Browse\" buttons to select a file name using the file
        selection dialog."""

        DemoWindow.__init__(self, l, demo_path('filebox.py') )

        frame = Frame(self); frame.pack(side=TOP,expand=YES,fill=BOTH)

        l1 = Label(frame, text='Select a file to open:')
        l2 = Label(frame, text='Select a file to save:')
        e1=Entry(frame); self.e1=e1
        e2=Entry(frame); self.e2=e2
        b1 = Button(frame, text='Browse...', command=self.selectopen_callback)
        b2 = Button(frame, text='Browse...', command=self.selectsave_callback)

        frame.rowconfigure(1,pad=10, weight=1)
        for r in (0,1,2):
            frame.columnconfigure(r, pad=5)

        # insert elements in the container
        rnum=0
        for r in ( (l1, e1, b1), (l2, e2, b2) ):
            cnum=0
            for w in r :
                w.grid(row=rnum, column=cnum ) 
                cnum=cnum+1
            rnum=rnum+1

        self.mvar=IntVar(self)
        mb = Checkbutton(self, text='Use motif stile dialog',
                         variable=self.mvar, command=self.changestyle_callback )
        mb.pack(side=TOP, expand=YES, fill=X )
Ejemplo n.º 5
0
    def __init__(self):
        l = """
        Choose the icon and type option of the message box.
        Then press the \"Message Box\" button to see the message box.
        """
        DemoWindow.__init__(self, l, demo_path('msgbox.py'))

        frame = Frame(self)
        frame.pack(expand=Y, fill=BOTH)

        #create the two option panels
        middleframe = Frame(frame)
        middleframe.pack(side=TOP, fill=X)
        p1 = OptionPanel(middleframe, 'Icon', 'error', 'window', 'question',
                         'warning')
        p1.set('error')
        p1.pack(side=LEFT, expand=YES, fill=BOTH, padx=10, pady=10)
        p2 = OptionPanel(middleframe, 'Type', 'abortretryignore', 'ok',
                         'okcancel', 'retrycancel', 'yesno')
        p2.set('ok')
        p2.pack(side=RIGHT, expand=YES, fill=BOTH, padx=10, pady=10)

        b = Button(frame, text='Open Dialog', command=self.opendialog_callback)
        b.pack(side=TOP, fill=X, padx=10)

        self.p1, self.p2 = p1, p2  # needed by the callback
Ejemplo n.º 6
0
    def __init__(self):
        l = """This window displays a canvas widget that can be
        scrolled either using the scrollbars or by dragging with
        button 2 in the canvas.  If you click button 1 on one of
        the rectangles, its indices will displayed.
        You can also drag with button 3 to scroll the canvas.
        """
        DemoWindow.__init__(self,l,demo_path('canvasscroll.py') )

        self.canvas = ScrollableCanvas(self)
        self.canvas.pack(expand='Y', fill='both' )
Ejemplo n.º 7
0
    def __init__(self):
        l = """This canvas widget shows a mock-up of a ruler.
        You can create tab stops by dragging them out of the
        well to the right of the ruler.  You can also drag
        existing tab stops.  If you drag a tab stop far enough
        up or down so that it turns dim, it will be deleted when
        you release the mouse button."""
        DemoWindow.__init__(self, l, demo_path('canvasruler.py'))

        self.canvas = RulerCanvas(self)
        self.canvas.pack(expand=YES, fill=BOTH )
Ejemplo n.º 8
0
    def __init__(self):
        l = """This window displays a canvas widget that can be
        scrolled either using the scrollbars or by dragging with
        button 2 in the canvas.  If you click button 1 on one of
        the rectangles, its indices will displayed.
        You can also drag with button 3 to scroll the canvas.
        """
        DemoWindow.__init__(self, l, demo_path('cscroll.py'))

        self.canvas = ScrollableCanvas(self)
        self.canvas.pack(expand='Y', fill='both')
Ejemplo n.º 9
0
    def __init__(self):
        l = """This canvas widget shows a mock-up of a ruler.
        You can create tab stops by dragging them out of the
        well to the right of the ruler.  You can also drag
        existing tab stops.  If you drag a tab stop far enough
        up or down so that it turns dim, it will be deleted when
        you release the mouse button."""
        DemoWindow.__init__(self, l, demo_path('ruler.py'))

        self.canvas = RulerCanvas(self)
        self.canvas.pack(expand=YES, fill=BOTH )
Ejemplo n.º 10
0
    def __init__(self):

        l = ("""This window contains a menubar with cascaded menus.
        You can post a menu from the keyboard by typing %s+x,
        where \"x\" is the character underlined on the menu.
        You can then traverse among the menus using the arrow keys.
        When a menu is posted, you can invoke the current entry by
        typing space, or you can invoke any entry by typing its
        underlined character.  If a menu entry has an accelerator,
        you can invoke the entry without posting the menu just by
        typing the accelerator. The rightmost menu can be torn
        off into a palette by selecting the first item in the menu.
        """ % POST_KEY)
        DemoWindow.__init__(self, l, demo_path('menu.py'))
Ejemplo n.º 11
0
    def __init__(self):
        l = """Press the buttons below to choose the foreground and
        background colors for the widgets in this window."""

        DemoWindow.__init__(self, l, demo_path('clrpick.py'))

        frame = Frame(self)
        frame.pack(expand=YES, fill=BOTH)
        button_fg = Button(frame, text='Foreground', command=self.fg_callback)
        button_bg = Button(frame, text='Background', command=self.bg_callback)
        for b in button_fg, button_bg:
            b.pack(side=TOP, padx=10, pady=5, expand=YES, fill=X)

        self.all_widgets = (frame, button_fg, button_bg)
Ejemplo n.º 12
0
    def __init__(self):

        l = ("""This window contains a menubar with cascaded menus.
        You can post a menu from the keyboard by typing %s+x,
        where \"x\" is the character underlined on the menu.
        You can then traverse among the menus using the arrow keys.
        When a menu is posted, you can invoke the current entry by
        typing space, or you can invoke any entry by typing its
        underlined character.  If a menu entry has an accelerator,
        you can invoke the entry without posting the menu just by
        typing the accelerator. The rightmost menu can be torn
        off into a palette by selecting the first item in the menu.
        """ % POST_KEY )
        DemoWindow.__init__(self,l, demo_path('menu.py'))
Ejemplo n.º 13
0
    def __init__(self):

        l="""This demo shows you two ways of having
        a dialog to grab focus: local and global grab.
        Click on the relevant button and learn about
        the differences"""

        DemoWindow.__init__(self, l, demo_path('dialoggrab.py'))

        frame=Frame(self, relief=RIDGE,border=2); frame.pack(expand=YES,fill=BOTH)
        b1=Button(frame,text='Open dialog with local grab',
                  command=self.localgrab_callback)
        b2=Button(frame,text='Open dialog with global grab',
                  command=self.globalgrab_callback)
        for b in b1,b2: b.pack(side=LEFT, padx=5)
Ejemplo n.º 14
0
    def __init__(self):
        l = """Press the buttons below to choose the foreground and
        background colors for the widgets in this window."""

        DemoWindow.__init__(self,l,demo_path('clrpick.py'))

        frame=Frame(self); frame.pack(expand=YES, fill=BOTH)
        button_fg = Button(frame, text='Foreground',
                                command=self.fg_callback  )
        button_bg = Button(frame, text='Background',
                                command=self.bg_callback )
        for b in button_fg,button_bg:
            b.pack(side=TOP, padx=10, pady=5, expand=YES, fill=X )

        self.all_widgets = ( frame, button_fg, button_bg )
Ejemplo n.º 15
0
 def __init__(self):
     l = """
     This window displays a string of text to demonstrate the text
     facilities of canvas widgets.  You can click in the boxes to
     adjust the position of the text relative to its positioning
     point or change its justification.  The text also supports
     the following simple bindings for editing:
     1. You can point, click, and type.
     2. You can also select with button 1.
     3. You can copy the selection to the mouse position with button 2.
     4. Backspace and Control+h delete the selection if there is one;
        otherwise they delete the character just before the insertion
        cursor.
     5. Delete deletes the selection if there is one; otherwise it deletes
        the character just after the insertion cursor.
     """
     DemoWindow.__init__(self,l, demo_path('canvastext.py') )
     self.canvas = TextDemoCanvas(self)
     self.canvas.pack(fill=BOTH, expand=Y)
Ejemplo n.º 16
0
    def __init__(self):

        l = """This demo shows you two ways of having
        a dialog to grab focus: local and global grab.
        Click on the relevant button and learn about
        the differences"""

        DemoWindow.__init__(self, l, demo_path('dialoggrab.py'))

        frame = Frame(self, relief=RIDGE, border=2)
        frame.pack(expand=YES, fill=BOTH)
        b1 = Button(frame,
                    text='Open dialog with local grab',
                    command=self.localgrab_callback)
        b2 = Button(frame,
                    text='Open dialog with global grab',
                    command=self.globalgrab_callback)
        for b in b1, b2:
            b.pack(side=LEFT, padx=5)
Ejemplo n.º 17
0
 def __init__(self):
     l = """
     This window displays a string of text to demonstrate the text
     facilities of canvas widgets.  You can click in the boxes to
     adjust the position of the text relative to its positioning
     point or change its justification.  The text also supports
     the following simple bindings for editing:
     1. You can point, click, and type.
     2. You can also select with button 1.
     3. You can copy the selection to the mouse position with button 2.
     4. Backspace and Control+h delete the selection if there is one;
        otherwise they delete the character just before the insertion
        cursor.
     5. Delete deletes the selection if there is one; otherwise it deletes
        the character just after the insertion cursor.
     """
     DemoWindow.__init__(self, l, demo_path('ctext.py'))
     self.canvas = TextDemoCanvas(self)
     self.canvas.pack(fill=BOTH, expand=Y)
Ejemplo n.º 18
0
    def __init__(self):
        l = """An arrow and an horizontal scale are
        displayed below.  If you click or drag
        mouse button 1 in the scale, you can
        change the size of the arrow."""
        DemoWindow.__init__(self, l, demo_path('hscale.py'))

        self.frame = Frame(self,width=550,height=300)
        self.frame.pack(expand=Y,fill=BOTH)

        self.scale = Scale(self.frame, orient='horizontal',
                           length=300,
                           from_=0, to_=250, tickinterval=50,
                           command=self.scale_callback )
        self.scale.pack(side=TOP,expand=Y, fill=Y,
                        padx=30)
        self.canvas = Canvas( self.frame, height=150, width=320 )
        self.canvas.pack(side=LEFT,expand=Y, fill=BOTH )
        options={'fill':'cyan', 'outline':'darkblue' }
        self.arrow = self.canvas.create_polygon( *self.arrow_points(50) )
        self.canvas.itemconfigure( self.arrow, options )
        self.scale.set(50)
Ejemplo n.º 19
0
    def __init__(self):
        l = """Enter a file name in the entry box or click on the
        \"Browse\" buttons to select a file name using the file
        selection dialog."""

        DemoWindow.__init__(self, l, demo_path('filebox.py'))

        frame = Frame(self)
        frame.pack(side=TOP, expand=YES, fill=BOTH)

        l1 = Label(frame, text='Select a file to open:')
        l2 = Label(frame, text='Select a file to save:')
        e1 = Entry(frame)
        self.e1 = e1
        e2 = Entry(frame)
        self.e2 = e2
        b1 = Button(frame, text='Browse...', command=self.selectopen_callback)
        b2 = Button(frame, text='Browse...', command=self.selectsave_callback)

        frame.rowconfigure(1, pad=10, weight=1)
        for r in (0, 1, 2):
            frame.columnconfigure(r, pad=5)

        # insert elements in the container
        rnum = 0
        for r in ((l1, e1, b1), (l2, e2, b2)):
            cnum = 0
            for w in r:
                w.grid(row=rnum, column=cnum)
                cnum = cnum + 1
            rnum = rnum + 1

        self.mvar = IntVar(self)
        mb = Checkbutton(self,
                         text='Use motif stile dialog',
                         variable=self.mvar,
                         command=self.changestyle_callback)
        mb.pack(side=TOP, expand=YES, fill=X)
Ejemplo n.º 20
0
    def __init__(self):

        l="""This window displays all of Tk's built-in bitmaps,
        along with the names you can use for them in  scripts.
        """

        DemoWindow.__init__(self,l, demo_path('builtinbitmaps.py'))

        frame=Frame(self);frame.pack(expand=YES, fill=BOTH, pady=10)

        list=( 'error', 'gray12', 'gray25', 'gray50', 'gray75',
               'hourglass', 'info', 'question', 'questhead', 'warning' )

        row=0; column=0
        for b in list:
            f = Frame(frame)
            l1=Label(f, bitmap=b ); l1.pack(side=TOP)
            l2=Label(f, text=b);l2.pack(side=BOTTOM)
            f.grid(row=row, column=column, sticky='ns', padx=10 )
            column=column+1;
            if column >= len(list)/2:
                row=row+1
                column=0
Ejemplo n.º 21
0
    def __init__(self):
        l = """This demonstration allows you to view images using a Tk "photo"
        image.  First type a directory name in the text entry, then type Return
        to load the directory into the listbox.
        Then double-click on a file name in the listbox to see that image.
        """
        DemoWindow.__init__(self,l,demo_path('image2.py'))

        frame=Frame(self);frame.pack(side=TOP,expand=YES,fill=BOTH)
        self.frame = frame
        
        #create the directory entry
        label_dir = Label(frame, text='Directory:')
        label_dir.pack(side=TOP, pady=5)
        self.entry_dir = Entry(frame)
        self.entry_dir.pack(side=TOP,expand=YES, fill=X )

        # define the callback to call when user enters <return> in the entry
        self.entry_dir.bind('<Return>', self.entry_callback )
            
        # create and pack the list of image files
        label_file = Label(frame, text='File:')
        label_file.pack(side=TOP, pady=10 )
        self.list_file = HScrollList(frame)
        self.list_file.pack(side=TOP, expand=YES, fill=X)

        self.list_file.list.bind('<Double-1>', self.list_callback )
        
        #create the label which contains the image and its title
        self.image_title = Label(frame, text='Image:')
        self.image_title.pack(side=TOP, pady=10 )
        self.image_label = Label(frame)
        self.image_label.pack(side=TOP )

        #pre-set interface to image subdirectory
        self.entry_dir.insert(0,'images')
        self.entry_callback()
Ejemplo n.º 22
0
    def __init__(self):
        l = """This demonstration allows you to view images using a Tk "photo"
        image.  First type a directory name in the text entry, then type Return
        to load the directory into the listbox.
        Then double-click on a file name in the listbox to see that image.
        """
        DemoWindow.__init__(self,l,demo_path('imageif.py'))

        frame=Frame(self);frame.pack(side=TOP,expand=YES,fill=BOTH)
        self.frame = frame
        
        #create the directory entry
        label_dir = Label(frame, text='Directory:')
        label_dir.pack(side=TOP, pady=5)
        self.entry_dir = Entry(frame)
        self.entry_dir.pack(side=TOP,expand=YES, fill=X )

        # define the callback to call when user enters <return> in the entry
        self.entry_dir.bind('<Return>', self.entry_callback )
            
        # create and pack the list of image files
        label_file = Label(frame, text='File:')
        label_file.pack(side=TOP, pady=10 )
        self.list_file = HScrollList(frame)
        self.list_file.pack(side=TOP, expand=YES, fill=X)

        self.list_file.list.bind('<Double-1>', self.list_callback )
        
        #create the label which contains the image and its title
        self.image_title = Label(frame, text='Image:')
        self.image_title.pack(side=TOP, pady=10 )
        self.image_label = Label(frame)
        self.image_label.pack(side=TOP )

        #pre-set interface to image subdirectory
        self.entry_dir.insert(0,'images')
        self.entry_callback()
Ejemplo n.º 23
0
    def __init__(self):
        DemoWindow.__init__(self, '', demo_path('twind.py') )

        frame = Frame(self); frame.pack(expand=Y, fill=BOTH )
        self.frame=frame
        frame.rowconfigure(0, weight=1 )
        frame.columnconfigure(0, weight=1 )
        self.text=Text(frame, relief=SUNKEN, bd=2, setgrid=1,
                  wrap='word', height=35);
        self.text.grid(row=0,column=0, sticky='nsew')
        bar=Scrollbar(frame); bar.grid(row=0,column=1,sticky='nsew')
        self.text['yscrollcommand']=bar.set; bar['command']=self.text.yview

        self.hscroll = None # preset is needed because it is checked in the
        self.plot = None    # callbacks

        #these are the buttons which will be embedded in the text
        self.b_turnon = Button(self.text, text='Turn On', cursor='top_left_arrow',
                               command = self.turnon_callback )
        self.b_turnoff = Button( self.text, text='Turn Off',
                                 cursor='top_left_arrow',
                                 command=self.turnoff_callback )
        self.b_clickhere = Button(self.text,  text='Click Here',
                                  cursor='top_left_arrow',
                                 command=self.clickhere_callback )
        self.b_delete = Button( self.text,text='Delete',
                                cursor='top_left_arrow',
                                 command=self.delete_callback )

        # insert text and embedding buttons
        self.text.insert(END,
                         "A text widget can contain other widgets embedded "+
                         "in it.  These are called \"embedded windows\", "+
                         "and they can consist of arbitrary widgets.  "+
                         "For example, here are two embedded button "+
                         "widgets.  You can click on the first button to " )
        self.text.window_create(END, window=self.b_turnon )
        self.text.insert(END,
                         " horizontal scrolling, which also turns off "+
                         "word wrapping.  Or, you can click on the second "+
                         "button to " )
        self.text.window_create(END, window=self.b_turnoff )
        self.text.insert(END,
                    "horizontal scrolling and turn back on word wrapping.\n\n" 
                         )
        self.text.insert(END,
                         "Or, here is another example.  If you ")
        self.text.window_create(END, window=self.b_clickhere )
        self.text.insert(END,
                         "a canvas displaying an x-y plot will appear right "+
                         "here." )

        # insert a mark where the plot window shall be inserted
        self.text.mark_set('plot', INSERT )
        self.text.mark_gravity('plot', LEFT)
        
        self.text.insert(END,
                         "\nYou can drag the data points around with "+
                         "the mouse, or you can click here to ")
        self.text.window_create(END, window=self.b_delete )
        self.text.insert(END, " the plot again.\n\n")

        
        self.text.insert(
            END,
            "You may also find it useful to put embedded windows in "
            "a text without any actual text.  In this case the "+
            "text widget acts like a geometry manager.  For "+
            "example, here is a collection of buttons laid out "+
            "neatly into rows by the text widget.  These buttons "+
            "can be used to change the background color of the "+
            "text widget (\"Default\" restores the color to "+
            "its default).  If you click on the button labeled "+
            "\"Short\", it changes to a longer string so that "+
            "you can see how the text widget automatically "+
            "changes the layout.  Click on the button again "+
            "to restore the short string.\n" )

        self.var = StringVar(self.text)
        self.var.set('Short')
        tb = Checkbutton( self.text, indicatoron=0,
                          textvariable=self.var,
                          variable=self.var,
                          offvalue='Short',
                          onvalue='A much longer string',
                          cursor='top_left_arrow',
                          padx=2, pady=4)
        self.text.window_create(END, window=tb )
        
        colors = ( 'AntiqueWhite3', 'Bisque1', 'Bisque2', 'Bisque3', 'Bisque4',
	'SlateBlue3', 'RoyalBlue1', 'SteelBlue2', 'DeepSkyBlue3', 'LightBlue1',
	'DarkSlateGray1', 'Aquamarine2', 'DarkSeaGreen2', 'SeaGreen1',
	'Yellow1', 'IndianRed1', 'IndianRed2', 'Tan1', 'Tan4' )

        c = self.text['background']
        db = Button(self.text, text='Default', background=c,
                    command=callit(self.button_callback, c ),
                    cursor = 'top_left_arrow' )
        self.text.window_create(END, window=db)
                    
        for c in colors:
            b = Button(self.text, text=c, background=c,
                       padx=2, pady=4,
                       cursor='top_left_arrow',
                       command=callit(self.button_callback, c ))
            self.text.window_create(END, window=b)
Ejemplo n.º 24
0
from infrastructure import DemoWindow, demo_path


RULER_UNITS = 10
RULER_TICKS = 4*RULER_UNITS

RULER_LENGTH=400
TICK_LENGTH = RULER_LENGTH//RULER_TICKS
RULER_START=30
RULER_END=RULER_START+RULER_LENGTH

TAB_Y = 60


STIPPLE_BITMAP_FILE=demo_path('images/gray25.bmp')

#
# Note : for some reason, this generates TclError 'bitmap XXXX not defined'
# when used either direcly or via 'name' attribute, so I used raw tk commands
# instead
#
# STIPPLE_BITMAP = BitmapImage(master=Tk(),file=STIPPLE_BITMAP_FILE)
#


#
# Note : to execute the Tk command, I need to create a Toplevel window
# I guess I could use the toplevel create in widget.py, buth then this
# module would not run stand-alone
#
Ejemplo n.º 25
0
    def hook_create_menubar(self):

        self.mbar = Menu(self, type='menubar')
        self['menu'] = self.mbar

        # create the 'File' menu
        menu = Menu(self.mbar, tearoff=0)
        self.mbar.add_cascade(label='File', underline=0, menu=menu)
        menu.add_command(label='0pen...',
                         underline=0,
                         command=callit(self.dummy_callback, 'Open'))
        menu.add_command(label='New',
                         underline=0,
                         command=callit(self.dummy_callback, 'New'))
        menu.add_command(label='Save',
                         underline=0,
                         command=callit(self.dummy_callback, 'Save'))
        menu.add_command(label='Save As ...',
                         underline=5,
                         command=callit(self.dummy_callback, 'Save As'))
        menu.add_separator()
        menu.add_command(label='Print',
                         underline=0,
                         command=callit(self.dummy_callback, 'Print'))
        menu.add_command(label='Print Setup ...',
                         underline=5,
                         command=callit(self.dummy_callback, 'Print Setup'))
        menu.add_separator()
        menu.add_command(label='Dismiss',
                         underline=0,
                         command=self.dismiss_callback)

        # create the basic menu
        menu = Menu(self.mbar, tearoff=0)
        self.mbar.add_cascade(label='Basic', underline=0, menu=menu)
        menu.add_command(label='Long entry which does nothing')
        for l in ('A', 'B', 'C', 'D', 'E', 'F'):
            menu.add_command(label='Print letter "%s"' % l,
                             accelerator='%s+%s' % (ACCEL_KEY, l),
                             command=callit(self.printletter_callback, l))

        # create the 'Cascades' menu
        menu = Menu(self.mbar, tearoff=0)
        self.mbar.add_cascade(label='Cascades', underline=0, menu=menu)
        menu.add_command(label='Print Hello',
                         accelerator='%s+%s' % (ACCEL_KEY, 'H'),
                         command=callit(self.print_callback, "Hello!"))
        menu.add_command(label='Print Goodby',
                         accelerator='%s+%s' % (ACCEL_KEY, 'G'),
                         command=callit(self.print_callback, "Goodby!"))

        # add check buttons sub-menu
        cb_menu = Menu(menu, tearoff=0)
        self.vars = {}
        labels = ('Oil checked', 'Transmission checked', 'Brakes checked',
                  'Lights checked')
        for l in labels:
            self.vars[l] = IntVar(self)
            cb_menu.add_checkbutton(label=l, variable=self.vars[l])
        cb_menu.add_separator()
        cb_menu.add_command(label='Show variables',
                            command=callit(self.showvars_callback, labels))
        menu.add_cascade(label='Check buttons', underline=0, menu=cb_menu)

        # add radio-buttons sub-menu
        cb_menu = Menu(menu, tearoff=0)
        self.vars['size'] = StringVar(self)
        self.vars['font'] = StringVar(self)
        for l in (10, 14, 18, 24, 32):
            cb_menu.add_radiobutton(label='l' + ' points',
                                    variable=self.vars['size'])
        cb_menu.add_separator()
        for l in ('Roman', 'Bold', 'Italic'):
            cb_menu.add_radiobutton(label=l, variable=self.vars['font'])
        cb_menu.add_separator()
        cb_menu.add_command(label='Show variables',
                            command=callit(self.showvars_callback,
                                           ('size', 'font')))
        menu.add_cascade(label='Radio buttons', underline=0, menu=cb_menu)

        # add 'Icons' menu
        menu = Menu(self.mbar, tearoff=0)
        self.mbar.add_cascade(label='Icons', underline=0, menu=menu)
        for b in ('@' + demo_path('images', 'pattern.bmp'), 'info',
                  'questhead', 'error'):
            menu.add_command(bitmap=b,
                             hidemargin=1,
                             command=self.icon_callback)
        menu.entryconfigure(2, columnbreak=1)

        # add 'More' menu
        menu = Menu(self.mbar, tearoff=0)
        self.mbar.add_cascade(label='More', underline=0, menu=menu)
        for l in ('An entry', 'Another entry', 'Does nothing',
                  'Just turn thumbs', 'Save the world', 'Armageddon'):
            menu.add_command(label=l,
                             command=callit(self.youselected_callback, l))

        # And, finally, add the colors menu
        menu = Menu(self.mbar, tearoff=1)
        self.mbar.add_cascade(label='Colors', underline=2, menu=menu)
        for l in ('red', 'green', 'blue', 'yellow', 'cyan', 'orange', 'brown'):
            menu.add_command(label=l,
                             background=l,
                             command=callit(self.color_callback, l))

        # bind menu entry selection event
        # ?? Why it does not work for Menubuton selection ??
        # (the tk demo does it)
        self.bind_class('Menu', '<<MenuSelect>>', self.entryselect_callback)
        self.bind_class('Menubutton', '<<MenuSelect>>',
                        self.entryselect_callback)
Ejemplo n.º 26
0
    def __init__(self):
        DemoWindow.__init__(self, '', demo_path('twind.py'))

        frame = Frame(self)
        frame.pack(expand=Y, fill=BOTH)
        self.frame = frame
        frame.rowconfigure(0, weight=1)
        frame.columnconfigure(0, weight=1)
        self.text = Text(frame,
                         relief=SUNKEN,
                         bd=2,
                         setgrid=1,
                         wrap='word',
                         height=35)
        self.text.grid(row=0, column=0, sticky='nsew')
        bar = Scrollbar(frame)
        bar.grid(row=0, column=1, sticky='nsew')
        self.text['yscrollcommand'] = bar.set
        bar['command'] = self.text.yview

        self.hscroll = None  # preset is needed because it is checked in the
        self.plot = None  # callbacks

        #these are the buttons which will be embedded in the text
        self.b_turnon = Button(self.text,
                               text='Turn On',
                               cursor='top_left_arrow',
                               command=self.turnon_callback)
        self.b_turnoff = Button(self.text,
                                text='Turn Off',
                                cursor='top_left_arrow',
                                command=self.turnoff_callback)
        self.b_clickhere = Button(self.text,
                                  text='Click Here',
                                  cursor='top_left_arrow',
                                  command=self.clickhere_callback)
        self.b_delete = Button(self.text,
                               text='Delete',
                               cursor='top_left_arrow',
                               command=self.delete_callback)

        # insert text and embedding buttons
        self.text.insert(
            END, "A text widget can contain other widgets embedded " +
            "in it.  These are called \"embedded windows\", " +
            "and they can consist of arbitrary widgets.  " +
            "For example, here are two embedded button " +
            "widgets.  You can click on the first button to ")
        self.text.window_create(END, window=self.b_turnon)
        self.text.insert(
            END, " horizontal scrolling, which also turns off " +
            "word wrapping.  Or, you can click on the second " + "button to ")
        self.text.window_create(END, window=self.b_turnoff)
        self.text.insert(
            END, "horizontal scrolling and turn back on word wrapping.\n\n")
        self.text.insert(END, "Or, here is another example.  If you ")
        self.text.window_create(END, window=self.b_clickhere)
        self.text.insert(
            END,
            "a canvas displaying an x-y plot will appear right " + "here.")

        # insert a mark where the plot window shall be inserted
        self.text.mark_set('plot', INSERT)
        self.text.mark_gravity('plot', LEFT)

        self.text.insert(
            END, "\nYou can drag the data points around with " +
            "the mouse, or you can click here to ")
        self.text.window_create(END, window=self.b_delete)
        self.text.insert(END, " the plot again.\n\n")

        self.text.insert(
            END, "You may also find it useful to put embedded windows in "
            "a text without any actual text.  In this case the " +
            "text widget acts like a geometry manager.  For " +
            "example, here is a collection of buttons laid out " +
            "neatly into rows by the text widget.  These buttons " +
            "can be used to change the background color of the " +
            "text widget (\"Default\" restores the color to " +
            "its default).  If you click on the button labeled " +
            "\"Short\", it changes to a longer string so that " +
            "you can see how the text widget automatically " +
            "changes the layout.  Click on the button again " +
            "to restore the short string.\n")

        self.var = StringVar(self.text)
        self.var.set('Short')
        tb = Checkbutton(self.text,
                         indicatoron=0,
                         textvariable=self.var,
                         variable=self.var,
                         offvalue='Short',
                         onvalue='A much longer string',
                         cursor='top_left_arrow',
                         padx=2,
                         pady=4)
        self.text.window_create(END, window=tb)

        colors = ('AntiqueWhite3', 'Bisque1', 'Bisque2', 'Bisque3', 'Bisque4',
                  'SlateBlue3', 'RoyalBlue1', 'SteelBlue2', 'DeepSkyBlue3',
                  'LightBlue1', 'DarkSlateGray1', 'Aquamarine2',
                  'DarkSeaGreen2', 'SeaGreen1', 'Yellow1', 'IndianRed1',
                  'IndianRed2', 'Tan1', 'Tan4')

        c = self.text['background']
        db = Button(self.text,
                    text='Default',
                    background=c,
                    command=callit(self.button_callback, c),
                    cursor='top_left_arrow')
        self.text.window_create(END, window=db)

        for c in colors:
            b = Button(self.text,
                       text=c,
                       background=c,
                       padx=2,
                       pady=4,
                       cursor='top_left_arrow',
                       command=callit(self.button_callback, c))
            self.text.window_create(END, window=b)
Ejemplo n.º 27
0
    def hook_create_menubar(self):

        self.mbar = Menu(self, type='menubar')
        self['menu'] = self.mbar

        # create the 'File' menu
        menu = Menu(self.mbar, tearoff=0)
        self.mbar.add_cascade(label='File', underline=0, menu=menu )
        menu.add_command(label='0pen...', underline=0,
                         command=callit(self.dummy_callback,'Open'))
        menu.add_command(label='New', underline=0,
                         command=callit(self.dummy_callback,'New'))
        menu.add_command(label='Save', underline=0,
                         command=callit(self.dummy_callback,'Save'))
        menu.add_command(label='Save As ...', underline=5,
                         command=callit(self.dummy_callback,'Save As'))
        menu.add_separator()
        menu.add_command(label='Print', underline=0,
                         command=callit(self.dummy_callback,'Print'))
        menu.add_command(label='Print Setup ...', underline=5,
                         command=callit(self.dummy_callback,'Print Setup'))
        menu.add_separator()
        menu.add_command(label='Dismiss', underline=0,
                         command=self.dismiss_callback)


        # create the basic menu
        menu = Menu(self.mbar, tearoff=0 )
        self.mbar.add_cascade(label='Basic', underline=0, menu=menu)        
        menu.add_command(label='Long entry which does nothing')
        for l in ('A','B','C','D','E', 'F'):
            menu.add_command(label='Print letter "%s"'%l,
                             accelerator='%s+%s'%(ACCEL_KEY,l),
                             command=callit(self.printletter_callback, l ))
        
        # create the 'Cascades' menu
        menu = Menu(self.mbar, tearoff=0 )
        self.mbar.add_cascade(label='Cascades', underline=0, menu=menu)
        menu.add_command(label='Print Hello',
                         accelerator='%s+%s'%(ACCEL_KEY,'H'),
                         command=callit(self.print_callback, "Hello!"))
        menu.add_command(label='Print Goodby',
                         accelerator='%s+%s'%(ACCEL_KEY,'G'),
                         command=callit(self.print_callback, "Goodby!"))



        # add check buttons sub-menu
        cb_menu = Menu(menu,tearoff=0)
        self.vars={}
        labels = ('Oil checked', 'Transmission checked',
                  'Brakes checked', 'Lights checked' )
        for l in labels:
            self.vars[l]=IntVar(self)
            cb_menu.add_checkbutton(label=l,
                                    variable=self.vars[l] )
        cb_menu.add_separator()
        cb_menu.add_command(label='Show variables',
                            command=callit(self.showvars_callback,
                                           labels ) )
        menu.add_cascade(label='Check buttons', underline=0,
                         menu=cb_menu)

        # add radio-buttons sub-menu
        cb_menu=Menu(menu,tearoff=0)
        self.vars['size'] = StringVar(self)
        self.vars['font'] = StringVar(self)
        for l in (10,14,18,24,32):
              cb_menu.add_radiobutton(label='l'+' points',
                                      variable=self.vars['size'] )
        cb_menu.add_separator()
        for l in ('Roman','Bold','Italic'):
              cb_menu.add_radiobutton(label=l,
                                      variable=self.vars['font'] )
        cb_menu.add_separator()
        cb_menu.add_command(label='Show variables',
                            command=callit(self.showvars_callback,
                                           ('size', 'font') ))
        menu.add_cascade(label='Radio buttons', underline=0,
                         menu=cb_menu)

        # add 'Icons' menu
        menu = Menu(self.mbar, tearoff=0)
        self.mbar.add_cascade(label='Icons', underline=0, menu=menu)
        for b in ( '@'+demo_path('images','pattern.bmp'),
                   'info', 'questhead', 'error' ):
            menu.add_command(bitmap=b, hidemargin=1,
                           command=self.icon_callback )
        menu.entryconfigure(2,columnbreak=1)
                           

        # add 'More' menu
        menu = Menu(self.mbar, tearoff=0)
        self.mbar.add_cascade(label='More', underline=0, menu=menu)
        for l in ( 'An entry', 'Another entry', 'Does nothing',
                   'Just turn thumbs' , 'Save the world',
                   'Armageddon'):
            menu.add_command(label=l,
                             command=callit(self.youselected_callback,l))
        

        # And, finally, add the colors menu
        menu = Menu(self.mbar, tearoff=1)
        self.mbar.add_cascade(label='Colors', underline=2, menu=menu)
        for l in ( 'red','green', 'blue', 'yellow', 'cyan', 'orange', 'brown'):
            menu.add_command(label=l,
                             background=l,
                             command=callit(self.color_callback,l))


        # bind menu entry selection event
        # ?? Why it does not work for Menubuton selection ??
        # (the tk demo does it)
        self.bind_class('Menu', '<<MenuSelect>>', self.entryselect_callback )
        self.bind_class('Menubutton', '<<MenuSelect>>', self.entryselect_callback )
Ejemplo n.º 28
0
from infrastructure import DemoWindow, demo_path


RULER_UNITS = 10
RULER_TICKS = 4*RULER_UNITS

RULER_LENGTH=400
TICK_LENGTH = RULER_LENGTH//RULER_TICKS
RULER_START=30
RULER_END=RULER_START+RULER_LENGTH

TAB_Y = 60


STIPPLE_BITMAP_FILE=demo_path('images/gray25.bmp')

#
# Note : for some reason, this generates TclError 'bitmap XXXX not defined'
# when used either direcly or via 'name' attribute, so I used raw tk commands
# instead
#
# STIPPLE_BITMAP = BitmapImage(master=Tk(),file=STIPPLE_BITMAP_FILE)
#


#
# Note : to execute the Tk command, I need to create a Toplevel window
# I guess I could use the toplevel create in widget.py, buth then this
# module would not run stand-alone
#
Ejemplo n.º 29
0
    def __init__(self):
        l = """This is a demonstration of menubuttons. The \"Below\"
        menubutton pops its menu below the button; the \"Right\"
        button pops to the right, etc. There are two option menus
        directly below this text; one is just a standard menu and
        the other is a 16-color palette.
        """
        DemoWindow.__init__(self, l, demo_path('menubu.py'))

        frame = Frame(self)
        frame.pack(expand=YES, fill=BOTH)
        frame.rowconfigure(1, weight=1, pad=120)
        frame.columnconfigure(1, weight=1, pad=120)

        #create the 'number' option menu in the middle
        middleframe = Frame(frame)
        middleframe.grid(row=1, column=1)
        var_numbers = StringVar(middleframe)
        var_numbers.set('One')
        om_numbers = OptionMenu(middleframe, var_numbers, 'One', 'Two',
                                'Three')
        om_numbers.pack(side=LEFT, padx=10)

        #create the 'color' optionmenu in the middle
        colors = ('Black', 'red4', 'DarkGreen', 'NavyBlue', 'gray75', 'Red',
                  'Green', 'Blue', 'gray50', 'Yellow', 'Cyan', 'Magenta',
                  'White', 'Brown', 'DarkSeaGreen', 'DarkViolet')
        var_colors = StringVar(middleframe)
        var_colors.set(colors[0])
        var_colors.trace_variable('w', self.colorsupdate_callback)
        om_colors = apply(OptionMenu, (middleframe, var_colors) + colors)
        om_colors['menu'].entryconfigure(len(colors) / 3, columnbreak=1)
        om_colors['menu'].entryconfigure(2 * len(colors) / 3 + 1,
                                         columnbreak=1)
        om_colors.pack(side=RIGHT, padx=10)
        print(om_colors)
        print(om_colors['menu'])
        # set images for color menu options
        self.images = []
        for i in range(0, len(colors)):
            img = PhotoImage(name='image_' + colors[i], height=16, width=16)
            self.images.append(img)  # images shall live as long as the menu
            img.put(colors[i], to=(0, 0, 15, 15))
            om_colors['menu'].entryconfigure(i, image=img)

        # for some reason, if this is done before the above loop,
        # the menu entries lose the 'image' property
        # Also the tk demo does this at the end
        om_colors['menu'].configure(tearoff=1)

        # store vars needed for callbacks
        self.var_colors = var_colors
        self.om_colors = om_colors

        #create the four menu buttons at the edge of the frame
        for text, direction, row, column, sticky in (('Above', 'above', 2, 1,
                                                      's'), ('Below', 'below',
                                                             0, 1, 'n'),
                                                     ('Left', 'left', 1, 0,
                                                      'w'), ('Right', 'right',
                                                             1, 2, 'e')):
            mb = Menubutton(frame,
                            text=text,
                            underline=0,
                            relief=RAISED,
                            direction=direction)
            menu = Menu(mb, tearoff=0)
            mb['menu'] = menu
            menu.add_command(label=text + ' menu first option',
                             underline=len(text) + 1)
            menu.add_command(label=text + ' menu second option',
                             underline=len(text) + 1)
            mb.grid(row=row, column=column, sticky=sticky)
Ejemplo n.º 30
0
    def __init__(self):
        l = """This is a demonstration of menubuttons. The \"Below\"
        menubutton pops its menu below the button; the \"Right\"
        button pops to the right, etc. There are two option menus
        directly below this text; one is just a standard menu and
        the other is a 16-color palette.
        """
        DemoWindow.__init__(self,l,demo_path('menubuttons.py'))

        frame= Frame(self);frame.pack( expand=YES, fill=BOTH )
        frame.rowconfigure(1,weight=1, pad=120)
        frame.columnconfigure(1,weight=1,pad=120)

        #create the 'number' option menu in the middle
        middleframe = Frame(frame);middleframe.grid(row=1,column=1)
        var_numbers=StringVar(middleframe);var_numbers.set('One')
        om_numbers= OptionMenu(middleframe,var_numbers,
                               'One', 'Two', 'Three')
        om_numbers.pack(side=LEFT, padx=10)

        #create the 'color' optionmenu in the middle
        colors = ('Black', 'red4', 'DarkGreen', 'NavyBlue',
                  'gray75', 'Red', 'Green', 'Blue', 'gray50',
                  'Yellow', 'Cyan', 'Magenta', 'White',
                  'Brown', 'DarkSeaGreen', 'DarkViolet' )
        var_colors=StringVar(middleframe);var_colors.set(colors[0])
        var_colors.trace_variable('w', self.colorsupdate_callback )
        om_colors=apply( OptionMenu, (middleframe,var_colors)+colors )
        om_colors['menu'].entryconfigure(len(colors)/3, columnbreak=1)
        om_colors['menu'].entryconfigure(2*len(colors)/3+1, columnbreak=1)      
        om_colors.pack(side=RIGHT,padx=10)
        print `om_colors`
        print `om_colors['menu']`
        # set images for color menu options
        self.images=[]
        for i in range(0,len(colors)):
            img = PhotoImage(name='image_'+colors[i],
                             height=16,width=16)
            self.images.append(img) # images shall live as long as the menu
            img.put(colors[i], to=(0,0,15,15))
            om_colors['menu'].entryconfigure(i, image=img )

        # for some reason, if this is done before the above loop,
        # the menu entries lose the 'image' property
        # Also the tk demo does this at the end
        om_colors['menu'].configure(tearoff=1)        

        # store vars needed for callbacks
        self.var_colors=var_colors
        self.om_colors=om_colors 
        
        #create the four menu buttons at the edge of the frame
        for text,direction,row,column,sticky in (
            ('Above','above',2,1,'s'),
            ('Below','below',0,1,'n'),
            ('Left','left',1,0,'w'),
            ('Right','right',1,2,'e')):
            mb=Menubutton(frame, text=text, underline=0,
                          relief=RAISED, direction=direction )
            menu = Menu(mb, tearoff=0)
            mb['menu']= menu
            menu.add_command(label=text+' menu first option',
                             underline=len(text)+1)
            menu.add_command(label=text+ ' menu second option',
                             underline=len(text)+1)
            mb.grid(row=row,column=column,sticky=sticky)