Re: Implementing a plug-in mechanism

2023-03-16 Thread Simon Ward

On Thu, Mar 16, 2023 at 07:45:18AM +1300, dn via Python-list wrote:
There is a PyPi library called pluggy (not used it). I've used informal 
approaches using an ABC as a framework/reminder (see @George's 
response).


typing.Protocol is also useful here as the plugin interface can be 
defined separately not requiring inheriting from an ABC.


Simon
--
A complex system that works is invariably found to have evolved from a
simple system that works.—John Gall
--
https://mail.python.org/mailman/listinfo/python-list


Re: Debugging reason for python running unreasonably slow when adding numbers

2023-03-16 Thread Roel Schroeven

Op 14/03/2023 om 8:48 schreef Alexander Nestorov:

I have the following code:

 ...
 for i in range(151): # 150 iterations
     ...
Nothing to do with your actual question and it's probably just a small 
oversight, but still I thought it was worth a mention: that comment does 
not accurately describe the code; the code is actually doing 151 
iterations, numbered 0 up to and including 150.


--
"I've come up with a set of rules that describe our reactions to technologies:
1. Anything that is in the world when you’re born is normal and ordinary and is
   just a natural part of the way the world works.
2. Anything that's invented between when you’re fifteen and thirty-five is new
   and exciting and revolutionary and you can probably get a career in it.
3. Anything invented after you're thirty-five is against the natural order of 
things."
-- Douglas Adams, The Salmon of Doubt

--
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter and cv2: "not responding" popup when imshow launched from tk app

2023-03-16 Thread aapost

On 3/15/23 07:37, John O'Hagan wrote:

On Tue, 2023-03-14 at 16:22 -0400, aapost wrote:

On 3/14/23 06:54, John O'Hagan wrote:


[...]





Read an alternative description of the waitKey behavior

>For example, waitKey(0) will display the window infinitely until any 
keypress (it is suitable for image display). waitKey(25) will display a 
frame and wait approximately 25 ms for a key press (suitable for 
displaying a video frame-by-frame). To remove the window, use 
cv::destroyWindow.


I went back to double check and I stand corrected on the "any keypress" 
part. Any keypress on the 'keyboard' does break the wait (as I 
incorrectly concluded and assumed only ESC did).


It is still slightly ambiguous in explaining that when using 25ms, 
keypress or not, the wait breaks at 25ms (or before that if you press a 
keyboard key). For my setup the window is stale at that point, no 
controls, just a stale frame behind the tkinter window that needs to be 
destroyed or reused.


Whether that is the exact behavior on all set-ups isn't clear, the note 
further uses the ambiguous phrasing "might".


>Note: This function should be followed by a call to cv::waitKey or 
cv::pollKey to perform GUI housekeeping tasks that are necessary to 
actually show the given image and make the window respond to mouse and 
keyboard events. Otherwise, it won’t display the image and the window 
might lock up.


It seems with the several variations, behavior varies between them, like 
one comment saying startWindowThread when using c++ and gtk allows you 
to not use waitKey (not the case here.. it seems -- changing my language 
to not misspeak, lol).


I haven't come across any examples beyond imshow running stand-alone as 
in my solution suggestion 2. But waitKey does return a keyvalue for the 
keypess to allow extending the functionality, so you can grab it, do 
something, and go right back to waiting, I haven't seen any use of this 
though.


You can also leave out reference to tkinter all together when using 
startWindowThread:


import sys
import cv2

