Re: Muti-column menu (cont)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Muti-column menu (cont)

Bugzilla from Vasilis.Vlachoudis@cern.ch
Is it possible to have a separator line extending both columns (something like columnspan=2).
If I add two separators, the first one appears ok while the second appears like a dot.

from Tkinter import *

def showMenu(event=None):
        menu = Menu(tk,tearoff=0)

        menu.add_command(label="PLA")
        menu.add_command(label="XZP")
        menu.add_separator()
        menu.add_command(label="RPP")
        menu.add_command(label="WED")
        menu.add_separator()
        menu.add_command(label="SPH")
        menu.add_separator()
        menu.add_command(label="RCC")
        menu.add_command(label="XCC")
        menu.add_command(label="YCC")
        menu.add_command(label="ZCC")
        menu.add_command(label="TRC")
        menu.add_separator()
        menu.add_command(label="ARB")
        menu.add_command(label="TRX")
        menu.add_command(label="TRZ")

        menu.add_command(label="XYP")
        menu.add_command(label="YZP")
        menu.add_separator()
        menu.add_command(label="BOX")
        menu.add_command(label="RAW")
        menu.add_separator()
        menu.add_command(label="ELL")
        menu.add_separator()
        menu.add_command(label="REC")
        menu.add_command(label="XEC")
        menu.add_command(label="YEC")
        menu.add_command(label="ZEC")
        menu.add_separator()
        menu.add_separator()
        menu.add_command(label="QUA")
        menu.add_command(label="TRY")

        menu.entryconfigure(17,columnbreak=1)

        menu.tk_popup(tk.winfo_pointerx(), tk.winfo_pointery())

tk = Tk()
tk.bind("<3>",showMenu)
tk.mainloop()



Vasilis

________________________________________
From: Vasilis Vlachoudis
Sent: 03 November 2011 11:48
To: Michael Lange; [hidden email]
Subject: RE: [Tkinter-discuss] Muti-column menu

Thank you very much.
Exactly what I was looking for.
Vasilis

________________________________________
From: tkinter-discuss-bounces+vasilis.vlachoudis=[hidden email] [tkinter-discuss-bounces+vasilis.vlachoudis=[hidden email]] on behalf of Michael Lange [[hidden email]]
Sent: 03 November 2011 11:36
To: [hidden email]
Subject: Re: [Tkinter-discuss] Muti-column menu

Hi Vasilis,

Thus spoketh Vasilis Vlachoudis <[hidden email]>
unto us on Wed, 2 Nov 2011 20:51:43 +0000:

> Hi All,
>
> in my application I have a submenu (appearing both on the menu bar and
> with right-click) that contains many entries ~30. But it has to be in
> one submenu since they are various types of geometrical bodies to
> insert. Is there a way to create a multi-column sub-menu in Tkinter?
>

Yes, all you need to do is

    menu.entryconfigure(i, columnbreak=1)

where i is the index number of the menu item that will appear at the top
of a new column.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

No one can guarantee the actions of another.
                -- Spock, "Day of the Dove", stardate unknown
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Muti-column menu (cont)

Michael Lange
Hi,

Thus spoketh Vasilis Vlachoudis <[hidden email]>
unto us on Thu, 3 Nov 2011 11:11:54 +0000:

> Is it possible to have a separator line extending both columns
> (something like columnspan=2). If I add two separators, the first one
> appears ok while the second appears like a dot.
>

The same here, seems like you cannot create a separator line in the
second column at all. I have no idea why, I thought this was supposed to
work.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Lots of people drink from the wrong bottle sometimes.
                -- Edith Keeler, "The City on the Edge of Forever",
                   stardate unknown
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Button-press on Menubuttons

Cam Farnell-2
I have a bunch of Menubuttons in my application, lets call them A, B and C.

Each Menubutton is bound to <ButtonPress-1> so, before the menu choices are displayed, I can enable/disable some of those choices depending on the situation at the time, and each binding leads to its own Menubutton-specific handler.

If the user clicks on Menubutton-A then the corresponding handler runs as expected. If, without making a choice from menu A, the user then clicks on Menubutton-B then - and this is the nub of the problem - the handler bound to Menubutton-B does NOT run. If the user now clicks on Menubutton-C, then the handler for B, yes B, runs.

Is this a bug, a feature or me being stupid? I'm running Python 2.6.5 on Ubuntu 10.04. The simplest demonstration example I could manage follows. Clicking on Menubutton A shows, in the label to the right of the Menubuttons, that the handler ran. If you then click immediately (without selecting any of the dummy menu choices or otherwise making the open menu go away) on Menubutton B then the handler does not run. If you then click on Menubutton A (or for that, click again in Menubutton B) then the handler for B runs.

