Re: Python 2.7 released
I, too, have multiple versions installed -- newer ones for running code I haven't upgraded; older ones for compatibility testing where needed. I just install to the default c:\pythonxy directories (although I like the idea of a common root) and I put NTFS hardlinks into my general c:\tools directory which is on the path. The out-of-context hardlinks work because of the registry settings which pick up the correct context for each version. Sorry to be daft here, but what do you mean by a hardlink ? A windows Shortcut ? I have just installed 2.7 and want to start upgrading some code, but alas still want to maintain some 2.5 code too. -- http://mail.python.org/mailman/listinfo/python-list
Re: Moving from PHP to Python. Is it Possible
So My question is. For example I had this kind of python file and we want to use this as plugin template div class='foo' % for n in range(3): # This indent will persist % pThis paragraph will be repeated 3 times./p % # This line will cause the block to end % This line will only be shown once.br /div on execution time, I want to import this template file, execute as python script and store output in a GLOBAL dictionary for later usage. Is it possible ? Have you checked out one of the templating systems modules ? I have used Cheetah quite successfully, but there a numerous other options. http://www.cheetahtemplate.org/ I think you will find that a template system (like Cheetah) will give you the best results with the most maintainable structure. g. -- http://mail.python.org/mailman/listinfo/python-list
Inheritance and Design Question
I have an object the I would like to use as a base class. Some of the methods I would like to override completely, but others I would simply like to call the base class method and use the return value in the child method. The purpose here is to eliminate the duplication of valuable code in the parent, when I really just need the child to operate of a results of the parent. Consider the following two classes; class Parent(object): def process(self, value): retval = Parent.result('%s') % value return retval class Child(Parent): def __init__(self): Parent.__init__(self) def process(self, value): retval = Child.result('%s') % super(Child, self).process (value) return retval So foo = Child() print foo.process('the value') Child.result('Parent.result('the value')') IS there another pattern or idiom that would accomplish this? This seems a bit 'smelly' to me. Also seems almost the inverse of decorators, but I am not sure decorators would be appropriate in this case. Any help suggestions would be appreciated. g. -- http://mail.python.org/mailman/listinfo/python-list
Re: Killing threads
On Apr 4, 10:43 pm, ericwoodwo...@gmail.com wrote: Hi, I'm new to python and even newer to threading and it seems as though I'm missing something fundamental about threads. Basically I have a program that looks like this: class ThreadOne(threading.Thread): while 1: do stuff class ThreadTwo(threading.Thread): while 1: do other stuff first = ThreadOne() second = ThreadTwo() while 1: do stuff The issue that I'm having is...I don't know how to kill this app in window. I hit ctrl-c but that only seems to kill one of the threads. The rest of the app just lingers. There's got to be a more graceful way but so far I haven't googled anything up. I'm using queues to talk between these threads so I could certainly put some kind of message on the queue that causes the threads to commit suicide but I'm thinking there's a more built in way to do what I want. I'm just not sure what it is. I'd appreciate it if somebody could point me in the right direction. Thanks. I am not an expert either, however, I think the standard practice is to use and threading.Event to communicate with the threads. So the structure goes something like this; In the main thread set a threading.Event called 'keepgoing'. Pass this object into the thread at instantiation or as a parameter in the .start method Over-ride the .run method to handle the process Change the while loop's condition to check the .keepgoing.isSet() In the primary thread, when you want the threads to stop, simply .clear () the keepgoing event The while loop terminates and at the end of the .run method, the thread will terminate. In the primary program, you should then .join() the worker threads. - doing this will block the program until all of the thread have stopped. So your example would become; class ThreadOne(threading.Thread): def __init__(self, keepgoing): threading.Thread.__init__(self) self.keepgoing = keepgoing def run(self) while self.keepgoing.isSet(): do stuff thread one class ThreadTwo(threading.Thread): def __init__(self, keepgoing): threading.Thread.__init__(self) self.keepgoing = keepgoing def run(self) while self.keepgoing.isSet(): do stuff in thread two # #now start the main process # keepgoing = threading.Event() keepgoing.set() first = ThreadOne(keepgoing) second = ThreadTwo(keepgoing) # you could also pass in the variable with a thread.start() method, which will then call the thread.run() while 1: do stuff if stop_condition:#keyboard interrupt ? keepgoing.clear() for worker in threading.enumerate(): if worker.isAlive(): worker.join() FULL DISCLAIMER: I am NOT a threading expert and have limited experience, so if this doesn't work, you are on your own ! -- http://mail.python.org/mailman/listinfo/python-list
Re: Killing threads
For more info, see the slides from my thread tutorial:http://pythoncraft.com/OSCON2001/ -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Aahz, thanks for this reference and link to your presentation. At the risk of highjacking the OP's question, I am bit confused as to how using an Event would cause a deadlock. You presentation outlines Events, but doesn't elaborate on the specifics or usage. In threading.Event python 2.5 docs say; This is one of the simplest mechanisms for communication between threads: one thread signals an event and other threads wait for it. Again, I have limited experience, however, in my reading of the threading manual and review examples, Events were specifically design to be a thread safe way to communicate a 'state' to running threads ? In the OP's example 'do stuff' was open to wide interpretation, however, if within the thread's main 'while' loop the tread checks to see if the 'keepgoing' Event.isSet(), in what scenario would this create deadlock ? Thanks for your patience. I thought I had grasped the basics of using threads/threading, so hope I can learn more. g. -- http://mail.python.org/mailman/listinfo/python-list
Re: split problem if the delimiter is inside the text limiter
You have to know the original encoding (I mean, the one used for the csv file), else there's nothing you can do. Then it's just a matter of decoding (to unicode) then encoding (to utf8), ie (if your source is in latin1): utf_string = latin1_string.decode(latin1).encode(utf8) The OP mentioned using 'pgdb' which I assumed to mean he is using PostgeSQL and the PygreSQL DB. If that is the case, then PostgreSQL has an optional parameter call 'client_encoding'. If this is set in within postgres db or as part of the db transaction, then the db will accept the incoming data 'as is' and do the decoding internally saving this step and giving a bit of a performance boost as well as the client (python) application doesn't need to be concerned about it. As you so correctly point out Bruno, you do need to know the original encoding. My comments above just simplify the db update process. This part of the manual might be helpful http://www.postgresql.org/docs/8.1/static/multibyte.html If 'pgdb' != PostgreSQL then please accept my apologies for this intrusion in this thread. g. -- http://mail.python.org/mailman/listinfo/python-list
Re: Restructure dictionary (Python 2.5)
... this is a crappy solution that's underusing Python. Please enlighten me of a better way! - Fencer One thing that springs to mind is using the dict method .setdefault untested for dkey, vallist in old_dict.iteritems(): for val in vallist: new_dict.setdefault(val, set()).add(dkey) /untested -- http://mail.python.org/mailman/listinfo/python-list
Re: access to MS Access password-protected database?
On Feb 11, 10:43 am, Ken McDonald kmmcdon...@medicine.wisc.edu wrote: Can anyone direct me towards a code snippet showing how to use Python to insert data into a password-protected MS Access database? My google searches have been uninformative for dbs that are password-protected. Thanks, Ken You post is a little vague on specifics - do you actually have access to the db ? - can you open it with access ? - can you currently read records using python ? I am assuming you don't have access to the db through python, once you do the rest is straight forward. I use DSN-less connections. This link below is quite helpful http://www.carlprothman.net/Default.aspx?tabid=90#ODBCDriverForAccess If you aren't using the adodbapi (part of the pywin32 package), you need to do something like this, assuming you access db is MS-Access 2000 and above. untested import win32com cnx = win32com.client.Dispatch('ADODB.connection') parms = {} parms['driver'] = '{Microsoft Access Driver (*.mdb)}' parms['dbase'] = path_to_mdb parms['sys_mdw'] = path_to_workgroup_security parms['uid'] = userid_defined_in_mdw parhs['pwd'] = pwd_for_uid_in_mdw cnxtr = 'Driver=%(driver)s; DBQ=%(dbase)s; SYSTEMDB=%(sys_mdw)s; UID=% (uid)s; PWD=%(pwd)s; ' % parms cnx.ConnectionString = cnxstr cnx.Open() /untested once you have an ADO Connection, execute SQL directly on the connection like this cnx.Execute('INSERT INTO tablename (col1, col2) VALUES ('val1, val2);') Or alternatively you should create RecordSets and manipulate these. IF you need help understanding ADO I would recommend; http://www.w3schools.com/ado/default.asp The examples are translateable to Python. You create recordsets via; rs = win32com.client.Dispatch('ADO.RecordSet') If you don't have/weren't given the passwords to the DB, but you do have access to the workgroup file ('*.MDW') file that stores the uid/ pwds and permission, then there are several third party tools that will recover these for you. Google is your friend. If you don't have access to the original .mdw ... well, I can't help you and I don't think anyone can. Good luck. -- http://mail.python.org/mailman/listinfo/python-list
Re: kinterbasdb + firebird 1.5 with python 2.6 ?
On Feb 3, 2:32 pm, Laszlo Nagy gand...@shopzeus.com wrote: Does anyone know how to get firebird 1.5 driver (kinterbasdb) for FireBird 1.5? My problem: * python 2.6 already installed on a server * there is a firebird 1.5 database on the same server * I need to access it from python 2.6 Any thoughts? Have you asked on the Firebird list ? The original maintainer of kinterbasedb passed away and maintenance was taken over by the Firebird project. See this link. http://www.firebirdsql.org/index.php?op=develsub=python Sorry, but that is the best I can do. g. -- http://mail.python.org/mailman/listinfo/python-list
Re: DrPython and py2exe
But the irritating thing is that DOS window stays open until particular instance of DrPython isn't closed. This is a relatively simple fix I think. You can change the extension of the drPython.py to drpython.pyw and the python windows executable (pythonw.exe) will launch the program instead of the traditional executable (python.exe). Traceback (most recent call last): File drpython.py, line 46, in module File wxversion.pyc, line 152, in select wxversion.VersionError: Requested version of wxPython not found check out the wiki on 'multi version installs'. http://wiki.wxpython.org/MultiVersionInstalls drPython is probably selecting a specific version of wxpython and py2exe doesn't like it or can't find it. Once you solve that, py2exe will work fine with wxpython. -- http://mail.python.org/mailman/listinfo/python-list
Re: Ternary operator and tuple unpacking -- What am I missing ?
On Jan 13, 1:01 am, Miles semantic...@gmail.com wrote: On Tue, Jan 13, 2009 at 12:02 AM, imageguy imageguy1...@gmail.com wrote: Using py2.5.4 and entering the following lines in IDLE, I don't really understand why I get the result shown in line 8. Note the difference between lines 7 and 10 is that 'else' clause result enclosed in brackets, however, in line 2, both the 'c,d' variables are assign correctly without the brackets being required. 1) n = None 2) c,d = n if n is not None else 0,0 3) print c,d, type(c), type(d) 4) 0 0 type 'int' type 'int' The ternary expression has higher precedence than the comma, so the actual effect of line 2 (and 8) is: c, d = (n if n is not None else 0), 0 Or written more explicitly: c = n if n is not None else 0 d = 0 So the only correct way to write the expression, for the result you want, is to use your line 10: 10) c,d = n if n is not None else (0,0) But if you're struggling with the precedence issues, I'd recommend ditching ternary expressions altogether and using full conditional blocks. -Miles Thanks. Hadn't thought through the operator precedence and the affect of the comma. This was the first time I tried to use with tuples, so will be more careful next time or stick to control blocks. g. -- http://mail.python.org/mailman/listinfo/python-list
Ternary operator and tuple unpacking -- What am I missing ?
Using py2.5.4 and entering the following lines in IDLE, I don't really understand why I get the result shown in line 8. Note the difference between lines 7 and 10 is that 'else' clause result enclosed in brackets, however, in line 2, both the 'c,d' variables are assign correctly without the brackets being required. Any chance someone could enlighten me on the rules for tuple unpacking as this seems inconsistent. 1) n = None 2) c,d = n if n is not None else 0,0 3) print c,d, type(c), type(d) 4) 0 0 type 'int' type 'int' 5) n = 22,11 6) print n, type(n) (22, 11) type 'tuple' 7) c,d = n if n is not None else 0,0 8) print c,d 9) (22, 11) 0 10) c,d = n if n is not None else (0,0) 11) print c,d 12) 22 11 -- http://mail.python.org/mailman/listinfo/python-list
Re: Ternary operator and tuple unpacking -- What am I missing ?
understand why I get the result shown in line 8. 7) c,d = n if n is not None else 0,0 8) print c,d 9) (22, 11) 0 OOPS sorry that should be line 9. g. -- http://mail.python.org/mailman/listinfo/python-list
Re: Reverse order of bit in repeating seqence of byte string
On Jan 2, 7:33 pm, John Machin sjmac...@lexicon.net wrote: For some very strange definition of works. You say you have 'bgr' and want to convert it to 'rbg'. The following code converts 'bgr' to 'rgb', which is somewhat more plausible, but not what you said you wanted. Well that's embarrassing ... you are correct. I need to convert from 'bgr' to 'rgb' Thanks to all others for suggestions FWIW, I realized the the C.types string buffer is/was mutable so settled on this; for start in xrange(0, ctypes.sizeof(buffer), 3): if buffer[start] != buffer[start+2]: #only need to swap the bits if they are different. ie if both are white or black, no change is required. blue, red = buffer[start], buffer[start+2] buffer[start], buffer[start+2] = red, blue This was about 30-40% faster that converting to list, processing and then converting back again. Will try the array module too ... but I think I need to find a new graphic package rather that makes working with the bits easier. g. -- http://mail.python.org/mailman/listinfo/python-list
Reverse order of bit in repeating seqence of byte string
I am looking for the most efficient method of replacing a repeating sequence in a byte string returned from a imaging .dll, connected via I receive the byte string with the following sequence 'bgrbgrbgrbgr' and I would like to convert this to 'rbgrbgrbgrbg' FWIW, the string is created using ctypes.create_string_buffer function The following code works but feels a bit clunk and is rather slow too. blist = list(buffer) for start in xrange(0,len(blist), 3): try: blue = blist[start] red = blist[start+2] blist[start] = red blist[start+2] = blue except IndexError: pass new_buffer = ''.join(blist) new_buffer is then passed to a wx program to create and image. Any thoughts comments would be appreciated. geoff. PS: I started this post earlier, but I think I hit the send button too soon. My apologies to the group for sloppy typing. -- http://mail.python.org/mailman/listinfo/python-list
Re: something else instead of PIL?
On Dec 17, 3:48 pm, Reimar Bauer r.ba...@fz-juelich.de wrote: Hi what has happened to PIL? No updates since two years. Or does one know an alternative lib for resizing images? cheers Reimar I have found the FreeImage library with the Python bindings quite workable. I work with multi-page TIF images and this seemed to be the best option. The FreeImage library seems to be actively maintained too (Last release in July 08 with updates to many of the image processing plug- ins). The python bindings took me a bit to understand as they try to emulate PIL, however they are implemented using ctypes, so you can change/manage yourself if needed. I found working directly with the functions exported from the .dll the best option and gave the best performance. Freeimage site: http://freeimage.sourceforge.net/ Python bindings: http://freeimagepy.sourceforge.net/ Hope that helps. Good luck. Working with images/graphics can make my brain hurt sometimes. g. -- http://mail.python.org/mailman/listinfo/python-list
Re: dBase III files and Visual Foxpro 6 files
On Dec 8, 2:53 am, Ethan Furman [EMAIL PROTECTED] wrote: Greetings All! I nearly have support complete for dBase III dbf/dbt files -- just wrapping up support for dates. The null value has been a hindrance for awhile but I nearly have that solved as well. For any who know of a cool dbf module already in existence for dBase III and Visual Foxpro -- where were you six months ago when I was searching? ;) Seriously, though, this has been a great learning experience for me. As I said -- dbf/dbt files are 99% ready. idx files -- no support: for my purposes I just don't need them. I've found no problem in loading tables up to 300,000 records with 50 fields per record, and re-ordering them on the fly in memory. However, after putting much effort into this code, and wanting it to be useful to others in the community, are there others who work with dbf files that would need idx/cdx support? Or tables so large they won't fit comfortably into memory? ~ethan~ I occasionally need access to dbf files. In the past I have used the recipe found in the python cookbook on the activestate website. I do not need access to the idx/cdx as I have found that loading the records from the table into memory worked well for me too. If/When you release would enjoy having a peak. g. -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing a hidden/background program
On Nov 2, 6:32 am, [EMAIL PROTECTED] wrote: On Nov 2, 3:59 am, Mike Driscoll [EMAIL PROTECTED] wrote: You probably want to create a Windows service with Python. There are various ways to accomplish this. Was considering a Windows service too, however would like to avoid that as non-Admin users may not be able to do that. While I'm not familiar with threading, I'm considering starting a seperate thread and use a function such as os.pexec that hangs until the external daemon .exe exists. Check out the wx.lib.delayedresults option in the demo. Since wx.App needs to run as the main thread, you might be able to run your as the 'delayedresult'. As for the main frame of your app, simply Hide()/Show() when it needs to be visible. When the wx.App closes, the thread running the service will automatically shut down. Other than that ... I think it is a bit more complicated and will probably require asyncore and/or asynchat. g. -- http://mail.python.org/mailman/listinfo/python-list
Re: String to hexadecimal conversion
On Sep 8, 5:05 am, Praveena P [EMAIL PROTECTED] wrote: Hi folks, I am new to Python... so am not too sure about how the type conversion works. I have to read a file that contains hexadecimal data and use the data further to do some arithmetic calculations. A sample of the input is : 20E032F8400022005E The problem I am facing is this: I am using f.read(2) to read a byte at a time, but the data that is read is a string rather than a number. So it kind of hampers any arithmetic operations I perform on this data... Could you please suggest some method I could use for this? Thanks guys! Praveena check out the struct module in the standard python library. It's title says it all Interpreting strings as packed binary data. I used this extensively to reverse engineer a couple proprietary file structures. You can read large chucks of the file - perhaps a record ? - and then based on the format provided, convert it to a tuple. Good luck. g. -- http://mail.python.org/mailman/listinfo/python-list
Examples using msilib to build windows installers
I have been using InnoSetup to distribute my wxpython app and ir works great, howver, I would like to offer a *.msi installer to customers as an option and this isn't available using Innosetup. It would appear to me that the msilib library included with standard python 2.5 would allow be to do this. I found the source code that builds the python distrubition installer packages, but I was wondering if there were other examples that I can learn from. TIA. -- http://mail.python.org/mailman/listinfo/python-list
distutils setup - changing the location in site-packages
I am hoping if someone can set me straight. I have created a setup script for a module, however, when running the install on my own machine, I would like to place the module in a specific site-packages directory/package. So if I start with a module in .\dev\mygreatmodule.py I want to end up with; .\lib\site-packages\mytools\mygreatmodule.py. I have the setup script working, however, when I run the install, it places the module in the root of site-packages. The following is the deatils from the script setup ( name = mymodule, version = 0.1, description = My modules special description, author = me, author_email = [EMAIL PROTECTED], py_modules = [exceptionhandler] ) This is for development purposes. I would like to have a development copy of some tools, but when ready and tested publish them to the site-packages where they can be included in production code. Any guidance/suggestions would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Removal of element from list while traversing causes the next element to be skipped
On Jan 29, 12:34 pm, William McBrine [EMAIL PROTECTED] wrote: Look at this -- from Python 2.5.1: a = [1, 2, 3, 4, 5] for x in a: ... if x == 3: ... a.remove(x) ... print x ... 1 2 3 5 a [1, 2, 4, 5] Sure, the resulting list is correct. But 4 is never printed during the loop! What I was really trying to do was this: apps = [name for name in os.listdir(ROOT) if os.path.isdir(os.path.join(ROOT, name))] apptitles = {} for name in apps: try: app = __import__(name) except: apps.remove(name) else: apptitles[name] = getattr(app, 'TITLE', name.title()) which worked fine, until I actually had a directory with no module in it. Then that directory was correctly removed from the list, but the _next_ one was skipped, so its title was never assigned, which caused problems later in the program. -- 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on You should not change/modify the original sequence iterating over. In the list comprehension, try changing os.listdir(ROOT) to os.listdir(ROOT)[:] so you are get a copy of the original list. geoff. -- http://mail.python.org/mailman/listinfo/python-list
application version checking against database
We are trying to implement a system that checks the version of the application against a version number stored in the database. We don't want the app and the db don't become out of sync. We have tried setting a __version__ variable in the top most module, however, it seems that this is not accessible for the modules that are subsequently imported. There are a several locations in the app where we want to do the version check, but we would like to have one place to set the version number, namely the top level module. We have thought of creating a Version class and passing it around, but aren't really keen on that idea. Any suggestions/ideas would be helpful. NOTE: the app is developed in wxPython. g. -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe - change name of exe created
Sorry for the double post, sent it to quickly. I have a setup script like this; setup(windows = [{script:myprogram.py, icon_resources:[(0,nabbitt.ico)], other_resources: [(24,1,manifest)]} ], name = My Program ver 0.1, data_files = [(,rootdata)], zipfile = None, options = {py2exe: { compressed : 1, dll_excludes: [w9xpopen.exe], bundle_files: 3 } }, ) Note that every thing works fine with this and creates an exe program called myprogram.exe I would like to setup program to create an output called; MyBestProgram.exe IS that at all possible ? Geoff. -- http://mail.python.org/mailman/listinfo/python-list
py2exe - change name of exe created
I have a setup script like this; setup(windows = [{script:myprogram.py, icon_resources:[(0,nabbitt.ico)], other_resources: [(24,1,manifest)]} ], name = Nabbitt ver 0.1, data_files = [(,rootdata)], zipfile = None, options = {py2exe: { compressed : 1, dll_excludes: [w9xpopen.exe], #should also exclude MSVCR71.dll bundle_files: 3 # 1=Single .exe, 2=.exe with pythonXX.dll } }, ) -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe - change name of exe created
On Sep 7, 11:22 am, Thomas Heller [EMAIL PROTECTED] wrote: imageguy schrieb: Sorry for the double post, sent it to quickly. I have a setup script like this; setup(windows = [{script:myprogram.py, icon_resources:[(0,nabbitt.ico)], other_resources: [(24,1,manifest)]} ], name = My Program ver 0.1, data_files = [(,rootdata)], zipfile = None, options = {py2exe: { compressed : 1, dll_excludes: [w9xpopen.exe], bundle_files: 3 } }, ) Note that every thing works fine with this and creates an exe program called myprogram.exe I would like to setup program to create an output called; MyBestProgram.exe IS that at all possible ? Yes. Use a 'dest_base' key in the dictionary, like so: setup(windows = [{script:myprogram.py, icon_resources:[(0,nabbitt.ico)], dest_base: MyBestProgram, other_resources: [(24,1,manifest)]} ... 'dest_base' is the basename of the destination program that py2exe creates. Thomas- Hide quoted text - - Show quoted text - Thanks. I really appreciate the response. Where would I find that in the docs ? Thought I had searched everywhere. G. -- http://mail.python.org/mailman/listinfo/python-list
py2exe - change name of exe created
I have a setup script like this; setup(windows = [{script:myprogram.py, icon_resources:[(0,nabbitt.ico)], other_resources: [(24,1,manifest)]} ], name = Nabbitt ver 0.1, data_files = [(,rootdata)], zipfile = None, options = {py2exe: { compressed : 1, dll_excludes: [w9xpopen.exe], #should also exclude MSVCR71.dll bundle_files: 3 # 1=Single .exe, 2=.exe with pythonXX.dll } }, ) -- http://mail.python.org/mailman/listinfo/python-list
Re: Open HTML file in IE
On Jul 18, 3:20 am, gravey [EMAIL PROTECTED] wrote: Hello. Apologies if this is a basic question, but I want to open a HTML file from my local drive (is generated by another Python script) in Internet Explorer. I've had a look at the webbrowser module and this doesn't seem to be what I need. Any help much appreciated. check out the os module. os.startfile(your_htmlfile.html) should do it. -- http://mail.python.org/mailman/listinfo/python-list
Re: msbin to ieee
On May 6, 6:44 pm, revuesbio [EMAIL PROTECTED] wrote: Hi Does anyone have the python version of the conversion from msbin to ieee? Thank u Not sure if this helps, but I think this thread has the answer; http://groups.google.com/group/comp.lang.python/browse_thread/thread/286d9f6daff9bfab/ce76d5fcd887a47d?lnk=gstq=geskerrettrnum=2#ce76d5fcd887a47d Check out the response from Bengt Richter. His function did the right thing. -- http://mail.python.org/mailman/listinfo/python-list
Re: Rendering text question (context is MSWin UI Automation)
I am trying to use UI Automation to drive an MS Windows app (with pywinauto). I need to scrape the app's window contents and use some form of OCR to get at the texts (pywinauto can't get at them). As an alternative to integrating an OCR engine, and since I know the fonts and sizes used to write on the app's windows, I reasoned that I could base a simple text recognition module on the capability to drive MSWindows text rendering - eg to generate pixmaps of texts I expect to find in the driven app's windows, exact to the pixel. The advantage of that approach would be exactitude and self-containment. I've verified manually inside an Idle window, that indeed I could produce pixmaps of expected app texts, exact to the pixel (with Tkinter+screen capture at least). I could use help to turn this into a programmable capability, ie : A simple - with Tkinter or otherwise - way to wrap access to the MS Windows UI text rendering engine, as a function that would return a picture of rendered text, given a string, a font, a size and colors ? And ideally, without interfering with screen contents ? Thanks in advance for any guidance, Boris Borcic I was looking for ( and still am searching for) similiar functionality. Specifically I would like to be able to capture a small area of the screen (a number or a code) and convert this to text that can be used in my application. When I asked my question, I was directed to the Microsoft Accessibility tool kit. Serach on this list for the post titled; Reading text labels from a Win32 window I work with wxPython and Win32 applications exclusively. So if I can be of any help or assistance, please let me know. Geoff. -- http://mail.python.org/mailman/listinfo/python-list