[issue30791] tkinter.Tk() adds suffix to window class name when launching multiple instances

2017-06-28 Thread Håkon Hægland

New submission from Håkon Hægland:

Hello. In order to group several instances of a given application under one 
icon in the desktop launcher (I am using Ubuntu 17.04) they must have the same 
appName property of the WM_CLASS string. For example, if I run emacs twice:

$ emacs &
$ emacs &

Both instances will show up under the Emacs icon in the desktop launchbar. The 
reason is that both instances have the same WM_CLASS string. We can check this 
string using

$ xprop WM_CLASS

and then click on the Emacs window. It then shows:

WM_CLASS(STRING) = "emacs", "Emacs"
Here "emacs" is the resource (appName), and "Emacs" is the className.

Now, consider this program (my-tkapp.py):

#! /usr/bin/env python
import tkinter as tk
root = tk.Tk(className='myTkApp')
label = tk.Label(root, text="Hello World")
label.pack()
root.mainloop()


If I run this program twice:

$ my-tkapp.py &
$ my-tkapp.py &

and then run xprop to check the WM_CLASS property of both windows, the first 
window gives:

WM_CLASS(STRING) = "myTkApp", "Mytkapp"

whereas the second gives:

WM_CLASS(STRING) = "myTkApp #2", "Mytkapp"

Note that tkinter has added a #2 suffix to the app name property. This is not 
desired. It makes the window manager group the two windows under separate icons 
in the desktop launch bar.

How can I keep the same appName property of the WM_CLASS string for different 
instances of my application?

Note: This question was first asked at stackoverflow.com:

https://stackoverflow.com/q/44795622/2173773

I tried to follow the source from the call:

root = tkinter.Tk(className='myTkApp')

but at 5 levels down on the stack I ended up inside TCL code, and I was not 
able to determine who was responsible for adding the "#2" suffix.

However, a similar perl script gives the same behavior, so I suspect the 
problem is within the TCL TK code. Is there a way to change the
WM_CLASS property of the window after the call to tkinter.Tk, but before 
entering mainloop() in order to work around the issue?
After entering the mainloop(), I guess it is too late to do anything, since 
then the icon is already displayed in the window manager's launch bar.

I am using Ubuntu 17.04 and Python version 3.6.1.

Best regards,
Håkon Hægland

--
components: Tkinter
messages: 297191
nosy: hakonhagland
priority: normal
severity: normal
status: open
title: tkinter.Tk() adds suffix to window class name when launching multiple 
instances
type: behavior

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30791>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30503] It should be possible to use a module name with the same name as a package name

2017-05-29 Thread Håkon Hægland

New submission from Håkon Hægland:

I have the following folder structure:

.
├── aaa
│   ├── bbb
│   │   ├── ccc.py
│   │   └── __init__.py
│   ├── bbb.py
│   └── __init__.py
├── __init__.py
└── t.py

./t.py:

import sys
sys.path = ['.']
import aaa.bbb
print(aaa.bbb.get_name())

./aaa/bbb.py:

def get_name():
return "aaa/bbb"

however, when I run the main script:

$ python -B t.py 
Traceback (most recent call last):
  File "t.py", line 5, in 
print(aaa.bbb.get_name())
AttributeError: module 'aaa.bbb' has no attribute 'get_name'

The reason is that there is also a package with name 'aaa.bbb' (i.e. file 
"./aaa/bbb/__init__.py") and python will see this package before it sees my 
module "./aaa/bbb.py" and will never load the module.

If this is correct, than this is a bad design in my opinion. I should be 
possible to use a module with the same name as a package. 

Thanks for considering this issue, and let me know if I can help improve Python 
at this point.

Note: I asked the question first at stackoverflow.com:
https://stackoverflow.com/q/44227763/2173773

--
components: Interpreter Core
messages: 294682
nosy: hakonhagland
priority: normal
severity: normal
status: open
title: It should be possible to use a module name with the same name as a 
package name
type: enhancement

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30503>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com