[issue39025] Windows Python Launcher does not update PATH to Scripts directory
Bluebird added the comment: Ok, I'll close my request if you do not think of any value in it. Py is such an elegant solution, I wish something as simple would also address this problem. Virtual environement do have the downside of not coming directly with Python. In my work environment, extra Python packages are strongly discouraged and my colleagues are not proficient enough in the Python ecosystem to use venv. -- resolution: -> rejected stage: -> resolved status: open -> closed ___ Python tracker <https://bugs.python.org/issue39025> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39025] Windows Python Launcher does not update PATH to Scripts directory
Bluebird added the comment: Thanks for the quick feedback. I agree that it makes sense for python modules to support -m. However, PyQt comes with many executables originally written in C++ for Qt (designer, assistant). It feels a bit strange to add a module with that name, just for the purpose of creating a -m target so that you can run it without Scripts in path. Moreover, some of these C++ exectuables depends on DLL which are only in the Scripts directory and it might not work. I do not think that your proposal addresses the full problem. -- ___ Python tracker <https://bugs.python.org/issue39025> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39025] Windows Python Launcher does not update PATH to Scripts directory
New submission from Bluebird : The py Python launcher is a great improvement over a few years ago when managing multiple Python installation was tedious. However, it does not solve one annoying problem: the Scripts directory. If you install tools like mypy, pyqt-tools or pyinstaller, to be able to use them, you need to have the Scripts directory in your PATH variable. And if you have multiple Python installations, you are back to square 1 where you have to explicitely modify your PATH according to the version of Python where the tools have been installed. To give a practical example, at work, I have Python 3.1 because some of our software are distributed as .pyc for this version of Python, Python 3.5 for the same reason and Python 3.7 for all the developments which do not incur the previous dependencies. The default environement with Python and Python\Scripts added to the path is Python 3.5 . However, for all PyQt developments, I use Python 3.7 . I launch my program with py -3.7 myfancygui.py but when I want to access some of the pyqt tools like pyuic5, I need to explicitely add Python3.7\Scripts to my PATH. The technical solution is not clear to me, but it would be nice to duplicate the benefits of the py launcher to the Scripts directory. Some random propositions: 1. Create a pyscript launcher, which would work like py but would take as command-line the name of the script to run: pyscript -3.7 pyuic5 2. Let py execute a command-line with proper environment for that specific version of python: > py -env-3.7 Environment adjusted for Python 3.7 > pyuic5 ... works fine > exit Back to default environement There are probably other stratagic ways to reach the same result. -- components: Windows messages: 358256 nosy: bluebird, paul.moore, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: Windows Python Launcher does not update PATH to Scripts directory type: enhancement versions: Python 3.7 ___ Python tracker <https://bugs.python.org/issue39025> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
unicode printing on Windows
Hi, The question is not totally related to Python but there is a strong connection. Everytime that I try to debug some python programs under Windows, I encounter the issue that things printed on the console simply break the program because : 1. My windows console does not support UTF8 2. Things printed by the program on the stdout / stderr do not necessarily use sys.getpreferredencoding() so break with UnicodeError. Does anybody know how to fix problem 1 ? That way, I could at least deal with programs that print UTF8 on stdout. Regarding point 2, I must admit even when I am the author of the program, printing debug information (in unicode) on the stdout is a really really tricky thing. Is there a recommendation on how to do that properly ? Important information : I am using Python 2.5 cheers, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Deeply nested dictionaries - should I look into a database or am I just doing it wrong?
I love named tuples, they rock for this kind of task: storing complicated structure in a python compatible way, without too much hassle. And as far as load/save on disk is concerned, I simply use regular python structure with safe eval [1]. I get all the flexibility that I need for the file format, without the annoyance of writing a conversion layer. [1]: http://code.activestate.com/recipes/364469-safe-eval/ -- http://mail.python.org/mailman/listinfo/python-list
Re: SOAP 1.2 Python client ?
On 5 mar, 13:19, lbolla lbo...@gmail.com wrote: On Mar 5, 10:01 am, BlueBird p...@freehackers.org wrote: On 3 mar, 20:35, Stefan Behnel stefan...@behnel.de wrote: BlueBird, 03.03.2010 17:32: I am looking for aSOAP1.2 python client. To my surprise, it seems that this does not exist. Does anybody know about this ? SOAPmay be an overly bloated protocol, but it's certainly not black magic. It's not hard to do manually if you really need to: http://effbot.org/zone/element-soap.htm But this requires a goog knowloedge ofSOAP, in order to parse everything correctly. The reason I want to use a ready-made client is that I have about zero knowledge aboutSOAP, and even more in the differences betweenSOAP1.1 and 1.2 . cheers, Philippe I use a thin custom-made python wrapper around gSoap[1], which is tens of times faster than ZSI. I looked at gSoap and the solution seemed really nice. They can generate C that I can call with ctypes. The only problem is that I am working on a closed source software and their licensing cost for close source were too expensive for my company. After much much digging, we found out the problem and managed to solve it with SUDS. When calling a .NET service, you should not reference the soap envelope spec with 'http://schemas.xmlsoap.org/soap/ envelope/' but with 'http://schemas.xmlsoap.org/soap/envelope' . The .NET server implementation seems to be very picky about the last / . Yeah for SUDS and oh for .NET cheers, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: SOAP 1.2 Python client ?
On 3 mar, 20:35, Stefan Behnel stefan...@behnel.de wrote: BlueBird, 03.03.2010 17:32: I am looking for a SOAP 1.2 python client. To my surprise, it seems that this does not exist. Does anybody know about this ? SOAP may be an overly bloated protocol, but it's certainly not black magic. It's not hard to do manually if you really need to: http://effbot.org/zone/element-soap.htm But this requires a goog knowloedge of SOAP, in order to parse everything correctly. The reason I want to use a ready-made client is that I have about zero knowledge about SOAP, and even more in the differences between SOAP 1.1 and 1.2 . cheers, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Docstrings considered too complicated
On Feb 24, 9:23 pm, Andreas Waldenburger use...@geekmail.invalid wrote: Hi all, a company that works with my company writes a lot of of their code in Python (lucky jerks). I've seen their code and it basically looks like this: Function that does stuff def doStuff(): while not wise(up): yield scorn Now my question is this: How do I kill these people without the authorities thinking they didn't deserve it? If they are generating their doc with doxygen, I think it's the right choice. See: http://www.stack.nl/~dimitri/doxygen/docblocks.html#pythonblocks Oops, after a second look, doxygen needs comments before the function, not doc strings. Philippe -- http://mail.python.org/mailman/listinfo/python-list
SOAP 1.2 Python client ?
Hi, I am looking for a SOAP 1.2 python client. To my surprise, it seems that this does not exist. Does anybody know about this ? The following clients seem to be both unmaintained and still supporting only SOAP 1.1 : - SUDS - zsi - SOAPy cheers, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Memory footpring of python objects
Hi, I have a program that manages several thousands instances of one object. To reduce memory consumption, I want of course that specific object to have the smallest memory footpring possible. I have a few ideas that I want to experiment with, like using __slots__, using a tuple or using a dict. My question is: how do I know the memory footprint of a given python object ? I could not find any builtin functions for this in the documentation. cheers, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory footpring of python objects
On 22 avr, 11:56, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: On Wed, 22 Apr 2009 02:30:32 -0700, Chris Rebert wrote: On Wed, Apr 22, 2009 at 2:24 AM, BlueBird p...@freehackers.org wrote: Hi, I have a program that manages several thousands instances of one object. To reduce memory consumption, I want of course that specific object to have the smallest memory footpring possible. I have a few ideas that I want to experiment with, like using __slots__, using a tuple or using a dict. My question is: how do I know the memory footprint of a given python object ? I could not find any builtin functions for this in the documentation. sys.getsizeof() -http://docs.python.org/library/sys.html#sys.getsizeof Only in Python 2.6. But if you search Activestate, there's a recipe to do the same thing. Ah, here it is: http://code.activestate.com/recipes/546530/ Thanks. There is always a tool that makes you realise how you are less smart than you thought - Andrew Morton, about git. I had a bit of hard time getting through the different sizes reported and the vocabulary. From what I understood, basicsize is the size of the object alone, without the size of his references. And asizeof( x, code=False, limit=100 ) will give me the memory footprint of a new instance of an object. In my case, I just want an object with named attributes. My two attempts for comparison: import sys, asizeof def print_sizeof( v_name, v ): print 'Size of %s: %d, %d' % (v_name, asizeof.flatsize(v), asizeof.asizeof(v, code=False, limit=100) ) def test_impl( v ): assert v.a == 1 assert v.b == 'bbb' assert v.c == False ### The reference, a dictionnary ref_dict = {'a':1, 'b':'bbb', 'c':False } print_sizeof( 'ref_dict', ref_dict ) ### A modified dictionnary class AttrDict (dict): Dictionary allowing attribute access to its elements if they are valid attribute names and not already existing methods. def __getattr__ (self, name): return self[name] attrDict = AttrDict( ref_dict ) test_impl( attrDict ) print_sizeof( 'attrDict', attrDict ) ### Using __slots__ class ObjWithSlots(object): __slots__ = [ 'a', 'b', 'c' ] objWithSlots = ObjWithSlots() for k in ref_dict: setattr( ObjWithSlots, k, ref_dict[k] ) test_impl( objWithSlots ) print_sizeof( 'ObjectWithSlots', objWithSlots ) is giving me: Size of ref_dict: 140, 304 Size of attrDict: 140, 304 Size of ObjectWithSlots: 36, 144 So, it looks like I could shrink down the structure to 144 bytes in a simple case. Marco, my objects have varying length data structures (strings) so I don't think that would be possible. And it would clearly be overkill in my case. -- http://mail.python.org/mailman/listinfo/python-list
[issue5190] optparse doex not export make_option
New submission from Bluebird p...@freehackers.org: The documentation of optparse mentions make_option() as the standard way to create an option list: For example, in the doc of python 2.5: 14.3.3.2 Populating the parser [...] pass it an Option instance (as returned by make_option()) [...] option_list = [ make_option(-f, --filename, action=store, type=string, dest=filename), make_option(-q, --quiet, action=store_false, dest=verbose), ] (make_option() is a factory function for creating Option instances; currently it is an alias for the Option constructor. A future version of optparse may split Option into several classes, and make_option() will pick the right class to instantiate. Do not instantiate Option directly.) === However, make_option is not part of the function exported in the __all__ list of optparse. Strangely enough, this does not prevent to use make_option() in regular python scripts, but it does not work when packaging a python application, for example with pyinstaller. The problem is also present in python 2.6 The fix is either to update the documentation to use Option() directly or to add make_option to __all__ -- assignee: georg.brandl components: Documentation, Library (Lib) messages: 81456 nosy: bluebird, georg.brandl severity: normal status: open title: optparse doex not export make_option type: behavior versions: Python 2.5, Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5190 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Event Handling and Signal-Slot Mechanism
On Jan 19, 4:10 am, Steven Woody narkewo...@gmail.com wrote: Hi, Python has Signal-Slot mechanism, Python does not have signal/slot mechanism. You are talking about the Qt toolkit, which is initially a (nice) C++ toolkit, available also in python via the PyQt wrapper. Signal/slots were introduced by Qt to make C++ gui programming easier. Signal/slots basically provides a very easy way to implement the observer/consumer design pattern, with only 2 or 3 lines of code (as opposed to one or two classes in java for example). Python itself does not have signal/slots but the it's very easy to emulate them using the Python language. In C++ however, it's tricky to do signal/slots in pure C++ and this addition is one of the reason that programming GUI in Qt is nice (personal opinion obviously). To comne back to your question: why he still need another mechanism Event Handling? This is actually a Qt question: why have event handling for some things, and signal/slot for some others ? My opinion on the debate: - signal/slot add an overhead of one class to every QObject class, and 3 method calls when emitting a signal (if I remember Qt documentation correctly). For some real-time tasks, like repainting the screen, every microseconds must be saved and sparing 3 method calls is a good idea. - since a GUI application is fundamentally an event driven system, the event stuff has to be there anyway. - signal/slot is very convenient for data exchange between widgets but I think it would be overkill to use it everywhere. Event propagation is a nice design as well. Now, if you want to discuss this further, I suggest to go to Qt interest ( http://lists.trolltech.com/qt-interest/ ) which is dedicated to discussion around Qt. cheers, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: How to kill orphaned threads at program exit
On Dec 28 2008, 6:33 pm, Giampaolo Rodola' gne...@gmail.com wrote: Hi, I know that it's not possible to kill threads but I'm wondering if does exist some workaround for my problem. I have a test suite which does a massive usage of threads. Sometimes happens that one test fails, the test suite keeps running until the end, and when it's finished the program hangs on and the only way to stop is to kill it manually. I noticed that, at the end of the program, I can call threading.enumerate() and see the pending thread objects: Hi, The way I handle it is to make sure that after each test, the thread count has returned to what I expect. It is possible to kill a thread if it's not blocked on a system call. It's highly unrecommended for standard usage but your use case exactly the one where the ability to kill a thread is very useful. I use the following code, which I borrowed to the Python Cook book somewhere: def _async_raise(tid, exctype): '''Raises an exception in the threads with id tid''' if not inspect.isclass(exctype): raise TypeError(Only types can be raised (not instances)) res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) if res == 0: raise ValueError(invalid thread id) elif res != 1: # if it returns a number greater than one, you're in trouble, # and you should call it again with exc=NULL to revert the effect ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0) raise SystemError(PyThreadState_SetAsyncExc failed) class ThreadWithExc(threading.Thread): '''A thread class that supports raising exception in the thread from another thread. ''' def _get_my_tid(self): determines this (self's) thread id CAREFUL : this function is executed in the context of the caller thread, to get the identity of the thread represented by this instance. if not self.isAlive(): raise threading.ThreadError(the thread is not active) # do we have it cached? if hasattr(self, _thread_id): return self._thread_id # no, look for it in the _active dict for tid, tobj in threading._active.items(): if tobj is self: self._thread_id = tid return tid # TODO : in python 2.6, there's a simpler way to do : self.ident ... raise AssertionError(could not determine the thread's id) def raiseExc(self, exctype): Raises the given exception type in the context of this thread. If the thread is busy in a system call (time.sleep(), socket.accept(), ...) the exception is simply ignored. If you are sure that your exception should terminate the thread, one way to ensure that it works is: t = ThreadWithExc( ... ) ... t.raiseExc( SomeException ) while t.isAlive(): time.sleep( 0.1 ) t.raiseExc( SomeException ) If the exception is to be caught by the thread, you need a way to check that your thread has caught it. CAREFUL : this function is executed in the context of the caller thread, to raise an excpetion in the context of the thread represented by this instance. _async_raise( self._get_my_tid(), exctype ) cheers, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: How to distribute a Python app together with its dependencies?
Alessio Pace wrote: Hi, I have to distribute a Python application which relies on an external library, and I'm not very fluent in this kind of stuff with Python (I come from the Java world where I would have used the Maven build tool to create an assembly with dependencies of all it is needed to run the app), so I was wondering if someone here could give me some suggestions :-) The external library is generally not present on the machines where I have to distribute my app, and the set of machines on which I have to distribute this application is not known a priori (it is just known they are Unix systems). In fact by means of SSH I will have to copy (and install) the app+library and make it runnable onto the specified destination(s). I have never used it myself, but bbfreeze claims to create packaged versions of an application, for windows and Unix : http://pypi.python.org/pypi/bbfreeze/0.95.2 cheers, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Interrupt python thread
On Aug 24, 8:35 pm, Dennis Lee Bieber [EMAIL PROTECTED] wrote: On Sun, 24 Aug 2008 01:48:46 -0700 (PDT), BlueBird [EMAIL PROTECTED] declaimed the following in comp.lang.python: Whenever an exception occurs, in the master thread or in one of the slave threads, I would like to interrupt all the threads and the main program. Threading API does not seem to provide a way to stop a thread, is there anyway to achieve that ? The only safe way to abort a thread is by having it exit on its own. This means one needs a means of setting an attribute that each thread periodically checks within a while loop. Unfortunately, this does not map very well with my program. Each of my threads are calling foreign code (still written in python though), which might be busy for 1 to 10 minutes with its own job. I wanted something to easily interrupt every thread to prevent my program to stall for 10 minutes if I want to stop it (getting tired of killing python all the time). Philippe -- http://mail.python.org/mailman/listinfo/python-list
Interrupt python thread
Hi, I have a program with a master thread and several slave threads. Whenever an exception occurs, in the master thread or in one of the slave threads, I would like to interrupt all the threads and the main program. Threading API does not seem to provide a way to stop a thread, is there anyway to achieve that ? The closest thing I found is thread.interrupt_main() but it's far from perfect : - it only allow to interrupt the main thread - if the main thread is sleeping, it does not interrupt it (at least on windows) cheers, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Continuous integration for Python projects
On Jul 29, 4:56 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: Hussein B wrote: Hi. Please correct my if I'm wrong but it seems to me that the major continuous integration servers (Hudson, CruiseControl, TeamCity ..) don't support Python based application. It seems they mainly support Java, .NET and Ruby. Can I use one of the previous listed servers for Python project? Hudson can, and AFAIK CC as well - they only invoke shell-scripts (at least hudson does, and CC you can convince doing that using ANT) I have CC almost running here with python tests and there is no technical problem in front. You must package your test scripts so that they exit with something different than 0 in case of failure, and then just use the Exec runner of CC to run them. -- http://mail.python.org/mailman/listinfo/python-list
[issue839496] SimpleHTTPServer reports wrong content-length for text files
Bluebird [EMAIL PROTECTED] added the comment: I confirm that the problem is present on python2.5 on windows, and that the attached patch fixes it. -- nosy: +bluebird ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue839496 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: how to use subprocess.Popen execute find in windows
On May 6, 11:19 am, [EMAIL PROTECTED] wrote: In cmd, I can use find like this. C:\netstat -an | find 445 TCP0.0.0.0:4450.0.0.0:0 LISTENING UDP0.0.0.0:445*:* C:\ And os.system is OK. import os os.system('netstat -an | find 445') TCP0.0.0.0:4450.0.0.0:0 LISTENING UDP0.0.0.0:445*:* 0 But I don't know how to use subprocess.Popen to do this. from subprocess import Popen, PIPE p1 = Popen(['netstat', '-an'], stdout = PIPE) p2 = Popen(['find', '445'], stdin = p1.stdout, stdout = PIPE) print p2.stdout.read() I would say that, according to documentation, the following should work: print p2.communicate()[0] Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: How to generate binary python?
On May 6, 6:29 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Mon, 05 May 2008 19:43:24 -0300, David Anderson [EMAIL PROTECTED] escribió: Hi, i'm comingo from Java and I'm wanting to know what in Python is the equivalent to the file.class in java, I am producing some apps that ar not open source, so I would like to share only the binaries, Both for Windows and for Linux, Can you suggest me anything? .class files map roughly to .pyc files Note that Python generates and writes .pyc files automatically when you import a module, but not for the main script being executed. The standard way to generate a binary distribution is using distutils, see the Python wiki at http://wiki.python.org/moin/DistributionUtilities You can have a look at the following page for a very very short comparison of the different solutions available today: http://www.freehackers.org/Packaging_a_python_program -- http://mail.python.org/mailman/listinfo/python-list
Re: python scripts to standalone executable
On Mar 31, 7:24 pm, Amit Gupta [EMAIL PROTECTED] wrote: Hi I am looking for a some tool that can convert python scripts to executable on Linux. I found freeeze.py as the only option so far. Couple of queries on freeze: 1. Have anyone used the freeze utility and any experiences to share from that? 2. Is there any enterprise-level exe-builder for python on linux (ActiveState has nothing)? Any other related commets are also welcome. Thanks Amit I've run into the same question and decided to keep a web page memo about it: http://www.freehackers.org/Packaging_a_python_program I'll be happy to update it with feedback. Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Using QSystemTrayIcon with PyQt
On Apr 1, 6:00 am, Alex Teiche [EMAIL PROTECTED] wrote: On Mar 31, 7:53 pm, Benjamin [EMAIL PROTECTED] wrote: On Mar 31, 8:41 pm, Alex Teiche [EMAIL PROTECTED] wrote: On Mar 31, 6:40 pm, Alex Teiche [EMAIL PROTECTED] wrote: On Mar 31, 11:49 am, Alex Teiche [EMAIL PROTECTED] wrote: On Mar 30, 3:50 pm, Benjamin [EMAIL PROTECTED] wrote: On Mar 29, 11:02 pm, Alex Teiche [EMAIL PROTECTED] wrote: Hello, I am pretty new to Python, and have never learned C++. I am trying to implement the following thing into my python application: http://doc.trolltech.com/4.3/qsystemtrayicon.html Through PyQt. I have been using PyQt for awhile and I know how do use it, but I could not get this specific thing to work. Can someone give me some hints as to get it working in Python? What problems are you having? Thanks a ton, Alex Thanks everyone for your help. I found the example to be particularly helpful, and I have made a simplified version just to display an icon with a quit button in its menu. Once I know how to do that I will incorporate it into my larger program, with more options and the ability show messages. The problem is, it doesn't work, and I can't find out what's wrong. Can you give me some hints? Here is the code: import sys from PyQt4 import QtGui, QtCore class trayIcon(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) #Create Actions for the Tray Menu# self.quitAction = QtGui.QAction(self.tr(Quit), self) QtCore.QObject.connect(self.quitAction, QtCore.SIGNAL(triggered()), QtGui.qApp, QtCore.SLOT(quit())) create_tray_icon() self.composeAction.setEnabled(visible) QtGui.QWidget.setVisible(self, visible) self.trayIcon.show() def create_tray_icon(self): self.trayIconMenu = QtGui.QMenu(self) self.trayIconMenu.addAction(self.composeAction) self.trayIcon = QtGui.QSystemTrayIcon(self) self.trayIcon.setContextMenu(self.trayIconMenu) self.trayIcon.setIcon(bad.svg) app = QtGui.QApplication(sys.argv) sys.exit(app.exec_()) OK, I messed around with it some more, and it works. I just don't know how to set an icon, and the example doesn't help at all. Here is the code: import sys from PyQt4 import QtCore, QtGui class Systray(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.createActions() self.createTrayIcon() #QtCore.QObject.connect(self.trayIcon, QtCore.SIGNAL(messageClicked()), self.messageClicked) #QtCore.QObject.connect(self.trayIcon, QtCore.SIGNAL(activated(QSystemTrayIcon::ActivationReason)), self.iconActivated) self.trayIcon.show() def createActions(self): #self.minimizeAction = QtGui.QAction(self.tr(Minimize), self) #QtCore.QObject.connect(self.minimizeAction, # QtCore.SIGNAL(triggered()), self, QtCore.SLOT(hide())) #self.maximizeAction = QtGui.QAction(self.tr(Maximize), self) #QtCore.QObject.connect(self.maximizeAction, # QtCore.SIGNAL(triggered()), self, # QtCore.SLOT(showMaximized())) #self.restoreAction = QtGui.QAction(self.tr(Restore), self) #QtCore.QObject.connect(self.restoreAction, # QtCore.SIGNAL(triggered()), self, # QtCore.SLOT(showNormal())) self.quitAction = QtGui.QAction(self.tr(Quit), self) QtCore.QObject.connect(self.quitAction, QtCore.SIGNAL(triggered()), QtGui.qApp, QtCore.SLOT(quit())) def createTrayIcon(self): self.trayIconMenu = QtGui.QMenu(self) #self.trayIconMenu.addAction(self.minimizeAction) #self.trayIconMenu.addAction(self.maximizeAction) #self.trayIconMenu.addAction(self.restoreAction) #self.trayIconMenu.addSeparator() self.trayIconMenu.addAction(self.quitAction) self.trayIcon = QtGui.QSystemTrayIcon(self) self.trayIcon.setContextMenu(self.trayIconMenu) app = QtGui.QApplication(sys.argv) x = Systray() sys.exit(app.exec_()) How would I go about setting the icon? Sorry, here is the code with commented out lines removed: import sys from PyQt4 import QtCore, QtGui class Systray(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.createActions() self.createTrayIcon() self.trayIcon.show() def createActions(self): self.quitAction = QtGui.QAction(self.tr(Quit), self)
Re: Is there a way to link a python program from several files?
On Feb 16, 7:53 pm, [EMAIL PROTECTED] (Edward A. Falk) wrote: IOW, is there a linker for python? I've written a program comprised of about five .py files. I'd like to find a way to combine them into a single executable. I wrote a small wiki page to sum-up my findings about such typical problem: http://www.freehackers.org/Packaging_a_python_program -- http://mail.python.org/mailman/listinfo/python-list
Re: Static linking of python and pyqt
On Dec 19, 1:26 pm, Markus Dahlbokum [EMAIL PROTECTED] wrote: I just want the qt libs linked to the interpreter without accessing them by a module. I tried the configure option '--with-libs='lib ...''. The make did fine but the executable is too small and the qt symbols are not known by it. How can I just link qt statically? Why do you want to do this? If qt isn't actually *used* in Python (as you don't include the pyqt modules), what effect do you expect from such linking? I think it linked just fine - it just didn't include any symbols, because none were needed. That is the correct, expected behavior. It all worked fine. Regards, Martin I need an environment that can be delivered to our customers without installing python, qt and pyqt. We want to provide the complete package. In order to do so I need to link at least python and qt. How can this be done? Of course a complete package with python, qt and pyqt would be the best solution but there seem to be even more complications that way. If you can help me with this I would be very grateful. If it's for windows, py2exe works like a charm for this kind of setup. For windows + linux, you might one to try one of: http://www.freehackers.org/Packaging_a_python_program -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to protect my new commercial software.
On Dec 10, 8:15 am, farsheed [EMAIL PROTECTED] wrote: I wrote a software and I want to protect it so can not be cracked easily. I wrote it in python and compile it using py2exe. what is the best way in your opinion? I used SoftwarePassport ( http://www.siliconrealms.com/ ) for exactly this. I have found it to be very complete, with many possible scheme: trial period, multiple licence schemes, lock on hardware, moveable installation, ... Although it will not stop a highly dedicated hacker, it will raise the barrier very high for breaking the protected software. A few of the memory protection were incompatible with py2exe, so you need to carefully test your program. But for me, it was a breeze to setup and use. -- http://mail.python.org/mailman/listinfo/python-list
Re: Code Management
On Dec 2, 4:27 pm, BlueBird [EMAIL PROTECTED] wrote: On Nov 26, 5:07 pm, Sergio Correia [EMAIL PROTECTED] wrote: Bluebird: If you are using python 2.5, relative imports are no longer an issue:http://docs.python.org/whatsnew/pep-328.html It does not solve my problem, or I missed something: Any idea what could be wrong in my code (in the previous message). Or did I misunderstand relative import seriously ? Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Python surpasses Perl in TIOBE index
On Dec 4, 4:08 pm, [EMAIL PROTECTED] wrote: This is *not* an attempt to start yet another Python-versus- AnyOtherProgrammingLanguage flame war, but I thought people might be interested in this: http://www.tiobe.com/tpci.htm Marc I find Ohloh comparisons also useful: http://www.ohloh.net/languages/compare?commit=Updatel0=pythonl0_0=-1l1=rubyl2=perlmeasure=commits What it highlights is that the number of python programmer is growing quicker than the number of perl programmers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Code Management
On Nov 26, 5:07 pm, Sergio Correia [EMAIL PROTECTED] wrote: Bluebird: If you are using python 2.5, relative imports are no longer an issue:http://docs.python.org/whatsnew/pep-328.html It does not solve my problem, or I missed something: [EMAIL PROTECTED] /cygdrive/d/work/work/vy-dev/foo $ find . -name '*.py' ./bar/bar.py ./bar/tests/test_bar.py ./bar/tests/test_bar1.py ./bar/tests/__init__.py ./bar/__init__.py ./foo/foo.py ./foo/tests/__init__.py ./foo/__init__.py ./__init__.py d:\work\work\vy-dev\fooC:\Python25\python.exe bar/tests/test_bar.py d:\work\work\vy-dev\foo ['d:\\work\\work\\vy-dev\\foo\\bar\\tests', 'C:\\Python25\\lib\\site- packages\\h gsvn-0.1.4-py2.5.egg', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\ \Python25\\DLL s', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\ \lib\\lib- tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-packages', 'C:\\Python25\ \lib\\sit e-packages\\win32', 'C:\\Python25\\lib\\site-packages\\win32\\lib', 'C: \\Python2 5\\lib\\site-packages\\Pythonwin', 'C:\\Python25\\lib\\site-packages\ \wx-2.8-msw -ansi'] Traceback (most recent call last): File bar/tests/test_bar.py, line 8, in module from ..bar import bar_f ValueError: Attempted relative import in non-package -- http://mail.python.org/mailman/listinfo/python-list
Re: Code Management
On Nov 21, 7:05 am, Sergio Correia [EMAIL PROTECTED] wrote: As a side note, I find much easier to drop a PTH file than messing with pythonpath. If you are not familiar with PTH files, what I do is this 1) Go to C:\Program Files\Python25\Lib\site-packages or whatever is appropiate in your case. 2) Create a text file, name it something like MyProjects.PTH (note the extension!) 3) in the file, just write the path of the folder that contains all your projects (in my case, C:/docs/python) The idea is to keep the main python installation separated from the modules you are currently developing. Your python installation goes to program files/python or bin/python, and your personal projects go somewhere else (usually inside your 'user' folder). This smooths many things, like working with different versions of a package you are developing. Hi, If I understand you correctly, you have the following directory organisation [Python installation]/site-packages/[MyProject.pth pointing to /home/ user/python-dev/] And then you do your development in python-dev. But how do you manage multiple development branches of the same program ? My directory structure looks like this: python-dev: + prog-branch1/ | + foo | | + foo.py | | + tests | |+ test_foo.py | + bar |+ bar.py |+ tests | + test_bar.py + prog-branch2/ + foo | + foo.py | + tests |+ test_foo.py + bar + bar.py + tests + test_bar.py bar/bar.py needs to import symbols from foo/foo.py . And bar/tests/ test_bar.py needs some symbols from both bar/bar.py and foo/foo.py I don't understand how having python-dev in the .pth file solves the problem. In my case, I make all my imports relative to the root of my project: bar/bar.py: from foo.foo import some_foo bar/tests/test_bar.py from foo.foo import some_foo from foo.bar import some_bar The way I managed to make it work is by extending sys.path but I would be happy to find a better solution: bar/bar.py is actually: import os, sys sys.path.append( '..') from foo.foo import some_foo and bar/tests/test_bar.py is actually: import os, sys sys.path.append( os.path.join('..','..') ) from foo.foo import some_foo from foo.foo import some_bar What is not nice with this method is that every runnable test script must extend unconditionally the sys.path . That creates some clutter. Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Python too complex ?!?!?!
On Nov 20, 9:36 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: FWIW it's trivial to run pyflakes on your code (automatically behind the scenes) to get syntax checking; in vim, my syntax errors get underlined immediately for python code. Can you describe your setup a bit more precisely ? I'm interested in this kind of development help. I had a quick look at pyflakes but I haven't found any signs of vim integration. I also get function prototypes on the status line I'm interested in that as well ! regards, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt with embedded python in Qt App
On Nov 2, 8:03 am, Bart. [EMAIL PROTECTED] wrote: Friday 02 of November 2007 01:06:58 Diez B. Roggisch napisa (a): So how to pass this object into embeded python interpreter (executed script)? Anyone know any example? You don't pass it, you _retrieve_ it in the embedded interpreter by invoking the code given to you. Know any example, please? For better understand this :) I wan't add scripting to one application wrotten with Qt. So, you have Qt/C++ application which you want to script through python. But why do you need PyQt for ? If you design a script api in python and bind it using whatever binding technology (manually, boost, sip, pyrex, ...), you should not need to use PyQt. Or do you mean to use PyQt as the binding technology ? Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: building a linux executable
Hi, Some time ago, I compiled a small list of tools to perform the some python executable bundling tasks. It might be useful for you. Here is the list: http://www.freehackers.org/Packaging_a_python_program Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to tell if a script has been run by Pythonw.exe instead of Python.exe?
On Oct 18, 11:56 pm, Metalone [EMAIL PROTECTED] wrote: In particular I want to know how to tell if reading and writing to the console can occur. Something like sys.isConsolePresent() For a different problem, I have the following code. It might help: def isrealfile(file): Test if file is on the os filesystem. This is necessary on windows, when starting python with pythonw.exe because in that case, the stdout and stderr are not real file and will create IOError when being flushed or when more than 4096 bytes are written. if not hasattr(file, 'fileno'): return False try: tmp = os.dup(file.fileno()) except: return False else: os.close(tmp); return True class NullStream: A file like class that writes nothing def close(self): pass def flush(self): pass def write(self, str): pass def writelines(self, sequence): pass if not isrealfile(sys.stdout): sys.stdout = NullStream() if not isrealfile(sys.stderr): sys.stderr = NullStream() -- http://mail.python.org/mailman/listinfo/python-list
Re: EasyMock for python ?
On Oct 11, 4:26 pm, Simon Brunning [EMAIL PROTECTED] wrote: On 10/10/07, BlueBird [EMAIL PROTECTED] wrote: Does anybody know where to find a library like EasyMock for python ? I searched quickly but could not find anything. I found python-mocks on sourceforge but form quickly reading the docs, it is not an EasyMock style mock. Actually, according to http://martinfowler.com/articles/mocksArentStubs.htmlI don't think it is even a mock library. More a stub. python-mock is more jMock than EasyMock in style, it's true, and the fact that you define expectations *after* the test invocation rather than before does feel a bit odd. But it does indeed check against the defined expectations, so that makes it a mock library in my book. A record-playback EasyMock style mock library would be nice, it's true... It should not be that hard to do, given that python-mocks already has the notion of recording and expectation verifiation. I may give it a stab. Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross-platform GUI development
On Oct 12, 12:30 pm, Nick Craig-Wood [EMAIL PROTECTED] wrote: My question is if Tix is old hat, what is the GUI toolkit I *should* be using for quick-n-dirty cross platform GUI development? I guess this is tangentially related to: http://groups.google.com/group/comp.lang.python/browse_thread/thread/... Personnaly, I use PyQt simply because I prefere Qt to Gtk, witch is much more integrated with all desktop than Gtk. In fact, your application in Qt on Mac, Win or Linux look like a native app. From my point of view, PyQt is very good. Qt is very actively developed and maintained, and the PyQt binding is of very good quality, and fully documented. I have used personally for several cross-platform projects and it worked like a charm. I like Qt's approach and extensive documentation. I've found that it works both for complex GUI as for quick'n dirty. There is usually a widget to do just what I need so that I can focus on my application logic instead of on the GUI code. In short, usage of Qt has driven me to love it. When looking at the other guis, I always find that the documentation is under my expectations, or that that things are quite complex to set- up to get what you need. On Oct 12, 12:30 pm, Nick Craig-Wood [EMAIL PROTECTED] wrote: I'd recommend wxPython over those becase 1) native look and feel on all platforms You get it with PyQt as well. 2) doesn't require expensive licensing for non-commercial apps (QT) You mean doesn't require expensive licensing for close source apps. Open source apps are free of charge. For professional developments, I bought the Qt license several times in the past because it was worth the time saved in my opinion. 3) Isn't a pain to install on windows (GTK) You get it with Qt as well. I was able to use it even as a windows newbie. -- http://mail.python.org/mailman/listinfo/python-list
EasyMock for python ?
Hi, Does anybody know where to find a library like EasyMock for python ? I searched quickly but could not find anything. I found python-mocks on sourceforge but form quickly reading the docs, it is not an EasyMock style mock. Actually, according to http://martinfowler.com/articles/mocksArentStubs.html I don't think it is even a mock library. More a stub. Philippe -- http://mail.python.org/mailman/listinfo/python-list
[issue1207] Load tests from path (patch included)
New submission from Bluebird: Something very nice about unittest is that it can find automatically the TestCase that you declare, and the test methods of every test case. This makes the operation of adding or removing tests very simple. For test modules however, there is nothing to automatically load all the modules of a given directory. I think that would be very helpful. Here is my proposal, to add to the set of TestLoader methods: def loadTestsFromPath( path='', filePattern='test*.py' ): '''Load all the TestCase in all the module of the given path. path: directory containing test files filePattern: glob pattern to find test modules inside path. Default is test*.py The path will be converted into an import statement so anything that can not be imported will not work. The path must be relative to the current directory, and can not include '.' and '..' directories. To simply load all the test files of the current directories, pass an empty path (the default). Return a test suite containing all the tests. ''' if len(path) == 0: pathPattern = filePattern else: pathPattern = path + '/' + filePattern pathPattern = os.path.normpath( pathPattern ) fileList = glob.glob( pathPattern ) mainSuite = TestSuite() for f in fileList: importName = f[:-3] importName = importName.replace( '\\', '.' ) importName = importName.replace( '/', '.' ) suite = defaultTestLoader.loadTestsFromName(importName) mainSuite._tests.extend( suite._tests ) return mainSuite === I use it like this: on my project, I have the following directory organisation: vy + run_all_tests.py + tests - run_tests.py - test_xxx.py - test_yyy.py + libvy + tests - run_tests.py - test_xxx.py - test_yyy.py + qvy + tests - run_tests.py - test_xxx.py - test_yyy.py I can do either: - cd libvy/tests python run_tests.py - cd qvy/tests python run_tests.py - cd tests python run_tests.py - run_all_tests.py Each time I add a new test module, it is automatically picked up by the test runners thank to the loadFromPath() feature. It makes it easy to maintain the global test suite that runs all the tests. That's the most important one because that test suite is responsible for non regression. run_tests.py: = if __name__ == '__main__': mainSuite = TestSuite() mainSuite._tests.extend( loadTestsFromPath('.')._tests ) ttr = TextTestRunner(verbosity=2) ttr.run( mainSuite ) run_all_tests.py: = if __name__ == '__main__': mainSuite = TestSuite() mainSuite._tests.extend( loadTestsFromPath( 'libvy/tests' )._tests ) mainSuite._tests.extend( loadTestsFromPath( 'qvy/tests' )._tests ) mainSuite._tests.extend( loadTestsFromPath( 'tests' )._tests ) ttr = TextTestRunner(verbosity=2) ttr.run( mainSuite ) -- components: Tests messages: 56148 nosy: bluebird severity: normal status: open title: Load tests from path (patch included) type: rfe versions: Python 2.5 __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1207 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: QPicture and Qpainter PyQt4
Hi, It looks like you have several things wrong: On Sep 17, 9:29 am, luca72 [EMAIL PROTECTED] wrote: class Form(QWidget, Ui_Form): [...] @pyqtSignature() def on_pushButton_clicked(self): Slot documentation goes here. # TODO: not implemented yet #raise Not implemented yet #gr = QtGui.QPainter() picture = QtGui.QPicture() gr = QtGui.QPainter() gr.begin(picture) gr.setPen(QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine)) gr.drawLine(70,100,150,100) gr.end() picture.save('dis.pic') self.frame.update() Normally, you don't paint inside a slot. You paint inside the paintEvent() method which is called automatically by Qt when an area of your widget needs to be repainted. from PyQt4.QtGui import QWidget from PyQt4.QtCore import pyqtSignature from PyQt4 import * class PictureFrame(QtGui.QFrame): def __init__(self, parent = None): QFrame.__init__(self, parent) picture = QtGui.QPicture() def paintEvent(self, event): picture.load('dis.pic') gr = QtGui.QPainter() gr.begin(self.frame) gr.drawPicture(0, 0, picture) gr.end() Don't load a picture inside a paintevent. Loading is an expensive process, you don't want to repeat it all the time. Second, you should check that your picture was loaded. Sometimes, it's a file problem. Check the size of your picture for example. Third, I think you should have : gr.begin( self ) Else, the painter is not painting on your widget. Hope that helps. PHilippe -- http://mail.python.org/mailman/listinfo/python-list
Reading text files where last line has no EOL
I tried and failed to read text files where the last line does not contain proper EOL. For my tests, I use a file that I create with the equivalent of : open('toto', 'w').write( '1234\n4567\n89AB' ) My reading code looks like this : l = f.readline() while len(l): self.appendLine( l ) l = f.readline() The last line is not returned (89AB) is never returned. I tried with for l in f with similar results. I read the doc : In order to make a for loop the most efficient way of looping over the lines of a file (a very common operation), the next() method uses a hidden read-ahead buffer. As a consequence of using a read-ahead buffer, combining next() with other file methods (like readline()) does not work right. However, using seek() to reposition the file to an absolute position will flush the read-ahead buffer. New in version 2.3. I've tried to do a f.seek( f.tell() ) but that did not help. So how am I supposed to fetch that last line ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading text files where last line has no EOL
On 17 sep, 13:24, Steve Holden [EMAIL PROTECTED] wrote: BlueBird wrote: I tried and failed to read text files where the last line does not contain proper EOL. For my tests, I use a file that I create with the equivalent of : open('toto', 'w').write( '1234\n4567\n89AB' ) My reading code looks like this : l = f.readline() while len(l): self.appendLine( l ) l = f.readline() The last line is not returned (89AB) is never returned. I tried with for l in f with similar results. I read the doc : In order to make a for loop the most efficient way of looping over the lines of a file (a very common operation), the next() method uses a hidden read-ahead buffer. As a consequence of using a read-ahead buffer, combining next() with other file methods (like readline()) does not work right. However, using seek() to reposition the file to an absolute position will flush the read-ahead buffer. New in version 2.3. I've tried to do a f.seek( f.tell() ) but that did not help. So how am I supposed to fetch that last line ? What version of Python are you using, and on what platform? WJFFM on 2.5.1/Cygwin: open('toto', 'w').write( '1234\n4567\n89AB' ) for l in open('toto'): ... print l ... 1234 4567 89AB You will observe that the last line is presented, but correctly does not include a trailing line feed. Oooops. It was a stupid bug in my script: textLine[:- int(textLine[-1]=='\n')] is not what I want (the real code was not a one-liner)! The documentation made me think that something wrong was going on with python but I should have known better. Thanks. -- http://mail.python.org/mailman/listinfo/python-list