Re: Import issue in python packages

2018-08-11 Thread Venkatesh Adiga
Thanks Peter... What are the ways to update outside of the python program
without defining environment variable for source code path Otherwise
can I do it once in during initialization of sys.path update?


On Fri, 10 Aug 2018, 10:56 pm Peter Otten, <[email protected]> wrote:

> Venkatesh Adiga wrote:
>
> > Hi All,
> >
> > I am facing issue with python package import.
> > In my project, I have many directories with different python classes
> > defined within them. I am trying to import those classes in another
> python
> > program, but not able to import them.
> > Here are my directories and file structures.
> >   src/platform/operatingsys.py : Defined OperatingSystem Class
> >   src/platform/ipc.py : Defined IPC class
> >   src/platform/MyThread.py: Defined MyThread class
> >   src/platform/__init__.py - zero sized file
> >
> >   src/utils/abc.py
> >   src/utils/def.py
> >   src/utils/__init__.py
> >
> >   src/api/xyz.py
> >   src/api/__init__.py
> >
> >   src/unittest/TestSuite.py - Defined UnitTest Class
> >   src/unittest/__init__.py
> >   src/__init__.py
> >
> >
> > Now, I am trying to use the above classes in another python program(
> > TestPackage.py) as below:
> >
> >
> > *from src.platform.operatingsys import OperatingSystem*
> > .
> > --
> > Execution of TestPackage.py throws an error as below
> >
> >  ImportError: No module named 'src'
> >
> > Currently I have a working code which prefixes sys.path with every
> > directory defined in the package list before import any classes.
> >
> > sys.path.append("src/unittest/")
> > import OperatingSystem
> >
> > But I do not have the hard-coded path and append to sys.path variable.
> > So my question is:
> > 1)  Is there any better way of having the sys.path variable appended by
> > directory listing?
> > 2)  What changes i need to do so that my import statement looks like
> > below:
> >*from src.platform.operatingsys import OperatingSystem*
> >
> > Please suggest...
>
> Ensure that src is in your PYTHONPATH, preferrably as an absolute path.
> Then import the packages and modules without the src prefix, e. g.
>
> sys.path.append("/path/to/src")
> import platform.operatingsys
>
> If you insist on src as part of the import the directory's parent needs to
> be in the path:
>
> sys.path.append("/path/to")
> import src.platform.operatingsys
>
> Note that it's better to avoid manipulating sys.path from within your
> scripts. If at all possible install your packages or at least add .pth
> files
> or a PYTHONPATH environment variable.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can't figure out how to do something using ctypes (and maybe struct?)

2018-08-11 Thread Peter Otten
inhahe wrote:

> I need to make a list of instances of a Structure, then I need to make an
> instance of another Structure, one of the fields of which needs to be an
> arbitrary-length array of pointers to the instances in the list. How do I
> do that?
> 
> Just in case it helps, I'll include what I tried that didn't work:
> --
> class NoteEvent(ctypes.Structure):
>   _fields_ = [('type', ctypes.c_int),
>   ('byteSize', ctypes.c_int),
>   ('deltaFrames', ctypes.c_int),
>   ('flags', ctypes.c_int),
>   ('noteLength', ctypes.c_int),
>   ('noteOffset', ctypes.c_int),
>   ('commandCode', ctypes.c_char),
>   ('noteNumber', ctypes.c_char),
>   ('velocity', ctypes.c_char)]
> 
> def mkVstEvents(events):
>   class Events(ctypes.Structure):
> _fields_ = [('numEvents', ctypes.c_int),
> ('reserved', ctypes.c_int),
> ('eventspointerarray', ctypes.c_void_p * len(events))]
>   return Events(len(events), 0, tuple([ctypes.pointer(event) for event in
> events]))

...

> RuntimeError: (c_void_p_Array_1) :
> incompatible types, LP_NoteEvent instance instead of c_void_p instance

Two things that you can try:

> ('eventspointerarray', ctypes.c_void_p * len(events))]

Either change c_void_p to POINTER(NoteEvent) like

https://stackoverflow.com/questions/7015487/ctypes-variable-length-structures

or cast the NoteEvent pointer to void *:

>   return Events(len(events), 0, tuple([ctypes.pointer(event) for event in
> events]))

... cast(pointer(event), c_void_p) ...


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


Re: Import issue in python packages

2018-08-11 Thread Peter Otten
Venkatesh Adiga wrote:

> Thanks Peter... What are the ways to update outside of the python program
> without defining environment variable for source code path Otherwise
> can I do it once in during initialization of sys.path update?

I don't understand the question. Your options are

- install your modules/packages in a directory already in sys.path
- put .pth file in a directory already in sys.path
- set PYTHONPATH
- manipulate sys.path at runtime

In my experience the last option has a tendency to break things which is why 
I prefer any of the other ones. It's your choice however.

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


[ANN] aioxmpp 0.10.1 released

2018-08-11 Thread Jonas Wielicki
Dear subscribers,

We are pleased to announce the release of aioxmpp 0.10.1. The current release 
can be obtained from GitHub [1] (check out the v0.10.1 tag) or PyPI [2]. The  
HTML documentation can be found at [3]. Examples can be found in the GitHub  
repository, in the examples sub directory.

aioxmpp is a Python library based on asyncio. It implements the client side of  
the XMPP protocol (RFC 6120 and others). For a more detailed description of  
the package, please review the README of the package on GitHub [1] or on PyPI 
[2]. For more information on XMPP, please see [8]. aioxmpp is licensed under  
the terms of the GNU Lesser General Public License Version 3.0 or later.


