wxpython-OGL fails to render objects with Python-3
I have a substantial wxpython-based application that I'm trying to port from python-2 to -3. Almost everything is working properly, except for a few small but important sections that use the OGL library. That executes without any exceptions, but the objects created within the diagram/canvas/panel are invisible! {sometimes they are visible for a small fraction of a second}. This occurs on Windows-10 and on Linux(Debian) systems. The colored background and buttons render just fine, the buttons do what they should, but no objects appear on the background (again, only with Py3, Py2 works properly). I have cut the code to a pretty minimum set and will attempt to paste it to the bottom of this message in the hope that it will encourage one of you to see what the problem might be. Alternatively if anyone knows of an example that works with Python-3 I'd be delighted to learn of it. Thanks for any insights!! # - # togl.py test 'OGL' shape system. from __future__ import print_function import sys if 2 == sys.version_info.major : import wxversion import wx import random import wx.lib.ogl as ogllib NOMSIZE=80 WINSIZE=400 N_ITEMS=7 shapeTypes= ( 'rect', 'circle', 'rndRect' ) class ShapeGraphicWindow(ogllib.ShapeCanvas): def __init__(self, parent): ogllib.ShapeCanvas.__init__(self, parent) self.diagram= ogllib.Diagram() self.SetDiagram(self.diagram) self.diagram.SetCanvas(self) self.SetBackgroundColour(wx.BLUE) def addShape(self, shape_type, title) : if 'rect' == shape_type : # rectangle shape= ogllib.RectangleShape(50, 35) brush= wx.Brush(wx.TheColourDatabase.Find("RED"), wx.SOLID) elif 'circle' == shape_type : # circle shape= ogllib.CircleShape(65) brush= wx.Brush(wx.TheColourDatabase.Find("YELLOW"), wx.SOLID) elif 'rndRect' == shape_type : # rounded-rectangle shape= ogllib.RectangleShape(45, 30) shape.SetCornerRadius(-0.3) brush= wx.Brush(wx.TheColourDatabase.Find("GOLDENROD"), wx.SOLID) else : raise AssertionError("Unable to add shape: %s : %s",(shape_type,title)) shape.SetBrush( brush ) x= int(random.uniform(NOMSIZE,WINSIZE-NOMSIZE)) shape.SetX(x) y= int(random.uniform(NOMSIZE,WINSIZE-NOMSIZE)) shape.SetY(y) shape.AddText(title) print("Draw",title,"at location ", (x,y), "on canvas of size", self.GetSize()) shape.SetCanvas(self) self.AddShape(shape) self.Refresh() shape.Show(True) return class TestPanel(wx.Panel): def __init__(self, frame) : wx.Panel.__init__(self, parent=frame) self.objcnts= (0,N_ITEMS) sz= wx.BoxSizer(wx.VERTICAL) hsz= wx.BoxSizer(wx.HORIZONTAL) btnq= wx.Button(self, -1, "Quit") btnq.Bind(wx.EVT_BUTTON, self.Quit) hsz.Add(btnq, 0, wx.ALL, 3) btnq= wx.Button(self, -1, "AutoTest") btnq.Bind(wx.EVT_BUTTON, self.AutoTest) hsz.Add(btnq, 0, wx.ALL, 3) sz.Add(hsz, 0, wx.ALIGN_LEFT) self.shp_graph_win= ShapeGraphicWindow(self) sz.Add(self.shp_graph_win, 2, wx.EXPAND) self.SetSizer(sz) #self.Layout() #self.Fit() self.SetAutoLayout(True) def mkTitle(self, index) : return ''.join([ chr(index + ord('A')), ":", str(index) ]) def AutoTest(self, event=None) : for j in range(*(self.objcnts)) : self.shp_graph_win.addShape(shapeTypes[j % len(shapeTypes)], self.mkTitle(j)) self.objcnts= (self.objcnts[1], self.objcnts[1]+N_ITEMS) def Quit(self, event) : self.Destroy() sys.exit(0) class TestFrame(wx.Frame): def __init__(self) : wx.Frame.__init__(self, None, -1, "test basic OGL functionality", size= wx.Size(WINSIZE,WINSIZE) ) TestPanel(self) self.Show(True) app = wx.App(False) frame = TestFrame() ogllib.OGLInitialize() app.MainLoop() sys.exit(0) -- https://mail.python.org/mailman/listinfo/python-list
Re: python3.7 installation failing - so why?
On Sat, 23 Feb 2019 14:56:03 +1100, Chris Angelico wrote: > On Sat, Feb 23, 2019 at 2:51 PM Frank Miles > wrote: >> >> I have a Debian/Linux machine that I just upgraded to the newer >> "testing" >> distribution. I'd done that earlier to another machine and all went >> well. With the latest machine, python2 is OK but python3 can barely >> run at all. For example: >> >> $ python3 Python 3.7.2+ (default, Feb 2 2019, 14:31:48) >> [GCC 8.2.0] on linux Type "help", "copyright", "credits" or "license" >> for more information. >> >>> help() >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/lib/python3.7/_sitebuiltins.py", line 102, in __call__ >> import pydoc >> File "/usr/lib/python3.7/pydoc.py", line 66, in >> import inspect >> File "/usr/lib/python3.7/inspect.py", line 40, in >> import linecache >> File "/usr/lib/python3.7/linecache.py", line 11, in >> import tokenize >> File "/usr/lib/python3.7/tokenize.py", line 33, in >> import re >> File "/usr/lib/python3.7/re.py", line 143, in >> class RegexFlag(enum.IntFlag): >> AttributeError: module 'enum' has no attribute 'IntFlag' >> >>> >> >>> >> Question: how can I determine what has gone wrong? > > Hmm. I'd start with: > > $ which python3 $ dpkg -S `which python3` > > and from inside Python: >>>> import sys; sys.path import enum; enum.__file__ > > My best guess at the moment is that your "enum" package is actually a > compatibility shim for earlier Python versions, less functional than the > one provided by Python 3.7. You may need to *uninstall* a shim package. > But I could well be wrong, and maybe there'd be a clue in your paths. > > ChrisA Whoopee! You nailed it! The path included /usr/local/lib/python3.7/dist-packages, which included an enum file as you suggested. The 'import enum; enum.__file__' (gonna have to look up that syntax) provided with the path to that directory. Many thanks Chris for a most helpful suggestion! -Frank -- https://mail.python.org/mailman/listinfo/python-list
python3.7 installation failing - so why?
I have a Debian/Linux machine that I just upgraded to the newer "testing" distribution. I'd done that earlier to another machine and all went well. With the latest machine, python2 is OK but python3 can barely run at all. For example: $ python3 Python 3.7.2+ (default, Feb 2 2019, 14:31:48) [GCC 8.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> help() Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.7/_sitebuiltins.py", line 102, in __call__ import pydoc File "/usr/lib/python3.7/pydoc.py", line 66, in import inspect File "/usr/lib/python3.7/inspect.py", line 40, in import linecache File "/usr/lib/python3.7/linecache.py", line 11, in import tokenize File "/usr/lib/python3.7/tokenize.py", line 33, in import re File "/usr/lib/python3.7/re.py", line 143, in class RegexFlag(enum.IntFlag): AttributeError: module 'enum' has no attribute 'IntFlag' >>> Question: how can I determine what has gone wrong? Reinstalling most of the packages hasn't done any good. I did a similar upgrade to another machine -- and it doesn't have this problem. Running md5sum on the above modules as well as /usr/bin/python3.7 generates the same numbers (comparing working and nonfunctional machines). Any clues/hints/ideas would be appreciated. There's a whole lot broken on this machine with python3 inoperable :( -F -- https://mail.python.org/mailman/listinfo/python-list
Re: closing image automatically in for loop , python
On Wed, 12 Apr 2017 04:18:45 -0700, Masoud Afshari wrote: > filename ="Ex_resample" +'_sdf_'+ str(n)+'.dat' > with open(filename, 'rb') as f: #read binary file data = np.fromfile(f, > dtype='float64', count=nx*ny) #float64 for Double precision float numbers > Ex = np.reshape(data, [ny, nx], order='F') > #print Ex.max() Your use of the 'with open(...) as f :' should automatically close access to filename once beyond that section. In your posting, the commented-out sections and garbled spacing would prevent anything useful from happening. Does that accurately reflect the code you're trying to run? -F -- https://mail.python.org/mailman/listinfo/python-list
Re: Data exchange between python script and bash script
On Tue, 04 Apr 2017 08:01:42 -0700, venkatachalam.19 wrote: > Hello All, > > I am writing a python code for processing a data obtained from a sensor. The > data from sensor is obtained by executing a python script. The data obtained > should be further given to another python module where the received data is > used for adjusting the location of an object. > > For achieving this, there is a central bash script, which runs both the > python modules parallel. Something like: > > python a.py & > python b.py & What is going on that two python scripts are needed? Which one generates the data needed by the bash script? > I am trying to return the sensor data to the bash .sh file, therefore it can > be provided to the other script. This, based on the online tutorials looks > like: > > sensor_data=$(python execute_sensor_process.py) & Presumably is simply getting the exit status code from the python interpreter, not the data, right? What are you seeing? > and the sensor_data is assigned by printing the required data in the > corresponding python script. For example, the data is printed in > execute_sensor_process.py as follows: > > print >>sys.stderr,sens_data > > By printing the data onto sys.stderr and assigning a return variable in the > bash, I am expecting the data to be assigned. Assigned to what? Some return variable in bash? What?? Why not use stdout? Either pipe the data from python directly into a (possibly modified) bash script, or into a file which gets read by the bash script. > But this is not happening. The sensor data is a dictionary and I like to have > this data for further analysis. I am not getting the data returned from the > python script on to the bash variable. Bash doesn't have dictionaries like python. Why is bash needed? > Can someone help me to understand why the code is not working? I tried other > approaches of function call such as You haven't given us enough of the code to really answer. > sensor_data=$`python execute_sensor_process.py` & > > python execute_sensor_process.py tempfile.txt & > kinexon_data=`cat tempfile.txt` & > > But none of the approaches are working. > > Thank you, > Venkatachalam Srinivasan I wonder if you could completely eliminate the bash script - do it all in python. I've written quite a few bash scripts, but not so many since I started using python. Only exception is for low level functions on systems without a functioning python. -- https://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing queue in py2.7
On Tue, 28 Mar 2017 15:38:38 -0400, Terry Reedy wrote: > On 3/28/2017 2:51 PM, Frank Miles wrote: >> I tried running a bit of example code from the py2.7 docs >> (16.6.1.2. Exchanging objects between processes) >> only to have it fail. The code is simply: >> # >> from multiprocessing import Process, Queue >> >> def f(q): >> q.put([42, None, 'hello']) >> >> if __name__ == '__main__': >> q = Queue() >> p = Process(target=f, args=(q,)) >> p.start() >> print q.get()# prints "[42, None, 'hello']" >> p.join() >> # --- > > Cut and pasted, this runs as specified on 2.7.13 on Win 10 > >> But what happens is f() fails: >> >> Traceback (most recent call last): >> File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in >> _bootstrap >> self.run() >> File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run >> self._target(*self._args, **self._kwargs) >> File "x.py", line 4, in f >> q.put([42, None, "Hello"]) >> AttributeError: 'int' object has no attribute 'put' > > This says that the arg bound to q in f is an int rather than a Queue. > Are you sure that you posted the code that you ran? > >> This is on a Debian jessie host, though eventually it needs to >> run on a raspberry pi 3 {and uses other library code that needs >> py2.7}. >> >> Thanks in advance for those marvelous clues! Argghh! I missed one stupid typo. Somehow had a '1' instead of the 'q' in the Process(..) line. My bad. Sorry for the noise, and thanks!! -F -- https://mail.python.org/mailman/listinfo/python-list
Multiprocessing queue in py2.7
I tried running a bit of example code from the py2.7 docs (16.6.1.2. Exchanging objects between processes) only to have it fail. The code is simply: # from multiprocessing import Process, Queue def f(q): q.put([42, None, 'hello']) if __name__ == '__main__': q = Queue() p = Process(target=f, args=(q,)) p.start() print q.get()# prints "[42, None, 'hello']" p.join() # --- But what happens is f() fails: Traceback (most recent call last): File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap self.run() File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run self._target(*self._args, **self._kwargs) File "x.py", line 4, in f q.put([42, None, "Hello"]) AttributeError: 'int' object has no attribute 'put' This is on a Debian jessie host, though eventually it needs to run on a raspberry pi 3 {and uses other library code that needs py2.7}. Thanks in advance for those marvelous clues! -F -- https://mail.python.org/mailman/listinfo/python-list
Re: Does anyone here use wxGlade on Linux?
On Thu, 11 Feb 2016 14:29:04 +, cl wrote: > I am trying out wxGlade on Linux, version 0.7.1 of wxGlade on xubuntu > 15.10. > > I have already written something using wxPython directly so I have the > basics (of my Python skills and the environment) OK I think. > > I am having a lot of trouble getting beyond the first hurdle of > creating a trivial Python GUI with wxGlade. Some of the problem is no > doubt that I'm unfamiliar with the interface but I seem to repeatedly > get to a situation where the interface won't respond to mouse clicks > (though the main menu items still work, I can Exit OK for instance). > > Is wxPython still buggy or is it really just down to my lack of > familiarity with it? Sure, there are bugs in wxPython, but they are "minor". I haven't tried using wxGlade, but if it's anything like the glade I tried using long ago there are issues in getting the two working together. -- https://mail.python.org/mailman/listinfo/python-list
Re: Which GUI?
On Fri, 24 Jul 2015 19:31:36 +0100, Paulo da Silva wrote: [snip] Which technology is better? matplotlib? tkinter? wxwidgets? qt? Sadly - I don't think wxpython has been ported to python3 yet. -- https://mail.python.org/mailman/listinfo/python-list
Pythonic way to iterate through multidimensional space?
I need to evaluate a complicated function over a multidimensional space as part of an optimization problem. This is a somewhat general problem in which the number of dimensions and the function being evaluated can vary from problem to problem. I've got a working version (with loads of conditionals, and it only works to #dimensions = 10), but I'd like something simpler and clearer and less hard-coded. I've web-searched for some plausible method, but haven't found anything nice. Any recommendations where I should look, or what technique should be used? TIA! -- https://mail.python.org/mailman/listinfo/python-list
Re: Pythonic way to iterate through multidimensional space?
On Tue, 05 Aug 2014 20:06:05 +, Frank Miles wrote: I need to evaluate a complicated function over a multidimensional space as part of an optimization problem. This is a somewhat general problem in which the number of dimensions and the function being evaluated can vary from problem to problem. I've got a working version (with loads of conditionals, and it only works to #dimensions = 10), but I'd like something simpler and clearer and less hard-coded. I've web-searched for some plausible method, but haven't found anything nice. Any recommendations where I should look, or what technique should be used? TIA! A should have waited. The answer: itertools.product! very nice -- https://mail.python.org/mailman/listinfo/python-list
Re: wx (not responding)
On Tue, 14 Jan 2014 07:26:10 -0800, ngangsia akumbo wrote: When i run this code on my pc it actually runs but signals that the app is not responding. [snip most of the code]- def main(): ex = wx.App() Example(None) ex.Mainloop() if __name__ == __main__: main() When I tried to run it I got a AttributeError: 'App' object has no attribute 'Mainloop' Not sure whether your wx version might have a 'Mainloop'. -- https://mail.python.org/mailman/listinfo/python-list
Re: Experiences/guidance on teaching Python as a first programming language
On Thu, 12 Dec 2013 16:18:22 -0500, Larry Martell wrote: On Thu, Dec 12, 2013 at 11:51 AM, bob gailer bgai...@gmail.com wrote: On 12/11/2013 9:07 PM, Larry Martell wrote: Nope. Long before that I was working on computers that didn't boot when you powered them up, You had to manually key in a bootstrap program from the front panel switches. PDP8? RIM loader, BIN loader? Data General Nova 3 IIRC - wasn't that a machine that didn't even have 'subtract' - you had to complement and add (2 steps) ? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Front-end to GCC
On Tue, 22 Oct 2013 16:40:32 +, Steven D'Aprano wrote: On Tue, 22 Oct 2013 15:39:42 +, Grant Edwards wrote: No, I was thinking of an array. Arrays aren't automatically initialised in C. If they are static or global, then _yes_they_are_. They are zeroed. Not that I don't believe you, but do you have a reference for this? Because I keep finding references to uninitialised C arrays filled with garbage if you don't initialise them. Wait... hang on a second... /fires up the ol' trusty gcc [steve@ando c]$ cat array_init.c #includestdio.h int main() { int i; int arr[10]; for (i = 0; i 10; i++) { printf(arr[%d] = %d\n, i, arr[i]); } printf(\n); return 0; } [steve@ando c]$ gcc array_init.c [steve@ando c]$ ./a.out arr[0] = -1082002360 arr[1] = 134513317 arr[2] = 2527220 arr[3] = 2519564 arr[4] = -1082002312 arr[5] = 134513753 arr[6] = 1294213 arr[7] = -1082002164 arr[8] = -1082002312 arr[9] = 2527220 What am I missing here? What you're missing is that arr[] is an automatic variable. Put a static in front of it, or move it outside the function (to become global) and you'll see the difference. -- https://mail.python.org/mailman/listinfo/python-list
Re: PDF generator decision
On Tue, 14 May 2013 08:05:53 -0700, Christian Jurk wrote: Hi folks, This questions may be asked several times already, but the development of relevant software continues day-for-day. For some time now I've been using xhtml2pdf [1] to generate PDF documents from HTML templates (which are rendered through my Django-based web application. This have been working for some time now but I'm constantly adding new templates and they are not looking like I want it (sometimes bold text is bold, sometimes not, layout issues, etc). I'd like to use something else than xhtml2pdf. So far I'd like to ask which is the (probably) best way to create PDFs in Python (3)? It is important for me that I am able to specify not only background graphics, paragaphs, tables and so on but also to specify page headers/footers. The reason is that I have a bunch of documents to be generated (including Invoice templates, Quotes - stuff like that). Any advice is welcome. Thanks. [1] https://github.com/chrisglass/xhtml2pdf Reportlab works well in Python 2.x. Their _next_ version is supposed to work with Python3... {yes, not much help there} -- http://mail.python.org/mailman/listinfo/python-list
Re: Urgent:Serial Port Read/Write
On Thu, 09 May 2013 23:35:53 +0800, chandan kumar wrote: Hi all,I'm new to python and facing issue using serial in python.I'm facing the below error ser.write(port,command)NameError: global name 'ser' is not defined Please find the attached script and let me know whats wrong in my script and also how can i read data from serial port for the same script. [snip] if __name__ == __main__: CurrDir=os.getcwd() files = glob.glob('./*pyc') for f in files: os.remove(f) OpenPort(26,9600) SetRequest(ER_Address) #SysAPI.SetRequest('ER',ER_Address) print Test Scripts Execution complete What kind of 'port' is 26? Is that valid on your machine? My guess is that ser is NULL (because the open is failing, likely due to the port selection), leading to your subsequent problems. HTH.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange __import__() behavior
On Wed, 25 Apr 2012 23:03:36 +0200, Kiuhnm wrote: On 4/25/2012 22:05, Frank Miles wrote: I have an exceedingly simple function that does a named import. It works perfectly for one file r- and fails for the second x. If I reverse the order of being called, it is still x that fails, and r still succeeds. os.access() always reports that the file is readable (i.e. true) If I simply call up the python interpreter (python 2.6 - Debian stable) and manually import x - there is no problem - both work. Similarly typing the __import__(x) works when typed directly at the python prompt. Both 'x' and 'r' pass pychecker with no errors. The same error occurs with winpdb - the exception message says that the file could not be found. 'file' reports that both files are text files, and there aren't any strange file-access permissions/attributes. Here's the function that is failing: def named_import(fname, description) : import os pname= fname + '.py' print ENTRY FILE, pname, : acces=, os.access(pname, os.R_OK) try : X=__import__(fname) x= [ X.cmnds, X.variables ] except ImportError : print failed return x This is the first time I've needed to import a file whose name couldn't be specified in the script, so there's a chance that I've done something wrong, but it seems very weird that it works in the CL interpreter and not in my script. TIA for any hints or pointers to the relevant overlooked documentation! I can't reproduce your problem on my configuration. Anyway, you should note that if x.pyc and r.pyc are present, __import__ will try to import them and not the files x.py and r.py. Try deleting x.pyc and r.pyc. Kiuhnm You are fast in replying! I nuked my query (within a few minutes of posting) when I discovered the reason. Perhaps it persisted in some domain. I'd forgotten that the python script containing the described function was not the file itself, but a link to the script. When I executed the script (er, link to the script) - even with winpdb - apparently __import__ examined the directory where the actual file resided. In _that_ directory, only 'r' existed, no 'x'. So thanks for trying, there was no way you (or anyone) could have seen that the script was just a link to a script... -F -- http://mail.python.org/mailman/listinfo/python-list
Strange __import__() behavior
I have an exceedingly simple function that does a named import. It works perfectly for one file r- and fails for the second x. If I reverse the order of being called, it is still x that fails, and r still succeeds. os.access() always reports that the file is readable (i.e. true) If I simply call up the python interpreter (python 2.6 - Debian stable) and manually import x - there is no problem - both work. Similarly typing the __import__(x) works when typed directly at the python prompt. Both 'x' and 'r' pass pychecker with no errors. The same error occurs with winpdb - the exception message says that the file could not be found. 'file' reports that both files are text files, and there aren't any strange file-access permissions/attributes. Here's the function that is failing: def named_import(fname, description) : import os pname= fname + '.py' print ENTRY FILE, pname, : acces=, os.access(pname, os.R_OK) try : X=__import__(fname) x= [ X.cmnds, X.variables ] except ImportError : print failed return x This is the first time I've needed to import a file whose name couldn't be specified in the script, so there's a chance that I've done something wrong, but it seems very weird that it works in the CL interpreter and not in my script. TIA for any hints or pointers to the relevant overlooked documentation! -F -- http://mail.python.org/mailman/listinfo/python-list
Re: Python web frameworks
On Tue, 20 Nov 2007, joe jacob wrote: There are a lot of web frameworks for python like django, mod_python, spyce, turbo gears, Zope, Cherrypy etc. Which one is the best in terms of performance and ease of study. Personally I found zope/plone to be very much its own enormously complex world. Performance was quite sluggish on a less-than-state-of-the-art computer. Part of my problem was that my particular job didn't really fit with the particular viewpoint (way of handling data) implicit in these programs. This might not be the case for you - you'll have to evaluate that for yourself. In the end I went with Django (hosted by mod_python/apache). Django thankfully doesn't require that you use their admin as the access point for normal users, though that means it will take more time and thought. It's still comparatively flexible and straightforward in comparison to zope/plone. There are a few things that I am not 100% satisifed with, but overall I have found django to be very adaptible to my particular needs. All this despite the fact that this is a pretty minor part of my work - I am pretty much a newby at developing for the web. BTW the book - while still apparently not fully completed - is available for free on the 'net. -f -- http://mail.python.org/mailman/listinfo/python-list
Re: fastest postgresql module
In article [EMAIL PROTECTED], Timothy Smith [EMAIL PROTECTED] wrote: Leif B. Kristensen wrote: Timothy Smith skrev: has anyone got some hard numbers on which pg access module is the fastest, i currently use pypgsql, but i can't help but feel it's a little slow. 3 seconds to connect, send one query, get th return data. i'm on a adsl 1.5mbit/256kbit link, the server is on a 10/10mbit, and i have a ping of 245ms average. maybe pypgsql does too much backand forth, i don't know. You might want to try psycopg, it's claimed to be optimized for speed. my only issue with psycopg, is last time i looked they had no win32 port? psycopg is available for win32 (though the development version might not be) Try: http://www.stickpeople.com/projects/python/psycopg/ HTH... -frank -- -- http://mail.python.org/mailman/listinfo/python-list