cv2.startWindowThread()
cv2.namedWindow("W", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("W", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.imshow("W", cv2.imread(sys.argv[1]))
while(1):
a = cv2.waitKey(0)
if a == 27:#ESC
break
#elif a == something else, do something
cv2.destroyAllWindows()
exit()

But it still blocks if integrated in to the main tkinter thread, and 
appears to use tkinter under the hood. And as tkinter is considered 
thread-unsafe, the startWindowThread would only be ok when spawned as a 
separate process like the subprocess example.


Anyway, apologies for the mistake on the any key part.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Implementing a plug-in mechanism

2023-03-16 Thread Loris Bennett
Simon Ward  writes:

> On Thu, Mar 16, 2023 at 07:45:18AM +1300, dn via Python-list wrote:
>> There is a PyPi library called pluggy (not used it). I've used
>> informal approaches using an ABC as a framework/reminder (see
>> @George's response).
>
> typing.Protocol is also useful here as the plugin interface can be
> defined separately not requiring inheriting from an ABC.

Thanks to all for the helpful suggestions.   I realise that I don't
actually need to be able to load a bunch of arbitrary plugins, but
merely to be able to override one (or, perhaps later, more) piece of
default behaviour.

Therefore I think the following very simple scheme will work for me:

  $ tree -L 3
  .
  └── myproj
  ├── __init__.py
  ├── mailer.py
  ├── main.py
  └── plugins
  └── normanmailer.py

Where main.py is

  #!/usr/bin/env python3
  # -*- coding: utf-8 -*-

  if __name__ == "__main__":

  try:
  import plugin.mailer as mailer
  print("Found plugin.mailer")
  except ModuleNotFoundError:
  import mailer
  print("Found mailer")

  m = mailer.Mailer('abc')
  m.run()

mailer.py is

  class Mailer():

  def run(self):
  print("This is a generic Mailer object!")

and plugins/normanmailer.py is

  class Mailer():

  def run(self):
  print("This is a customized Mailer object!")

This then gives me

  $ poetry run myproj\/main.py
  Found mailer
  This is a generic Mailer object!

  $ mv myproj/plugins/{norman,}mailer.py

  $ poetry run myproj\/main.py
  Found plugins.mailer
  This is a customized Mailer object!

I suspect I was using slightly incorrect/misleading terminology.  I
don't want to be able to load arbitrary functionality via plugins,
e.g. sending an email, dumping to a database, uploading to a cloud.
That would, I far as I can tell, necessitate having some mechanism to
select the functionality.

Instead I just want to modify the behaviour of a piece of fixed
functionality. e.g. sending a mail.  So am I really talking about
customisation here.

Cheers,

Loris

--
This signature is currently under constuction.
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: Python Meeting Düsseldorf - 22.03.2023

2023-03-16 Thread eGenix Team


/This announcement is in German since it targets a local user 
group//meeting in Düsseldorf, Germany/



   Ankündigung

   Python Meeting Düsseldorf -
   
März
   2023
   

   Ein Treffen von Python Enthusiasten und Interessierten
   in ungezwungener Atmosphäre.

   *22.03.2023, 18:00 Uhr*
   Raum 1, 2.OG im Bürgerhaus Stadtteilzentrum Bilk
   
   Düsseldorfer Arcaden
   , Bachstr. 145,
   40217 Düsseldorf
   



   Programm

Bereits angemeldete Vorträge:

Charlie Clark:
        "Eine neue XML Bibliothek: Pugixml"

Marc-Andre Lemburg:
        "Data Analysis with OpenSearch – Waiting times at the DUS airport"

Arkadius Schuchhardt:
        "Concurrent data loading by using the thread producer-consumer 
pattern"


Weitere Vorträge können gerne noch angemeldet werden. Bei Interesse, 
bitte unter [email protected] melden.



 Startzeit und Ort

Wir treffen uns um 18:00 Uhr im Bürgerhaus in den Düsseldorfer Arcaden.

Das Bürgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet 
sich an der Seite der Tiefgarageneinfahrt der Düsseldorfer Arcaden.


Über dem Eingang steht ein großes "Schwimm’ in Bilk" Logo. Hinter der 
Tür direkt links zu den zwei Aufzügen, dann in den 2. Stock hochfahren. 
Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt.


>>> Eingang in Google Street View 


 Corona

Die Corona Einschränkungen sind mittlerweile aufgehoben worden. Vorsicht 
ist zwar immer noch geboten, aber jetzt jedem selbst überlassen.


*⚠️ Wichtig*: Bitte nur dann anmelden, wenn ihr absolut sicher seid, 
dass ihr auch kommt. Angesichts der begrenzten Anzahl Plätze, haben wir 
kein Verständnis für kurzfristige Absagen oder No-Shows.



   Einleitung

Das Python Meeting Düsseldorf  ist eine regelmäßige 
Veranstaltung in Düsseldorf, die sich an Python Begeisterte aus der 
Region wendet.


Einen guten Überblick über die Vorträge bietet unser PyDDF YouTube-Kanal 
, auf dem wir Videos der Vorträge nach 
den Meetings veröffentlichen.


Veranstaltet wird das Meeting von der eGenix.com GmbH 
, Langenfeld, in Zusammenarbeit mit Clark 
Consulting & Research , Düsseldorf:



   Format

Das Python Meeting Düsseldorf  nutzt eine Mischung aus 
(Lightning) Talks und offener Diskussion.


Vorträge können vorher angemeldet werden, oder auch spontan während des 
Treffens eingebracht werden. Ein Beamer mit XGA Auflösung steht zur 
Verfügung.


(Lightning) Talk Anmeldung bitte formlos per EMail an [email protected] 




   Kostenbeteiligung

Das Python Meeting Düsseldorf  wird von Python Nutzern 
für Python Nutzer veranstaltet.


Da Tagungsraum, Beamer, Internet und Getränke Kosten produzieren, bitten 
wir die Teilnehmer um einen Beitrag in Höhe von EUR 10,00 inkl. 19% 
Mwst. Schüler und Studenten zahlen EUR 5,00 inkl. 19% Mwst.


Wir möchten alle Teilnehmer bitten, den Betrag in bar mitzubringen.


   Anmeldung

Da wir nur 25 Personen in dem angemieteten Raum empfangen können, 
möchten wir bitten, sich vorher anzumelden.


   *Meeting Anmeldung* bitte per Meetup
   


   Weitere Informationen

Weitere Informationen finden Sie auf der Webseite des Meetings:

https://pyddf.de/

Viel Spaß !

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Mar 16 2023)

Python Projects, Coaching and Support ...https://www.egenix.com/
Python Product Development ...https://consulting.egenix.com/



::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48

D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   https://www.egenix.com/company/contact/
 https://www.malemburg.com/
--
https://mail.python.org/mailman/listinfo/python-list


Friday finking: IDE 'macro expansions'

2023-03-16 Thread dn via Python-list
It is a long, long, time since I've thrown one of these into the 
maelstrom of our musings.

(have the nightmares receded?)


Do you make use of your IDE's expansionist tendencies, and if-so, which 
ones?



NB this is where vi/emacs enthusiasts start chuckling (polite term for 
'insane cackling'). Hence the question's limitation to IDEs, cf 'editors'!
Also: I'm talking 'PyCharm' because of the story, but others use Codium, 
Sublime Text, etc - which presumably offer equivalent features.



Was helping a friend install PyCharm. Jumped into the Settings. Isn't it 
incredible how many there are?


Idly noted that there are two short-cut or macro-expansion types of 
facilities:

- Postfix Completion, (nothing to do with email or polish notation) and
- Live Templates (again, we're not talking about jinja2)


With both, one types an abbreviated-name and the IDE will expand it into 
appropriate code. For (LiveTemplate) example, typing compli and pressing 
Tab induces PyCharm to add the following to the program[me]:


[ ! for ! in !drop-down menu! if ! ]

It offers further typo-saving through the drop-down menu which lists a 
bunch of likely (iterable) candidates from amongst previously-written 
code. The action continues after selecting from the menu, by inviting 
completion of the other ("!") placeholders, in-turn.



I haven't made use of such a tool, to-date - OK, yes, I have practised a 
high typing-speed (and accuracy). Puff, puff...


Also, at the time, I'm thinking in 'code', rather than about what tool 
might implement said ideas.



Do you make use of such expansionist-tendencies?

Do you make use of other powerful features within the IDE, or are its 
editor functionalities employed at pretty-much the NotePad level?




Web.Refs:
https://www.jetbrains.com/help/pycharm/settings-postfix-completion.html
https://www.jetbrains.com/help/pycharm/using-live-templates.html#live_templates_types
--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday finking: IDE 'macro expansions'

2023-03-16 Thread Mats Wichmann

On 3/16/23 16:55, dn via Python-list wrote:
It is a long, long, time since I've thrown one of these into the 
maelstrom of our musings.

(have the nightmares receded?)


Do you make use of your IDE's expansionist tendencies, and if-so, which 
ones?



NB this is where vi/emacs enthusiasts start chuckling (polite term for 
'insane cackling'). Hence the question's limitation to IDEs, cf 'editors'!
Also: I'm talking 'PyCharm' because of the story, but others use Codium, 
Sublime Text, etc - which presumably offer equivalent features.



Was helping a friend install PyCharm. Jumped into the Settings. Isn't it 
incredible how many there are?


Idly noted that there are two short-cut or macro-expansion types of 
facilities:

- Postfix Completion, (nothing to do with email or polish notation) and
- Live Templates (again, we're not talking about jinja2)


With both, one types an abbreviated-name and the IDE will expand it into 
appropriate code. For (LiveTemplate) example, typing compli and pressing 
Tab induces PyCharm to add the following to the program[me]:


     [ ! for ! in !drop-down menu! if ! ]

It offers further typo-saving through the drop-down menu which lists a 
bunch of likely (iterable) candidates from amongst previously-written 
code. The action continues after selecting from the menu, by inviting 
completion of the other ("!") placeholders, in-turn.



I haven't made use of such a tool, to-date - OK, yes, I have practised a 
high typing-speed (and accuracy). Puff, puff...


Also, at the time, I'm thinking in 'code', rather than about what tool 
might implement said ideas.



Do you make use of such expansionist-tendencies?

Do you make use of other powerful features within the IDE, or are its 
editor functionalities employed at pretty-much the NotePad level?


Not sure the purpose of the "survey" but - no, I don't use these.  IDEs 
are incredible things, but you need to invest yourself completely in 
them, basically live in them, or there's not that much payback. There's 
just too much to remember, and honestly, too much mouse movement needed, 
especially if you have a big screen. In the PyCharm case, the startup 
time is incredibly slow, so, since I don't "live in it", I don't use it 
much any more - there are some things it does superbly, but it's such a 
cost to fire it up just for those I pretty much don't bother any more.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday finking: IDE 'macro expansions'

2023-03-16 Thread Thomas Passin

On 3/16/2023 6:55 PM, dn via Python-list wrote:
It is a long, long, time since I've thrown one of these into the 
maelstrom of our musings.

(have the nightmares receded?)


Do you make use of your IDE's expansionist tendencies, and if-so, which 
ones?



NB this is where vi/emacs enthusiasts start chuckling (polite term for 
'insane cackling'). Hence the question's limitation to IDEs, cf 'editors'!
Also: I'm talking 'PyCharm' because of the story, but others use Codium, 
Sublime Text, etc - which presumably offer equivalent features.



Was helping a friend install PyCharm. Jumped into the Settings. Isn't it 
incredible how many there are?


Idly noted that there are two short-cut or macro-expansion types of 
facilities:

- Postfix Completion, (nothing to do with email or polish notation) and
- Live Templates (again, we're not talking about jinja2)


With both, one types an abbreviated-name and the IDE will expand it into 
appropriate code. For (LiveTemplate) example, typing compli and pressing 
Tab induces PyCharm to add the following to the program[me]:


     [ ! for ! in !drop-down menu! if ! ]

It offers further typo-saving through the drop-down menu which lists a 
bunch of likely (iterable) candidates from amongst previously-written 
code. The action continues after selecting from the menu, by inviting 
completion of the other ("!") placeholders, in-turn.



I haven't made use of such a tool, to-date - OK, yes, I have practised a 
high typing-speed (and accuracy). Puff, puff...


Also, at the time, I'm thinking in 'code', rather than about what tool 
might implement said ideas.



Do you make use of such expansionist-tendencies?

Do you make use of other powerful features within the IDE, or are its 
editor functionalities employed at pretty-much the NotePad level?


In general, I don't like a lot of popups and code completions, so I tend 
to avoid them.  I don't even like automatic parens or brace insertion. 
They distract me, and often put the cursor somewhere I don't want it.


Of course, for Python code I do like automatic indentation after a 
colon: if the cursor ends up in the right place, then I'm happy.


If I'm using a plain editor, then I usually like EditPlus.  It's not 
free but the cost is low and it's well worth it (but Windows only).  It 
knows about file types, and can do various insertions and completions if 
you want (as I said, I mostly don't).  I also use Notepad++, but I more 
often go with EditPlus.


What I find more useful is matching brackets/parens/braces.  Not 
inserting them but highlighting or (better) jumping to the matching one 
when asked.


Otherwise I'm usually working in the Leo Editor, which is hard to 
explain in a few words but is a real gift, especially for Python 
programmers.  It does have an abbreviation capability that I use a 
little, but so far mostly for inserting symbols like math and Greek 
letters.  Leo is written in Python (with a Qt GUI) and you can easily 
get access to all its internals, so once you learn something about how 
it works, you can create scripts to do almost anything you want.


The Leo Editor is an MIT-licensed project on GitHub (I know I sound very 
positive but despite that, it's not my project; it really can grow on 
you - if you are willing to climb the learning curve).


--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday finking: IDE 'macro expansions'

2023-03-16 Thread 2QdxY4RzWzUUiLuE
On 2023-03-17 at 11:55:38 +1300,
dn via Python-list  wrote:

> Do you make use of your IDE's expansionist tendencies, and if-so, which
> ones?

Expansionist tendencies.  Nice phrase.  :-)

> NB this is where vi/emacs enthusiasts start chuckling (polite term for
> 'insane cackling') ...

Long time (since the 1980s, when you had to edit config.h and compile it
yourself) insane emacs enthusiast and "Unix is my IDE" claimant here.  I
used one language that required a special editor because the "source
code" was a semi-compiled byte stream instead of ASCII.  A coworker once
awarded me a black belt in vi for knowing how to indent and unindent
code.

They made me write in Java at my last job; that language encourages IDEs
beause they deny that the underlying OS and tools exist at all.  I used
to say that some of my coworkers weren't writing Java, they were writing
IntelliJ.

Anyway, the short answer to your question is no.

I think the main reason is that there are/were too many editors in too
many contexts to start depending on such features.  What happens if I'm
editing on a target box instead of my desktop?  What if I'm helping a
coworker, and they use a different editor (different tools for different
programmers)?

> I haven't made use of such a tool, to-date - OK, yes, I have practised a
> high typing-speed (and accuracy). Puff, puff...

I, too, type relatively quickly, which definitely relieves some of the
appeal.  Saving a few keystrokes isn't worth the extra congnitive load
to remember how to use those features.  And by the time I edit the
template, it's more keystrokes (and usually cursor motion and
placeholder deletion keystrokes not related to the programming task at
hand) than if I had typed the full code in the first place.

> Also, at the time, I'm thinking in 'code', rather than about what tool might
> implement said ideas.

Exactly.  Any excursion away from the programming language and the
programming task at hand is disruptive.

I did finally train myself to use Emacs' dabbrev-expand function, which
completes the current "word" according to the previous occurrance of
that word, which lets me use longer identifiers without having to type
them out or copy/paste them.  That said, I often find myself typing
stuff out anyway, again because any deviation from writing code is a
deviation from writing code.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Friday finking: IDE 'macro expansions'

2023-03-16 Thread Grant Edwards
On 2023-03-16, Thomas Passin  wrote:

> In general, I don't like a lot of popups and code completions, so I
> tend to avoid them.  I don't even like automatic parens or brace
> insertion.

I _hate_ it when the "editor" decides to insert stuff I didn't
type. There's an html editor I use occasionally that auto-inserts the
closing tag when you type an opening tag. It's, always, 100% of the
time, wrong. Either the tag ends up in the wrong place, or it's a
duplicate because there was already a closing tag.

> They distract me, and often put the cursor somewhere I don't want it.

Maybe it matters how good a typist you are, but I don't really
concentrate that hard on watching the letters show up on the screen,
so any sort of "IDE know better than you do" stuff tends to trip me
up.

> Of course, for Python code I do like automatic indentation after a 
> colon: if the cursor ends up in the right place, then I'm happy.

Yep, I do allow emacs to do auto indent.

> If I'm using a plain editor, then I usually like EditPlus.  It's not
> free but the cost is low and it's well worth it (but Windows only).
> It knows about file types, and can do various insertions and
> completions if you want (as I said, I mostly don't).  I also use
> Notepad++, but I more often go with EditPlus.
>
> What I find more useful is matching brackets/parens/braces.  Not 
> inserting them but highlighting or (better) jumping to the matching one 
> when asked.

Same here.



-- 
https://mail.python.org/mailman/listinfo/python-list