[issue39177] In tkinter, simple dialogs, askstrings, etc. with flexible coordinates and no viewable parent.

2019-12-31 Thread Dominic Mayers


New submission from Dominic Mayers :

Currently, it's not possible to center or change the coordinates in anyway of 
an askstring, askfloat or askinteger dialog in simpledialog.py. One can see 
this by looking at the code:

if parent.winfo_viewable():
self.transient(parent)

if title:
self.title(title)

self.parent = parent

self.result = None

body = Frame(self)
self.initial_focus = self.body(body)
body.pack(padx=5, pady=5)

self.buttonbox()

if not self.initial_focus:
self.initial_focus = self

self.protocol("WM_DELETE_WINDOW", self.cancel)

if self.parent is not None:
self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
  parent.winfo_rooty()+50))

Here self.parent is never None, because the first statement would create a run 
time error if parent was None. So, the geometry always depends on the parent. 
Moreover, if the parent is not viewable, `parent.winfo_rootx()` and 
`parent.winfo_rooty()` are both 0. So, we can only set the coordinates of a 
simple dialog using a viewable parent. This contradicts a bit "simple" in 
"simpledialog". For example, what about an application that does not have a 
root window, like git for example, but, which unlike git, needs to create 
simple dialogs in some occasions. 

I am aware that a messagebox does not use the code that is presented above, but 
a messagebox is not a simple dialog - it's only a message. 

I am also aware of the class SimpleDialog, which also does not use this code, 
but it only works with buttons. It's not like askstring, askinteger and 
askfloat.

--
messages: 359147
nosy: dominic108
priority: normal
severity: normal
status: open
title: In tkinter, simple dialogs, askstrings, etc. with flexible coordinates 
and no viewable parent.
type: enhancement
versions: Python 3.9

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



[issue39171] Missing default root in tkinter simpledialog.py

2019-12-31 Thread Dominic Mayers


Dominic Mayers  added the comment:

Just to add that I realize now that tkinter is designed for applications with a 
root window, the "application window". That's why little attention is given to 
a possible missing root. In fact, it's interesting that we have this code in 
simpledialog.py: 

 
# Here, if parent is None, we have a run time error.
if parent.winfo_viewable():
self.transient(parent)
 
if title:
self.title(title)

self.parent = parent

self.result = None

body = Frame(self)
self.initial_focus = self.body(body)
body.pack(padx=5, pady=5)

self.buttonbox()

if not self.initial_focus:
self.initial_focus = self

self.protocol("WM_DELETE_WINDOW", self.cancel)

if self.parent is not None:
self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
  parent.winfo_rooty()+50))


But, self.parent will never be None. So the geometry always depends on the 
parent, which is compatible with the view that we are within an application 
with a root window - there is always a parent.

But it contradicts a bit, in my view, the "simple" in "simpledialog". What 
about an application with no root window, like git for example, but which, 
unlike git,  needs to create a simple dialog in some occasions?

--

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



[issue39171] Missing default root in tkinter simpledialog.py

2019-12-31 Thread Dominic Mayers


Change by Dominic Mayers :


--
versions: +Python 3.9 -Python 3.7

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



[issue39171] Missing default root in tkinter simpledialog.py

2019-12-31 Thread Dominic Mayers


Dominic Mayers  added the comment:

Again, I just spent a few minutes looking at this, but in the ttk module, in a 
similar situation, they do:

if master is None:
if tkinter._support_default_root:
master = tkinter._default_root or tkinter.Tk()
else:
raise RuntimeError(
"No master specified and tkinter is "
"configured to not support default root")

Why not do the same for _QueryDialog in simpledialog.py? Actually, I would also 
withdraw the root that was just created, because the user doesn't expect this 
extra window. So, I would replace

if not parent:
 parent = tkinter._default_root
 
with

if parent is None:
if tkinter._default_root: 
parent = tkinter._default_root
elif tkinter._support_default_root
parent = tkinter.Tk()
parent.withdraw()
else:
raise RuntimeError(
"No parent specified and tkinter is "
"configured to not support default root")

This tries to get a parent, if possible, and provides a more useful message 
when no parent can be found, just as in the ttk module in a similar situation.

--

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



[issue39171] Missing default root in tkinter simpledialog.py

2019-12-31 Thread Dominic Mayers


Dominic Mayers  added the comment:

If it's normal, then the error message should perhaps be more informative and 
user friendly than just a traceback: 

Traceback (most recent call last):
  File "./dialog.py", line 6, in 
