Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Christian Gollwitzer Newsgroups: comp.lang.python Subject: Re: non-blocking getkey? Date: Thu, 10 Dec 2015 09:54:26 +0100 Organization: A noiseless patient Spider Lines: 54 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 10 Dec 2015 08:51:58 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="09360e0ab07672f4bcf79b9f96c5414e"; logging-data="15412"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189L3ve7owSksq7uUe9RxoivMTQg1A4JqY=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: Cancel-Lock: sha1:BZZOPQMgEZ5tPL96UlmiUrXVZK8= Xref: csiph.com comp.lang.python:100222 Am 10.12.15 um 09:28 schrieb Ulli Horlacher: > Ulli Horlacher wrote: >> Found it: >> >> from Tkinter import Tk >> from tkFileDialog import askopenfilename >> >> Tk().withdraw() >> file = askopenfilename() > > My users do not like it :-( > They want to drag&drop files. > Therefore I have added it as another option to enter files: > > [f] select a file > [d] select a directory > [e] enter a file or directory (with drag&drop or copy&paste) Well I know that you won't take my advice but..... There are standard protocols for drag'n'drop of files and folders on all three major platforms. Tk supports this using the optional TkDND module, which unfortunately isn't installed with a standard Python distribution. Beware there is a "Tkdnd" Python module which implements local Drag'n'drop only; you need the "real thing" from here http://sourceforge.net/projects/tkdnd/ plus the correct Python bindings: Maybe this is the correct one: http://osdir.com/ml/python.tkinter/2005-07/msg00000.html I'm not sure - never used it from Python, only from Tcl. Using "the real thing" also allows you to accept multiple files/drectories dragged from the system file manager. Of course, you need a Tk main window to implement this, which you refused earlier. > With [f] starts askopenfilename and [d] starts askdirectory > > The problem with [e] is: my users do not press ENTER after pasting. > > My idea now is: instead of raw_input() I use a get_paste() function, which > reads input character for input character and after a (say) 1 s timeout it > returns the string. Pasting a string with the mouse is rather fast, there > should be no big delay between the characters. > > How can I implement such a get_paste() function? > I need a non-blocking getkey() function. > > It must work on Windows and Linux. Raw tty input. You'll have to write two different versions for Windows and Linux. Sorry I can't help with that one. Christian