I've already developed a workaround for my particular application, but this strikes me as anomalous behavior.

Cheers

Cam Farnell

import Tkinter as tk

class Application(tk.Frame):
     def __init__(self, master=None):
         tk.Frame.__init__(self, master)
         self.pack()

         self.MenuButtonA = tk.Menubutton(self,text='Menu Button A')
         self.MenuButtonA.pack(side='left')
         T = tk.Menu(self.MenuButtonA)
         T.add_command(label='Dummy 1')
         T.add_command(label='Dummy 2')
         self.MenuButtonA['menu'] = T
         self.MenuButtonA.bind('<ButtonPress-1>',self.HandlerA)

         self.MenuButtonB = tk.Menubutton(self,text='Menu Button B')
         self.MenuButtonB.pack(side='left')
         T = tk.Menu(self.MenuButtonB)
         T.add_command(label='Dummy 1')
         T.add_command(label='Dummy 2')
         self.MenuButtonB['menu'] = T
         self.MenuButtonB.bind('<ButtonPress-1>',self.HandlerB)

         self.InfoLabel = tk.Label(self,text='---------')
         self.InfoLabel.pack(side='left')

     def HandlerA(self,Event):
         self.InfoLabel['text'] = 'Handler A'
         
     def HandlerB(self,Event):
         self.InfoLabel['text'] = 'Handler B'

app = Application()
app.master.title("Sample application")
app.mainloop()




_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Button-press on Menubuttons

Michael Lange
Hi,

Thus spoketh Cam Farnell <[hidden email]>
unto us on Sat, 26 Nov 2011 12:54:09 -0400:

(..)
>
> If the user clicks on Menubutton-A then the corresponding handler runs
> as expected. If, without making a choice from menu A, the user then
> clicks on Menubutton-B then - and this is the nub of the problem - the
> handler bound to Menubutton-B does NOT run. If the user now clicks on
> Menubutton-C, then the handler for B, yes B, runs.

Not sure, I guess this has something to do with the Menu's event-grabbing.
Maybe a better solution than binding to the Menubuttons is to use the
menu's postcommand option as in:

import Tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.pack()

        self.MenuButtonA = tk.Menubutton(self,text='Menu Button A')
        self.MenuButtonA.pack(side='left')
        self.TA = TA = tk.Menu(self.MenuButtonA)
        TA.add_command(label='Dummy 1')
        TA.add_command(label='Dummy 2')
        self.MenuButtonA['menu'] = TA
        TA.config(postcommand=self.HandlerA)

        self.MenuButtonB = tk.Menubutton(self,text='Menu Button B')
        self.MenuButtonB.pack(side='left')
        self.TB = TB = tk.Menu(self.MenuButtonB)
        TB.add_command(label='Dummy 1')
        TB.add_command(label='Dummy 2')
        self.MenuButtonB['menu'] = TB
        TB.config(postcommand=self.HandlerB)

        self.InfoLabel = tk.Label(self,text='---------')
        self.InfoLabel.pack(side='left')

    def HandlerA(self,Event=None):
        self.InfoLabel['text'] = 'Handler A'
        print 'Handler A'
        self.TA.entryconfigure(1, label='FOO')

    def HandlerB(self,Event=None):
        self.InfoLabel['text'] = 'Handler B'
        print 'Handler B'
        self.TB.entryconfigure(1, state='disabled')

app = Application()
app.master.title("Sample application")
app.mainloop()

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

We fight only when there is no other choice.  We prefer the ways of
peaceful contact.
                -- Kirk, "Spectre of the Gun", stardate 4385.3
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Button-press on Menubuttons

Cam Farnell-2
Thanks, using the postcommand option does the job but it still strikes me as odd that a menubutton which has been been activated by clicking on it doesn't generate a <ButtonPress> event.

Cam

On 11-11-26 02:37 PM, Michael Lange wrote:

> Hi,
>
> Thus spoketh Cam Farnell<[hidden email]>
> unto us on Sat, 26 Nov 2011 12:54:09 -0400:
>
> (..)
>>
>> If the user clicks on Menubutton-A then the corresponding handler runs
>> as expected. If, without making a choice from menu A, the user then
>> clicks on Menubutton-B then - and this is the nub of the problem - the
>> handler bound to Menubutton-B does NOT run. If the user now clicks on
>> Menubutton-C, then the handler for B, yes B, runs.
>
> Not sure, I guess this has something to do with the Menu's event-grabbing.
> Maybe a better solution than binding to the Menubuttons is to use the
> menu's postcommand option as in:
>
<snip>
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Button-press on Menubuttons