integer_value = simpledialog.askinteger('Dialog Title', 'What is your 
age?', minvalue=0, maxvalue=100)
  File "/usr/lib/python3.7/tkinter/simpledialog.py", line 341, in askinteger
d = _QueryInteger(title, prompt, **kw)
  File "/usr/lib/python3.7/tkinter/simpledialog.py", line 271, in __init__
Dialog.__init__(self, parent, title)
  File "/usr/lib/python3.7/tkinter/simpledialog.py", line 137, in __init__
if parent.winfo_viewable():
AttributeError: 'NoneType' object has no attribute 'winfo_viewable'

If it is not too intrusive, it would be even more user friendly if the code 
found some parent window.

--

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



[issue39171] Missing default root in tkinter simpledialog.py

2019-12-31 Thread Dominic Mayers


New submission from Dominic Mayers :

My first "bug" report here. Not sure I am doing it right. It is just that if I 
execute the code

import tkinter
from tkinter import simpledialog
tkinter.Tk().withdraw() 
integer_value = simpledialog.askinteger('Dialog Title', 'What is your 
age?', minvalue=0, maxvalue=100)

It works. In particular, when the line `parent = tkinter._default_root` is 
executed in simpledialog.py, `_default_root` is defined.  However, if I execute 
the code

import tkinter
from tkinter import simpledialog
integer_value = simpledialog.askinteger('Dialog Title', 'What is your 
age?', minvalue=0, maxvalue=100)

which does not have the line `tkinter.Tk().withdraw()` it does not work. When 
the line `parent = tkinter._default_root` is executed, `_default_root` is not 
defined. 

I don't know if it is a bug. I don't understand the remainder of the code 
enough to say. However, the purpose of this line is to define a parent when 
none is provided. It seem to me that it should be possible to find a parent 
window...

--
components: Tkinter
messages: 359106
nosy: dominic108
priority: normal
severity: normal
status: open
title: Missing default root in tkinter simpledialog.py
type: behavior
versions: Python 3.7

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-05 Thread Dominic Mayers

Changes by Dominic Mayers <dominic_may...@yahoo.com>:


Removed file: 
http://bugs.python.org/file46775/Issue29947_for_discussion_03.patch

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-05 Thread Dominic Mayers

Dominic Mayers added the comment:

An improved version of the patch, I hope. I will remove the old patch, because 
it's really does not help to see the old versions.

--
Added file: http://bugs.python.org/file46781/Issue29947_for_discussion_04.patch

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-04 Thread Dominic Mayers

Changes by Dominic Mayers <dominic_may...@yahoo.com>:


Added file: http://bugs.python.org/file46775/Issue29947_for_discussion_03.patch

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-04 Thread Dominic Mayers

Changes by Dominic Mayers <dominic_may...@yahoo.com>:


Removed file: 
http://bugs.python.org/file46774/Issue29947_for_discussion_02.patch

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-04 Thread Dominic Mayers

Changes by Dominic Mayers <dominic_may...@yahoo.com>:


Removed file: http://bugs.python.org/file46770/Issue29947_for_discussion.patch

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-04 Thread Dominic Mayers

Dominic Mayers added the comment:

I simplified the patch. Using a class as a factory function is the simplest 
case, so I took advantage of this. I also give one way to pass extra parameters 
to the handler in the factory function, because it's the main reason why we 
cannot always use a class.

--
Added file: http://bugs.python.org/file46774/Issue29947_for_discussion_02.patch

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-03 Thread Dominic Mayers

Dominic Mayers added the comment:

The key point, IMHO, is that the BaseRequestHandler class is just provided as 
an option and its API (setup, handle and finish) is ignored by the code that we 
support. 

Some applications may have used the API, but these are details in applications. 
Simply, we keep BaseRequestHandler as it is so that we do not break these 
applications. 

So, yes, we should keep supporting the API, but we do not expect this API on 
our side. The latter is the key point.

--

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-02 Thread Dominic Mayers

Dominic Mayers added the comment:

I started to look at the documentation to see what would need to be changed, 
assuming that we agree for a change in the API. Just for the purpose of this 
discussion, I created a patch that only change the comments in socketserver.py.

--

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-02 Thread Dominic Mayers

Changes by Dominic Mayers <dominic_may...@yahoo.com>:


--
keywords: +patch
Added file: http://bugs.python.org/file46770/Issue29947_for_discussion.patch

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-02 Thread Dominic Mayers

Changes by Dominic Mayers <dominic_may...@yahoo.com>:


Removed file: http://bugs.python.org/file46768/factorymixinclass

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-02 Thread Dominic Mayers

Dominic Mayers added the comment:

I did not think very far when said that renaming the parameter could not 
possibly break the code ! Oh well ! But, renaming the parameter was not 
important in itself.  It was to make the situation clearer and easier for those 
who write the documentation. Martin mentioned that it is a big change for the 
API. This is what I had in mind. And yes, I should have used 'factory 
function', not 'factory instance'. Oh well ! I am glad things are working and 
that we will move ahead to resolve this issue.

--

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-01 Thread Dominic Mayers

Dominic Mayers added the comment:

Oops, I did not realize that David was one of the developers. Well, may be this 
needs the attention of more than one developer.

--

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-01 Thread Dominic Mayers

Dominic Mayers added the comment:

The reason why I feel we should not make it immediately a documentation issue 
is that I don't know how a person working on documentation could proceed ahead 
without a clear go ahead signal from developers. In that sense,  having a 
documentation that says that the variable name does not reflect its intent 
seems tricky. It's very easy to change a variable name. It cannot possibly 
break the code, except for a collision, but they are easy to avoid.  If we 
don't have the interest of developers, not even for a simple renaming, I don't 
see a go ahead signal in this.

--

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-01 Thread Dominic Mayers

Dominic Mayers added the comment:

To sum up, David clarified that we can in fact easily pass an arbitrary factory 
method that creates and starts a request handler, instead of a request handler 
class with setup, handle and finish in its API. This could indeed be a valid 
reason to consider this issue resolved,  but I would like to be sure that it is 
really a normal and supported use of the code. The only place where I can ask 
this is here. If I ask in StackOverflow, etc. I would get all kind of opinions  
and it would not be useful.  To be honest, looking at the parameter name, the 
documentation,  the examples, etc. it does not look at all a normal and 
supported use of the code, but who am I to decide that?  If it turns out to be 
a normal and supported use of the code, then I will create a different issue 
only about the documentation, because it's not clear at all.

--
nosy: +martin.panter

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-04-01 Thread Dominic Mayers

Dominic Mayers added the comment:

Perhaps I should raise a separate issue, but it is related, because the current 
code "requires" that we define an handler class with `setup()`, `handle()` and 
`finish()` in its API. If you look at the actual code, there is no such 
requirement. We only have to pass a factory method that receives three 
arguments, creates a new handler instance and starts it. The handler does not 
have to offer any API - you don't even have to subclass the RequestHandlerBase 
class. I still say that it "requires" it, because it is part of the 
documentation and, if you don't, you could be in trouble in future versions. 
However, this requirement is clearly annoying, because if you have an handler 
for another server, you need to re-factorize the code to provide this API, 
which is not even used. I am sure there is no such requirement, but it's not 
clear at first. 

This is clearly not just a documentation issue. The intent in the code is the 
concern of the designers of the code. David and I assume that the intent is 
that we can provide any arbitrary factory method that receives the three 
arguments, creates and starts the handler, but we can be mistaken. In fact, to 
me this looks as a hack, especially given the parameter name, which says that 
we must pass the handler class. An handler class is indeed a factory method, 
but it is a very specific one, not the one that we want to pass if we must 
include extra parameters.

--

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-03-31 Thread Dominic Mayers

Dominic Mayers added the comment:

I am a bit ashamed that I missed that. Still, the intent in the current code, 
the name of the parameter, the examples, etc. is that we pass the handler 
class. This is more than its __init__ function and less than a generic factory  
method. An important difference, which could become important, is that with a 
factory the handler type could depend on the request.  As pointed out by Eric, 
passing the class was perhaps the intent in the early days. Now, perhaps many 
use it differently and pass a factory method, not a class, but it still appears 
as a hack that does not respect the intent. One could legitimately worry that 
this hack will not be supported in future versions, because it is not 
documented.

--

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-03-30 Thread Dominic Mayers

Dominic Mayers added the comment:

On the other hand, it occurs to me that this seems way more flexible than 
passing the object through the server, because you share the factory with the 
server, not only the object. This means that you could even change the type of 
the handler while the server is running !

--

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-03-30 Thread Dominic Mayers

Changes by Dominic Mayers <dominic_may...@yahoo.com>:


--
resolution: wont fix -> 
status: closed -> open

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-03-30 Thread Dominic Mayers

Dominic Mayers added the comment:

Finally, I looked around and people just use the server to pass any extra 
parameter. I do find it awkward, but it works and it is simple, in fact simpler 
than having to define a factory object. I don't close it, because I will be 
happy to see another opinion. I would use this factory approach for myself, 
because I am just not comfortable to add an attribute to a server that would 
not even look at it, but maybe that it just me.

--
resolution:  -> wont fix
status: open -> closed

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-03-30 Thread Dominic Mayers

Dominic Mayers added the comment:

One way to make the factory optional is to offer a MixIn. I attached a file 
with a FactoryMixIn. It's just that I find it awkward that the proposed 
approach is to pass the extra parameters in a subclassed server. More modern 
approaches should also be offered.

--
resolution: rejected -> 
status: closed -> open
Added file: http://bugs.python.org/file46768/factorymixinclass

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



[issue29947] In SocketServer, why not passing a factory instance for the RequestHandlerClass instead of the class itself?

2017-03-30 Thread Dominic Mayers

New submission from Dominic Mayers:

I am just curious to know if someone considered the idea of passing a factory 
instance that returns RequestHandlerClass instances instead of directly passing 
the class? It may affect existing handlers that read non local variables, but 
there should be a way to make the factory optional. The purpose is only 
aesthetic and a better organization of the code. I find it awkward to have to 
subclass the server every time that we have an handler that needs special 
objects, a database connection, a socket connection to another party, etc. The 
server class should have a single purpose: accept a request and pass it to an 
handler. We should only need to subclass a server when we need to do that in a 
different way : TCP vs UDP, Unix Vs INET, etc. The usage is simpler and more 
natural. Instead of subclassing the server, we create a factory for the handler.

--
components: Library (Lib)
messages: 290840
nosy: dominic108
priority: normal
severity: normal
status: open
title: In SocketServer, why not passing a factory instance for the 
RequestHandlerClass  instead of the class itself?
type: enhancement
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7

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