Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108847

Re: Resources/pointers for writing maintable, testable Python

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Terry Reedy <tjreedy@udel.edu>
Newsgroups comp.lang.python
Subject Re: Resources/pointers for writing maintable, testable Python
Date Thu, 19 May 2016 18:45:30 -0400
Lines 67
Message-ID <mailman.44.1463697947.27390.python-list@python.org> (permalink)
References <CA+yM-qbQSUKy8f3K1OF0-ON0mU7UugPLVnSkxXENkFes2SYQkA@mail.gmail.com> <CA+y5TLaDATkWELXdESMMYfmhJKNLiDJjGEbTDYYSRYTZqws4GA@mail.gmail.com> <mailman.22.1463608092.27390.python-list@python.org> <ffa86da4-f7f1-4a02-9fba-0bd6ca68e074@googlegroups.com> <nhkpa0$crf$1@ger.gmane.org> <mailman.35.1463675017.27390.python-list@python.org> <909ee5e9-ae16-4ebe-a6c1-c838ff3bb8fd@googlegroups.com> <nhlfmb$n5p$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de hxGnG3fsD2XXYLe2mde2jAqdjFFQoUm5iASkYjCEboUA==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'handler': 0.04; 'root': 0.04; 'subject:Python': 0.05; "'a'": 0.07; 'apps,': 0.07; 'keys,': 0.07; 'mouse': 0.07; 'works.': 0.07; "'''": 0.09; 'events.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'reference)': 0.09; 'jan': 0.11; 'thursday,': 0.13; 'def': 0.13; 'argument': 0.15; '*before*': 0.16; '2016': 0.16; '54,': 0.16; 'buttons,': 0.16; 'called,': 0.16; 'curious.': 0.16; 'driscoll': 0.16; 'entry.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'reminding': 0.16; 'selenium': 0.16; 'simulate': 0.16; 'simulated': 0.16; 'subject:writing': 0.16; 'wrote:': 0.16; 'specifies': 0.18; 'widget': 0.18; 'commands,': 0.22; 'object.': 0.22; 'referring': 0.22; 'tkinter': 0.22; 'needed.': 0.23; 'import': 0.24; 'url:edu': 0.24; 'header:In-Reply-To:1': 0.24; 'discussion': 0.24; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'external': 0.27; 'handling': 0.27; 'sequence': 0.27; 'values': 0.28; 'arguments,': 0.29; 'screen.': 0.29; 'mike': 0.29; 'subject:/': 0.30; 'skip:. 10': 0.32; 'idle': 0.33; 'case,': 0.34; 'could': 0.35; 'text': 0.35; 'done': 0.35; 'but': 0.36; 'needed': 0.36; '(and': 0.36; 'keyword': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'button': 0.38; 'test': 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'field': 0.60; 'providing': 0.62; 'received:96': 0.63; 'more': 0.63; 'url:help': 0.73; 'clicking': 0.75; '**kw)': 0.84; 'events:': 0.84; 'perspective.': 0.84; 'url:tkinter': 0.84; 'received:fios.verizon.net': 0.91
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host pool-96-227-207-81.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0
In-Reply-To <909ee5e9-ae16-4ebe-a6c1-c838ff3bb8fd@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <nhlfmb$n5p$1@ger.gmane.org>
X-Mailman-Original-References <CA+yM-qbQSUKy8f3K1OF0-ON0mU7UugPLVnSkxXENkFes2SYQkA@mail.gmail.com> <CA+y5TLaDATkWELXdESMMYfmhJKNLiDJjGEbTDYYSRYTZqws4GA@mail.gmail.com> <mailman.22.1463608092.27390.python-list@python.org> <ffa86da4-f7f1-4a02-9fba-0bd6ca68e074@googlegroups.com> <nhkpa0$crf$1@ger.gmane.org> <mailman.35.1463675017.27390.python-list@python.org> <909ee5e9-ae16-4ebe-a6c1-c838ff3bb8fd@googlegroups.com>
Xref csiph.com comp.lang.python:108847

Show key headers only | View raw


On 5/19/2016 4:10 PM, Mike Driscoll wrote:
> On Thursday, May 19, 2016 at 11:23:53 AM UTC-5, Terry Reedy wrote:

>> In my case, I learned better how to test IDLE from a user perspective.
>> For tkinter apps, an external program such as Selenium is not needed.
>> Tk/tkinter have the simulated event generation and introspection needed
>> to simulate a user hitting keys, clicking mouse buttons, and reading the
>> screen.

> I am curious. Where is this documented? Are you referring to calling
 > the invoke() method on each widget?

For widget commands, yes.  (And thanks for reminding of the method.)

For events:
http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/universal.html
(An indispensible tkinter reference) says:
'''
w.event_generate(sequence, **kw)

     This method causes an event to trigger without any external 
stimulus. The handling of the event is the same as if it had been 
triggered by an external stimulus. The sequence argument describes the 
event to be triggered. You can set values for selected fields in the 
Event object by providing keyword=value arguments, where the keyword 
specifies the name of a field in the Event object.

     See Section 54, “Events” for a full discussion of events.
'''
This omits some essentials.  tcl.tk/man/tcl8.6/TkCmd/event.htm
has much more, including the need to put focus on Text and Entry.

 From Stackoverflow, I learned that .update() is needed *before* 
.event_generate.  The following works.

import tkinter as tk
root = tk.Tk()
def prt():
     print('Handler called')
button = tk.Button(root, text='Click', command=prt)
button.place(x=20, y=20)
def ev(e):
     print(e.x, e.y)
button.bind('<ButtonPress-1>', ev)
button.update()
button.event_generate('<ButtonPress-1>', x=0, y=0)
button.event_generate('<ButtonRelease-1>')
button.invoke()
entry=tk.Entry(root)
entry.place(x=20, y=50)
entry.focus_force()
entry.update()
entry.event_generate('<Key-a>')

The event is reported, the handler is called, and 'a' is inserted. 
(Inserting text could be done more easily, but some key events such as 
<Key-End> do have text equivalents.)

-- 
Terry Jan Reedy


Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: Resources/pointers for writing maintable, testable Python Andrew Farrell <armorsmith42@gmail.com> - 2016-05-18 17:23 -0400
  Re: Resources/pointers for writing maintable, testable Python Mike Driscoll <kyosohma@gmail.com> - 2016-05-19 08:33 -0700
    Re: Resources/pointers for writing maintable, testable Python Jacob Scott <jacob.scott@gmail.com> - 2016-05-19 09:10 -0700
    Re: Resources/pointers for writing maintable, testable Python Terry Reedy <tjreedy@udel.edu> - 2016-05-19 12:23 -0400
      Re: Resources/pointers for writing maintable, testable Python Mike Driscoll <kyosohma@gmail.com> - 2016-05-19 13:10 -0700
        Re: Resources/pointers for writing maintable, testable Python Terry Reedy <tjreedy@udel.edu> - 2016-05-19 18:45 -0400

csiph-web