Michael Lange
Thus spoketh Cam Farnell <[hidden email]>
unto us on Sat, 26 Nov 2011 15:54:51 -0400:

> Thanks, using the postcommand option does the job but it still strikes
> me as odd that a menubutton which has been been activated by clicking
> on it doesn't generate a <ButtonPress> event.
>

Now, I guess what actually happens is this:

when Menu A is being mapped it does a grab_set_global() behind the
scenes, which is useful, because it needs to be aware if the user clicks
for example on the desktop and as a consequence of this the menu must be
unmapped. There is no other way for tk to know this than the global grab.
Now when you click Menubutton B with Menu A still being mapped, the
ButtonPress event is actually being grabbed by Menu A.

Right now I can see the same behavior if I run your test app on top of
my mail client's window: when I click into the mail client while
Menu A is mapped, the menu disappears but the test app stays on top of
the mail client, which is perfectly normal in this context, it would be
confusing if the test app would be hidden under the other window on the
first mouse click when I just want to "click away" the menu. It seems
like it is exactly the same which now confuses you; probably the tk
developers decided that it's better to confuse programmers than users ;)

Maybe what happens becomes clearer if you add a few additional
callbacks with print statements to your example :

#######################
import Tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.pack()

        self.MenuButtonA = tk.Menubutton(self,text='Menu Button A')
        self.MenuButtonA.pack(side='left')
        self.TA = TA = tk.Menu(self.MenuButtonA)
        TA.add_command(label='Dummy 1')
        TA.add_command(label='Dummy 2')
        self.MenuButtonA['menu'] = TA
        #TA.config(postcommand=self.HandlerA)
        self.MenuButtonA.bind('<ButtonPress-1>',self.HandlerA, '+')
        TA.bind('<Map>', self.on_map_A, '+')
        TA.bind('<Unmap>', self.on_unmap_A, '+')
        self.MenuButtonA.bind('<ButtonPress-1>',self.on_b1_A, '+')
        self.MenuButtonA.bind('<ButtonRelease-1>',self.on_b1release_A, '+')


        self.MenuButtonB = tk.Menubutton(self,text='Menu Button B')
        self.MenuButtonB.pack(side='left')
        self.TB = TB = tk.Menu(self.MenuButtonB)
        TB.add_command(label='Dummy 1')
        TB.add_command(label='Dummy 2')
        self.MenuButtonB['menu'] = TB
        #TB.config(postcommand=self.HandlerB)
        self.MenuButtonB.bind('<ButtonPress-1>',self.HandlerB, '+')
        TB.bind('<Map>', self.on_map_B, '+')
        TB.bind('<Unmap>', self.on_unmap_B, '+')
        self.MenuButtonB.bind('<ButtonPress-1>',self.on_b1_B, '+')
        self.MenuButtonB.bind('<ButtonRelease-1>',self.on_b1release_B, '+')

        self.InfoLabel = tk.Label(self,text='---------')
        self.InfoLabel.pack(side='left')

    def HandlerA(self,Event=None):
        self.InfoLabel['text'] = 'Handler A'
        print 'Handler A'
        self.TA.entryconfigure(1, label='FOO')

    def HandlerB(self,Event=None):
        self.InfoLabel['text'] = 'Handler B'
        print 'Handler B'
        self.TB.entryconfigure(1, state='disabled')

    def on_b1_A(self, event):
        print 'button 1 pressed over Menubutton A'

    def on_b1release_A(self, event):
        print 'button 1 released over Menubutton A'

    def on_b1_B(self, event):
        print 'button 1 pressed over Menubutton B'

    def on_b1release_B(self, event):
        print 'button 1 released over Menubutton B'

    def on_map_A(self, event):
        print 'Menu A mapped'

    def on_map_B(self, event):
        print 'Menu B mapped'

    def on_unmap_A(self, event):
        print 'Menu A unmapped'

    def on_unmap_B(self, event):
        print 'Menu B unmapped'

app = Application()
app.master.title("Sample application")
app.mainloop()

#######################

When you run this, you see that while Menu A is mapped the button press
event never reaches Menubutton B.

Best regards

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

It [being a Vulcan] means to adopt a philosophy, a way of life which is
logical and beneficial.  We cannot disregard that philosophy merely for
personal gain, no matter how important that gain might be.
                -- Spock, "Journey to Babel", stardate 3842.4
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss