Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41957
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <msirenef@lightbird.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'context': 0.07; 'nested': 0.07; 'forcing': 0.09; 'lst': 0.09; 'python:': 0.09; 'subject:design': 0.09; 'window.': 0.09; 'wrapper': 0.09; 'subject:Help': 0.11; 'python': 0.11; 'windows': 0.15; "'s')": 0.16; '10:59': 0.16; 'effect.': 0.16; 'gained': 0.16; 'ourselves,': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject:API': 0.16; 'tabs': 0.16; 'vastly': 0.16; 'window;': 0.16; 'world!")': 0.16; 'wrote:': 0.18; 'library': 0.18; 'all,': 0.19; 'trying': 0.19; 'acquired': 0.19; 'user.': 0.19; 'starts': 0.20; 'work,': 0.20; 'seems': 0.21; 'command': 0.22; 'example': 0.22; 'header:User- Agent:1': 0.23; 'large,': 0.24; 'switched': 0.24; "i've": 0.25; 'script': 0.25; 'switch': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'michael': 0.29; 'rest': 0.29; 'am,': 0.29; 'generally': 0.29; 'ignored.': 0.30; 'gives': 0.31; 'code': 0.31; 'easier': 0.31; 'argue': 0.31; 'block,': 0.31; 'context,': 0.31; 'extensively': 0.31; 'though.': 0.31; 'handled': 0.32; '(i.e.': 0.33; 'could': 0.34; 'subject: (': 0.35; 'common': 0.35; 'but': 0.35; 'there': 0.35; 'belong': 0.36; 'should': 0.36; 'wrong': 0.37; 'too': 0.37; 'two': 0.37; 'others.': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'bad': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'read': 0.60; 'easy': 0.60; 'commands': 0.60; 'dangerous': 0.60; 'most': 0.60; 'march': 0.61; 'entire': 0.61; "you're": 0.61; 'further': 0.61; 'first': 0.61; "you've": 0.63; 'kind': 0.63; 'skip:n 10': 0.64; 'different': 0.65; 'afraid': 0.65; 'within': 0.65; '26,': 0.68; 'burden': 0.68; 'fortune': 0.68; 'of:': 0.68; "'with'": 0.84; "it'd": 0.84; 'off,': 0.84; 'do:': 0.91; 'deal,': 0.93; '2013': 0.98 |
| Date | Tue, 26 Mar 2013 18:01:08 -0400 |
| From | Mitya Sirenef <msirenef@lightbird.net> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Help me pick an API design (OO vs functional) |
| References | <68da956e-ebe0-4f58-92cd-f7ffff0075b4@googlegroups.com> <mailman.3706.1364254851.2939.python-list@python.org> <01a290d9-6a59-45ad-bc30-e09d13aa7799@googlegroups.com> <mailman.3746.1364305302.2939.python-list@python.org> <c2b7ea32-f73c-4613-bbaf-b40492c469f2@googlegroups.com> |
| In-Reply-To | <c2b7ea32-f73c-4613-bbaf-b40492c469f2@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3780.1364335271.2939.python-list@python.org> (permalink) |
| Lines | 108 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1364335271 news.xs4all.nl 6948 [2001:888:2000:d::a6]:37506 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:41957 |
Show key headers only | View raw
On 03/26/2013 10:59 AM, Michael Herrmann wrote:
> On Tuesday, March 26, 2013 2:41:38 PM UTC+1, Mitya Sirenef wrote:
>> ...
>> At the __exit__, further commands are no longer routed to that window;
>> if it was a nested context, window is switched to the outer context,
>> WHEN there are commands in it (i.e. on the first command). This seems
>> pretty intuitive to me:
>>
>> with notepad1:
>> ^S
>> with notepad2:
>> ^S
>> write('something')
>>
>
>> ...
>> > What I am most afraid of: that the window that's currently the
>> > context "disappears":
>>
>> > notepad = start("Notepad")
>> > with notepad:
>> > press(ALT + TAB)
>> > write("Am I in Notepad now?")
>>
>>
>> Alt-tab needs to be handled by a wrapper function that gives you the
>> object of the window you've switched to:
>>
>> otherwin = alt_tab()
>> with otherwin:
>> ...
>>
>> If window is changed within 'with' block, the rest of block should be
>> ignored. Perhaps there could also be a way to switch this behaviour off,
>> for the entire script or for current block only.
>>
>>
>> > What do you think of designs #3 and #4?
>> > ...
>>
>> These are ok, too, but I feel it's much easier to send commands to a
>> wrong window vs. context managers. The same command in a different
>> window can have vastly different and dangerous effect. In other python
>> code that's generally not common at all, and would be bad style:
>>
>> lst = lst1
>> lst.append('x')
>> del lst[3]
>> lst.insert(0, 'a')
>> lst = lst2
>> del lst[2]
>> lst.append('y')
>> lst = lst3
>> lst.insert(0, 'x')
>> lst += [1,2]
>>
>> I think current window should also be acquired explicitly:
>>
>> with get_current_window():
>> type("some kind of snippet")
>>
>> For usage when a command should apply to all types of windows.
>
> I was skeptical of your suggestion at first but trying it out on an
example script made me see its appeal:
>
> notepad_main = start("Notepad")
> with notepad_main:
> write("Hello World!")
> save_dialogue = press(CTRL + 's')
> with save_dialogue:
> write("test.txt", into="File name")
> click("Save")
> click("Close")
>
> Forcing the library user to always use the "with ..." seems like
overkill though. I think the gained precision does not justify this
burden on the library user. Hm....
I don't see why that's a big deal, I've used AHK extensively and in my
experience you don't switch windows all that often. I think it's best to
optimize to have easy to type and read commands while you're working in
the same window.
I think you could argue that dialogs that belong to the main window
should be handled implicitly, though. I think for other windows it'd
definitely be good to use context managers, but for quick/simple dialogs
it's too much hassle, although for large, complex dialogs that have
inner tabs and require a lot of work, it again starts to make sense.
At the very least, for small dialogs it's sipmpler to do:
with press(CTRL + 's'):
write("test.txt", into="File name")
click("Save")
-m
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
Calamities are of two kinds: misfortunes to ourselves, and good fortune
to others.
Ambrose Bierce, The Devil's Dictionary
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-25 12:29 -0700
Re: Help me pick an API design (OO vs functional) Kwpolska <kwpolska@gmail.com> - 2013-03-25 20:42 +0100
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-25 13:48 -0700
Re: Help me pick an API design (OO vs functional) Chris Angelico <rosuav@gmail.com> - 2013-03-26 08:08 +1100
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 01:53 -0700
Re: Help me pick an API design (OO vs functional) Chris Angelico <rosuav@gmail.com> - 2013-03-26 22:38 +1100
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 05:13 -0700
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 05:13 -0700
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-25 13:48 -0700
Re: Help me pick an API design (OO vs functional) Ethan Furman <ethan@stoneleaf.us> - 2013-03-25 16:11 -0700
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 02:06 -0700
Re: Help me pick an API design (OO vs functional) Dave Angel <davea@davea.name> - 2013-03-26 06:26 -0400
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 05:04 -0700
Re: Help me pick an API design (OO vs functional) Dave Angel <davea@davea.name> - 2013-03-26 08:42 -0400
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 07:33 -0700
Re: Help me pick an API design (OO vs functional) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-26 22:37 +0000
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-27 02:34 -0700
Re: Help me pick an API design (OO vs functional) Ethan Furman <ethan@stoneleaf.us> - 2013-03-27 09:45 -0700
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-28 03:54 -0700
Re: Help me pick an API design (OO vs functional) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-28 00:42 +0000
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-28 04:41 -0700
Re: Help me pick an API design (OO vs functional) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-26 12:59 +0000
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 07:26 -0700
Re: Help me pick an API design (OO vs functional) Mitya Sirenef <msirenef@lightbird.net> - 2013-03-25 19:40 -0400
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 02:38 -0700
Re: Help me pick an API design (OO vs functional) Chris Angelico <rosuav@gmail.com> - 2013-03-26 22:43 +1100
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 05:18 -0700
Re: Help me pick an API design (OO vs functional) Mitya Sirenef <msirenef@lightbird.net> - 2013-03-26 09:41 -0400
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 07:59 -0700
Re: Help me pick an API design (OO vs functional) Chris Angelico <rosuav@gmail.com> - 2013-03-27 02:16 +1100
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-27 01:45 -0700
Re: Help me pick an API design (OO vs functional) Mitya Sirenef <msirenef@lightbird.net> - 2013-03-26 18:01 -0400
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-27 02:10 -0700
Re: Help me pick an API design (OO vs functional) Mitya Sirenef <msirenef@lightbird.net> - 2013-03-27 09:56 -0400
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-28 03:52 -0700
Re: Help me pick an API design (OO vs functional) Neil Cerutti <neilc@norwich.edu> - 2013-03-26 14:13 +0000
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-26 07:40 -0700
Re: Help me pick an API design (OO vs functional) Dave Angel <davea@davea.name> - 2013-03-26 12:41 -0400
Re: Help me pick an API design (OO vs functional) Neil Cerutti <neilc@norwich.edu> - 2013-03-26 17:25 +0000
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-27 01:55 -0700
Re: Help me pick an API design (OO vs functional) Chris Angelico <rosuav@gmail.com> - 2013-03-27 22:44 +1100
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-27 05:23 -0700
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-03-27 05:23 -0700
Re: Help me pick an API design (OO vs functional) Michael Herrmann <michael.herrmann@getautoma.com> - 2013-04-04 00:05 -0700
csiph-web