Version 0.10.1 is a bugfix release with possible security implications. 

It was discovered that two types of specifically crafted (invalid) IQ stanzas 
could make aioxmpp 0.10.0 disconnect, leading to a Denial-of-Service type 
effect. We decided to push a release quickly to fix this issue. Thanks to 
Martin for discovering and reporting the issue.


Bugs, feature requests, patches and questions can be directed to either the 
aioxmpp mailing list [4], the GitHub issue tracker [5] or the XMPP Multi-User 
chat [6], whatever floats your boat. Please direct security-relevant issue 
reports directly to me ([email protected]), preferably encrypted using my 
GPG public key [7].

kind regards,
Jonas

   [1]: https://github.com/horazont/aioxmpp
   [2]: https://pypi.python.org/pypi/aioxmpp
   [3]: https://docs.zombofant.net/aioxmpp/0.10/
   [4]: https://lists.zombofant.net/mailman/listinfo/aioxmpp-devel
   [5]: https://github.com/horazont/aioxmpp/issues
   [6]: [email protected]
   [7]: https://sks-keyservers.net/pks/lookup?op=get&search=0xE5EDE5AC679E300F
AA5A 78FF 508D 8CF4 F355  F682 E5ED E5AC 679E 300F
   [8]: https://xmpp.org/



signature.asc
Description: This is a digitally signed message part.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python-Tkinter issue. Multiple overlaping event routines called by single click

2018-08-11 Thread wfgazdzik
I have a main window open.  Then I open a tk.TopLevel dialog window giving the 
user multiple choices.  He selects one, the corresponding event is executed.  
Then in the underlining main window, just by chance there is another button 
exactly under the mouse click in the TopLevel dialog window.  Its corresponding 
event is then triggered.

How can I keep the main window button that just happens to be in the wrong 
place from being triggered?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python-Tkinter issue. Multiple overlaping event routines called by single click

2018-08-11 Thread Peter Otten
[email protected] wrote:

> I have a main window open.  Then I open a tk.TopLevel dialog window giving
> the user multiple choices.  He selects one, the corresponding event is
> executed.  Then in the underlining main window, just by chance there is
> another button exactly under the mouse click in the TopLevel dialog
> window.  Its corresponding event is then triggered.
> 
> How can I keep the main window button that just happens to be in the wrong
> place from being triggered?

Please post a small script that shows the behaviour described above. That 
will give us some common ground to talk about.

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


Re: Python-Tkinter issue. Multiple overlaping event routines called by single click

2018-08-11 Thread MRAB

On 2018-08-11 21:01, [email protected] wrote:

I have a main window open.  Then I open a tk.TopLevel dialog window giving the 
user multiple choices.  He selects one, the corresponding event is executed.  
Then in the underlining main window, just by chance there is another button 
exactly under the mouse click in the TopLevel dialog window.  Its corresponding 
event is then triggered.

How can I keep the main window button that just happens to be in the wrong 
place from being triggered?

The handler should return the string "break" to prevent the event from 
propagating further. Are you doing that? It's surprising how far you can 
go without it before running into a problem!

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


Re: Python-Tkinter issue. Multiple overlaping event routines called by single click

2018-08-11 Thread Steven D'Aprano
On Sat, 11 Aug 2018 13:01:44 -0700, wfgazdzik wrote:

> I have a main window open.  Then I open a tk.TopLevel dialog window
> giving the user multiple choices.  He selects one, the corresponding
> event is executed.  Then in the underlining main window, just by chance
> there is another button exactly under the mouse click in the TopLevel
> dialog window.  Its corresponding event is then triggered.

Sounds to me that the user is clicking twice, once in the dialog, and 
then a second time just as it disappears and the main window takes focus.

Possibly they are trying to double-click.

Or their mouse is faulty.

Unless you can replicate this with multiple users, the most likely cause 
is user-error. And unless you can eliminate user-error, trying to work-
around users who click randomly is a nightmare. How do you decide which 
clicks are intended and which are not?


> How can I keep the main window button that just happens to be in the
> wrong place from being triggered?

If you put in a delay between enacting the event and closing the dialog, 
I reckon the problem will go away... but instead you'll have two click 
events in the dialog.

But it seems like an interesting experiment... put time.sleep(0.3) at the 
end of the event handler and see what happens.



-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: Python-Tkinter issue. Multiple overlaping event routines called by single click

2018-08-11 Thread Steven D'Aprano
On Sun, 12 Aug 2018 01:30:43 +0100, MRAB wrote:

> On 2018-08-11 21:01, [email protected] wrote:
>> I have a main window open.  Then I open a tk.TopLevel dialog window
>> giving the user multiple choices.  He selects one, the corresponding
>> event is executed.  Then in the underlining main window, just by chance
>> there is another button exactly under the mouse click in the TopLevel
>> dialog window.  Its corresponding event is then triggered.
>> 
>> How can I keep the main window button that just happens to be in the
>> wrong place from being triggered?
>> 
> The handler should return the string "break" to prevent the event from
> propagating further. Are you doing that? It's surprising how far you can
> go without it before running into a problem!

I think you are mistaken:

https://stackoverflow.com/a/12357536

but since the description of the problem is so vague, it is hard to tell 
exactly what's happening.


-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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