From timr at probo.com Fri May 1 20:09:45 2015 From: timr at probo.com (Tim Roberts) Date: Fri, 1 May 2015 11:09:45 -0700 Subject: [python-win32] I need to make a COM object with py2exe. Please HELP! In-Reply-To: References: <54ECBDCD.1050103@probo.com> Message-ID: <5543C169.10900@probo.com> Diego V?lez Torres wrote: > > After studying the "Python Programming on Win32" book, I was able to > make COM servers . But so far I can pass simple arguments (in both > directions) between Visual Basic and the Python COM server (e.g. > integers, strings, floats and arrays). I wonder if it's possible to > return from the COM server other kind of objects such as graphics to > be used directly from the .NET program. > > To be more precise, I have Python code that uses heavily Numpy and > Matplotlib. I want to make a COM server that returns images generated > with Matplotlib in order to use within Excel. The best solution I > came out was to store the Matplotlib's images as .PNG in temporary > files. The COM server would return their paths so Visual Basic could > insert them into the spreadsheet with its own commands. > > Though this solution may work, the images cannot be interactive. A > change would require the creation of new images each time, store them, > reload them back, etc... all processes together are expensive. > Therefore, I wish I could return directly from the COM server an image > object that Visual Basic could handle. Another reason why I want to > return an image object directly is because I want to use remote COM > Servers (DCOMs); where the path solution may not work. You are trying to cross-connect several very different worlds here. You are going to be in for a lot of frustrating experimentation. HOWEVER, before we start brainstorming wild ideas, let me point out something that you may have overlooked. You, right now, are using the CPython implementation, which runs the interpreter as native code. If you are going to spend a lot of time interacting with .NET, you may not be aware that there is a complete .NET implementation of Python called IronPython. It is a full .NET language, supported in Visual Studio, running under the same Common Language Runtime as the other .NET languages. And, it supports both NumPy and SciPy. Theoretically, it should be possible to create an IronPython assembly and invoke it directly from Excel. It's possible that would be your least effort solution. If there is a reason you can't do that (and do some serious thinking before you discard it), then you probably have to rely on COM. Your COM object can return other COM objects, although I don't think there are any interfaces that will be recognized by Excel as native graphics objects. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From waldemar.osuch at gmail.com Fri May 1 21:34:54 2015 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Fri, 1 May 2015 13:34:54 -0600 Subject: [python-win32] I need to make a COM object with py2exe. Please HELP! In-Reply-To: <5543C169.10900@probo.com> References: <54ECBDCD.1050103@probo.com> <5543C169.10900@probo.com> Message-ID: This project seems to be relevant to the discussion. http://xlwings.org/ It's Excel <-> Python integration. Maybe you do not have to start from scratch to achieve your goal. w/o -------------- next part -------------- An HTML attachment was scrubbed... URL: From divelez69 at gmail.com Tue May 5 02:14:06 2015 From: divelez69 at gmail.com (=?UTF-8?Q?Diego_V=C3=A9lez_Torres?=) Date: Mon, 4 May 2015 19:14:06 -0500 Subject: [python-win32] I need to make a COM object with py2exe. Please HELP! In-Reply-To: References: <54ECBDCD.1050103@probo.com> <5543C169.10900@probo.com> Message-ID: Hi Tim and Waldemar: I have tried ironPython before. I guess that is pretty straight to compile an ironPython code into a DLL so other .NET program can call it. I never done it before, but I followed an example of a DLL made with C++ that later was called from an ironPython program. However, in order to use Matplotlib within ironPython, this library has to be called with a CPython engine embedded. In fact, the guys of Resolver Systems started "The C Extensions for IronPython Project" in order to use any CPython library with ironPython. But this doesn't solve my original question. It seems that Matplotlib (not any library out there) doesn't generate a usable image objects for Excel. So I think, at the end there would not be any difference if I go for the COM server solution or the ironPython one. I have been checking some external libriaries and APIs that integrates Excel with Python. Among them is "xlwings" as suggested by Waldermar. I'll write my findings so other people reading this forums may benefit: - xlwings: I think this is the earliest package and is open source. I never tried, but it seems very suitable for replacing VBA for Python in Excel spreadsheets. I checked if there's any easy way to bring to the spreadsheet images generated in the Python code , but I didn't find any. Therefore, the only way may be the one I found with the COM servers: save an image file with python, and then load the image with VBA. - ExcelPython: Also is open source, and newer than xlwings. It seems to be better for writting Excel Functions (UDFs). But still relies on VBA on the spreadsheet. I don't know about importing images. - PyXll: This is not an open source, and its fee is quite expensive ($250). It's been around for 5 years and it works very well in all issues. It manages images very well, but looking more in detail, it imports images through temporally files. However, I don't have to write any code in VBA to do so. It relies on PyQt to do so, and some code in Python is required. - DataNitro: This in not open source and its fee is $99. This is basically an Excel Add-In. This is the only one I tested directly. It does work very good in almost everything. It imports images beautifully. It has a PyPlot wrapper called "nitroplot" that behaves exactly the same, but as if it were native to Excel. There're examples of dynamic images working on the spreadsheet. I have no idea how DataNitro imports images. However, I found that this Add-In doesn't work on any version of Excel. For example, I use a Spanish version and there are some issues very difficult (sometimes impossible) to fix. The following blog makes a very interesting comparision https://www.pyxll.com/blog/performance-comparison/ but for obvious reasons is biased towards PyXll. As I don't need dynamic images, I'll go through the route with COM servers and and temporally files in order to import images. So TIM: Now that I know how to build COM servers, can you please give my lights how can I make a stand alone one using py2exe? I need to install in computers were the clients may not even know that Python exists. Thanks everybody for reading and writing about this topic. Best regards, Diego 2015-05-01 14:34 GMT-05:00 Waldemar Osuch : > This project seems to be relevant to the discussion. > http://xlwings.org/ > > It's Excel <-> Python integration. Maybe you do not have to start from > scratch to achieve your goal. > > w/o > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > > -- Diego V?lez Torres divelez69 at gmail.com Tel?fono: 098 28 57 58 Cuenca, Ecuador -------------- next part -------------- An HTML attachment was scrubbed... URL: From adrianpanella at hotmail.com Tue May 5 03:13:23 2015 From: adrianpanella at hotmail.com (=?iso-8859-1?B?QWRyaeFuIFBhbmVsbGE=?=) Date: Mon, 4 May 2015 22:13:23 -0300 Subject: [python-win32] Adodbapi date param error with MS access Message-ID: Hi, I'am trying to use adodbapi to wrap a connection to an .accdb MS Access database and I'm getting an error when executing a query with a date parameter.For what I could deduce the problem is that it converts to COMDate only if "settings_known" is set, which seems not to be the case for Access querys, and defaults to assuming that the parameter is a string even if it is a datetime object. I have solved the problem changing the following lines of code in adodbapi.py (in function _configure_parameter): 195 elif type(value) in dateconverter.types: 196 (old) #if settings_known and adotype in api.adoDateTimeTypes: 196 (new) if adotype in api.adoDateTimeTypes: 197 p.Value = dateconverter.COMDate(value) 198 else: #probably a string This works but it is not very portable as it requires to change library code on each installation. Any suggestions? I have also tried running it as a stored procedure (with callproc), but in that case it tries to retrieve paramenter information (cmd.Parameters.Refresh). Which it does without error but getting all blanks. So it doesn?t work either. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Tue May 5 10:17:51 2015 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 5 May 2015 18:17:51 +1000 Subject: [python-win32] Re: I need to make a COM object with py2exe. Please HELP! In-Reply-To: References: <54ECBDCD.1050103@probo.com> <5543C169.10900@probo.com> Message-ID: <55487CAF.1050602@gmail.com> On 5/05/2015 10:14 AM, Diego V?lez Torres wrote: > So TIM: Now that I know how to build COM servers, can you please give > my lights how can I make a stand alone one using py2exe? I need to > install in computers were the clients may not even know that Python exists. py2exe comes with some sample COM objects - your best bet is to start with them and the py2exe wiki. Mark From divelez69 at gmail.com Tue May 5 13:54:33 2015 From: divelez69 at gmail.com (divelez69) Date: Tue, 05 May 2015 06:54:33 -0500 Subject: [python-win32] I need to make a COM object with py2exe. Please HELP! Message-ID: Thanks Mark Sent from Samsung Mobile
-------- Original message --------
From: Mark Hammond
Date:05-05-2015 3:17 AM (GMT-05:00)
To: Diego V?lez Torres
Cc: Python-Win32 List
Subject: Re: [python-win32] I need to make a COM object with py2exe. Please HELP!
On 5/05/2015 10:14 AM, Diego V?lez Torres wrote: > So TIM: Now that I know how to build COM servers, can you please give > my lights how can I make a stand alone one using py2exe? I need to > install in computers were the clients may not even know that Python exists. py2exe comes with some sample COM objects - your best bet is to start with them and the py2exe wiki. Mark -------------- next part -------------- An HTML attachment was scrubbed... URL: From vernondcole at gmail.com Wed May 6 00:25:15 2015 From: vernondcole at gmail.com (Vernon D. Cole) Date: Tue, 5 May 2015 22:25:15 +0000 Subject: [python-win32] Adodbapi date param error with MS access In-Reply-To: References: Message-ID: Thanks for bringing this to attention. That exception was in the code (in a slightly different form) when I inherited it many years ago. There was once a note to the effect that it was needed to work around a bug in Access. It is very likely that the Jet database engine has been improved in the last decade and the workaround is no longer necessary. Perhaps we can get rid of it. What version of the Jet provider are you using? Do you feel confident that your testing to determine that "this works" was extensive enough to release the patch generally? -- Vernon Cole (adodbapi maintainer) On Tue, May 5, 2015 at 1:13 AM, Adri?n Panella wrote: > Hi, I'am trying to use adodbapi to wrap a connection to an .accdb MS > Access database and I'm getting an error when executing a query with a date > parameter. > For what I could deduce the problem is that it converts to COMDate only if > "settings_known" is set, which seems not to be the case for Access querys, > and defaults to assuming that the parameter is a string even if it is a > datetime object. > > I have solved the problem changing the following lines of code in > adodbapi.py (in function _configure_parameter): > > 195 elif type(value) in dateconverter.types: > 196 (old) #if settings_known and adotype in api.adoDateTimeTypes: > 196 (new) if adotype in api.adoDateTimeTypes: > 197 p.Value = dateconverter.COMDate(value) > 198 else: #probably a string > > This works but it is not very portable as it requires to change library > code on each installation. > > Any suggestions? > > I have also tried running it as a stored procedure (with callproc), but in > that case it tries to retrieve paramenter information > (cmd.Parameters.Refresh). Which it does without error but getting all > blanks. So it doesn?t work either. > > Thanks > > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From adrianpanella at hotmail.com Sat May 9 19:02:08 2015 From: adrianpanella at hotmail.com (=?utf-8?B?QWRyacOhbiBQYW5lbGxh?=) Date: Sat, 9 May 2015 12:02:08 -0500 Subject: [python-win32] Adodbapi date param error with MS access In-Reply-To: References: Message-ID: Hi. I'm using the last ACE driver. I haven't done enough testing to release it. I was first checking here. But I will do it. I think it's not completely general as it doesn't solve the problem with callproc. I'll do some more testing also with the last JET driver and come back, but I can't check side effects with other providers. Adrian > El 05/05/2015, a las 17:25, Vernon D. Cole escribi?: > > Thanks for bringing this to attention. That exception was in the code (in a slightly different form) when I inherited it many years ago. There was once a note to the effect that it was needed to work around a bug in Access. It is very likely that the Jet database engine has been improved in the last decade and the workaround is no longer necessary. Perhaps we can get rid of it. > > What version of the Jet provider are you using? > > Do you feel confident that your testing to determine that "this works" was extensive enough to release the patch generally? > -- > Vernon Cole > (adodbapi maintainer) > >> On Tue, May 5, 2015 at 1:13 AM, Adri?n Panella wrote: >> Hi, I'am trying to use adodbapi to wrap a connection to an .accdb MS Access database and I'm getting an error when executing a query with a date parameter. >> For what I could deduce the problem is that it converts to COMDate only if "settings_known" is set, which seems not to be the case for Access querys, and defaults to assuming that the parameter is a string even if it is a datetime object. >> >> I have solved the problem changing the following lines of code in adodbapi.py (in function _configure_parameter): >> >> 195 elif type(value) in dateconverter.types: >> 196 (old) #if settings_known and adotype in api.adoDateTimeTypes: >> 196 (new) if adotype in api.adoDateTimeTypes: >> 197 p.Value = dateconverter.COMDate(value) >> 198 else: #probably a string >> >> This works but it is not very portable as it requires to change library code on each installation. >> >> Any suggestions? >> >> I have also tried running it as a stored procedure (with callproc), but in that case it tries to retrieve paramenter information (cmd.Parameters.Refresh). Which it does without error but getting all blanks. So it doesn?t work either. >> >> Thanks >> >> >> >> >> _______________________________________________ >> python-win32 mailing list >> python-win32 at python.org >> https://mail.python.org/mailman/listinfo/python-win32 > -------------- next part -------------- An HTML attachment was scrubbed... URL: From waaaseee at gmail.com Mon May 11 09:38:09 2015 From: waaaseee at gmail.com (Wasi Khan) Date: Mon, 11 May 2015 12:38:09 +0500 Subject: [python-win32] Need Contributors/Freelancers required for pywin32 app. Message-ID: Hi pyous people, I have a project I am looking contributors for. It is a software related to education, writing and plagiarism detection. We use pywin32 extensively, so if anyone is interested in working on it freelance or otherwise please contact me. Regards, Wasi Khan -------------- next part -------------- An HTML attachment was scrubbed... URL: From divelez69 at gmail.com Tue May 12 18:32:53 2015 From: divelez69 at gmail.com (=?UTF-8?Q?Diego_V=C3=A9lez_Torres?=) Date: Tue, 12 May 2015 11:32:53 -0500 Subject: [python-win32] Is there anyway to pass a VBA object to a Python COM Server and perform operations? Message-ID: Hi: I'm still working at my COM server. In my project I'm using VBA functions in Excel which in turn call the Python COM Server for farther processes. However, the code in Python calls back into Excel in order to place graphs into the spreadsheet with the calculated data. The first problem that I have encountered is to know exactly the spreadsheet where the VBA function is. The typical line of code: xlApp = win32com.client.Dispatch('Excel.Application') doesn't help as it turns back the first Excel instance registered, which may not be the one where the function is. Even though the Excel may be correct, the spreadsheet or the workbook may be different. I found a not so elegant solution by retrieving in VBA the workbook and sheet names. Later I pass them to the COM server to get the proper object with a line like this: sheet_obj = win32com.client.GetObject(fullname) I tried to simplify the code be passing a VBA object directly to the COM and treat there in the same way as it is done in VBA. For example, in VBA I make this: Set App_Caller = Application.Caller TheGrap = PythonCom.PlaceGraphic(Param1, Param2, App_Caller) Meanwhile in the COM code I do something like this: def PlaceGraphic(self, param1, param2, app_caller): sheet_obj = app_caller.Worksheet When I run the code I get the following error message: 'PyIDispatch' object has no attribute 'Worksheet' Is there anyway to pass a VBA object to a Python COM Server and perform operations? Cheers to all, -- Diego V?lez Torres divelez69 at gmail.com Tel?fono: 098 28 57 58 Cuenca, Ecuador -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Wed May 13 02:45:06 2015 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 13 May 2015 10:45:06 +1000 Subject: [python-win32] Is there anyway to pass a VBA object to a Python COM Server and perform operations? In-Reply-To: References: Message-ID: <55529E92.70104@gmail.com> On 13/05/2015 2:32 AM, Diego V?lez Torres wrote: > Set App_Caller = Application.Caller > TheGrap = PythonCom.PlaceGraphic(Param1, Param2, App_Caller) > > Meanwhile in the COM code I do something like this: > > def PlaceGraphic(self, param1, param2, app_caller): > sheet_obj = app_caller.Worksheet > > When I run the code I get the following error message: > > 'PyIDispatch' object has no attribute 'Worksheet' > > Is there anyway to pass a VBA object to a Python COM Server and perform > operations? You should be able to "wrap" this PyIDispatch by doing win32com.client.Dispatch(app_caller) - Dispatch() lets you pass in either a string or a PyIDispatch. HTH, Mark From divelez69 at gmail.com Sat May 16 19:49:12 2015 From: divelez69 at gmail.com (=?UTF-8?Q?Diego_V=C3=A9lez_Torres?=) Date: Sat, 16 May 2015 12:49:12 -0500 Subject: [python-win32] Issues with tkinter, COM servers and Python 3.x Message-ID: Hi: I'm having issues with tkinter, COM servers and Python 3.4. I can't call tkinter inside a COM server. I tried many examples of tkinter, but every time I try to init a tkniter instance ( tk = tkinter.Tk() ) inside a running COM server, the same following error arises: ''' .... .... tk = Tk() File "C:\Python34\Lib\tkinter\__init__.py", line 1851, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) TypeError: must be str, not bytes ''' Of course the Traceback is much larger, but I intentionally posted the same 5 last lines in order to show where in the __init__ file raises the error. I have tried outside the COM server the same tkinter examples and they work perfectly. However, this is not the case with Python 2.7.9. All tkinter examples work perfectly inside and outside the COM server. I've intensely searched in the web about this specific subject with no luck. Question: Is perhaps needed some setup in order to use tkinter inside a COM server while in Python 3.x? ...or this may be a bug specifically of Python 3.4? Best regards, -- Diego V?lez Torres divelez69 at gmail.com Tel?fono: 098 28 57 58 Cuenca, Ecuador -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Mon May 18 19:26:23 2015 From: timr at probo.com (Tim Roberts) Date: Mon, 18 May 2015 10:26:23 -0700 Subject: [python-win32] Issues with tkinter, COM servers and Python 3.x In-Reply-To: References: Message-ID: <555A20BF.5060202@probo.com> Diego V?lez Torres wrote: > Hi: > > I'm having issues with tkinter, COM servers and Python 3.4. I can't > call tkinter inside a COM server. I tried many examples of tkinter, > but every time I try to init a tkniter instance ( tk = tkinter.Tk() > ) inside a running COM server, the same following error arises: > > tk = Tk() > File "C:\Python34\Lib\tkinter\__init__.py", line 1851, in __init__ > self.tk = _tkinter.create(screenName, baseName, > className, interactive, wantobjects, useTk, sync, use) > TypeError: must be str, not bytes Interesting. The signature in the source code requires screenName, baseName, className, and use to be strings, but only screenName and use are optional. className is not actually used -- the source overrides it. As an experiment, can you change your code to this: tk = Tk( baseName='xxx' ) and see what happens? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From divelez69 at gmail.com Mon May 18 21:49:43 2015 From: divelez69 at gmail.com (=?UTF-8?Q?Diego_V=C3=A9lez_Torres?=) Date: Mon, 18 May 2015 14:49:43 -0500 Subject: [python-win32] Issues with tkinter, COM servers and Python 3.x In-Reply-To: <555A20BF.5060202@probo.com> References: <555A20BF.5060202@probo.com> Message-ID: Hi Tim: I just fixed the issue by applying your advise. But (...and here comes a big BUT !!!), why do I have to do this when calling tkinter inside a COM server, meanwhile this is not necessarily when outside a COM? If my COM Server were using tkinter directly I could rely on this trick. However, my originally problem came up by trying to use pyplot from Matplotlib. I found that pyplot.figure() launches a tk instance. Therefore, in order to use this library (and any other that uses tkinter) within COMs, I must modify the source codes. It doesn't seem this to be a feasible solution. Is there any other solution? Best regards, 2015-05-18 12:26 GMT-05:00 Tim Roberts : > Diego V?lez Torres wrote: > > Hi: > > > > I'm having issues with tkinter, COM servers and Python 3.4. I can't > > call tkinter inside a COM server. I tried many examples of tkinter, > > but every time I try to init a tkniter instance ( tk = tkinter.Tk() > > ) inside a running COM server, the same following error arises: > > > > tk = Tk() > > File "C:\Python34\Lib\tkinter\__init__.py", line 1851, in __init__ > > self.tk = _tkinter.create(screenName, baseName, > > className, interactive, wantobjects, useTk, sync, use) > > TypeError: must be str, not bytes > > Interesting. The signature in the source code requires screenName, > baseName, className, and use to be strings, but only screenName and use > are optional. className is not actually used -- the source overrides > it. As an experiment, can you change your code to this: > tk = Tk( baseName='xxx' ) > and see what happens? > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > -- Diego V?lez Torres divelez69 at gmail.com Tel?fono: 098 28 57 58 Cuenca, Ecuador -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Mon May 18 22:14:02 2015 From: timr at probo.com (Tim Roberts) Date: Mon, 18 May 2015 13:14:02 -0700 Subject: [python-win32] Issues with tkinter, COM servers and Python 3.x In-Reply-To: References: <555A20BF.5060202@probo.com> Message-ID: <555A480A.30202@probo.com> Diego V?lez Torres wrote: > > I just fixed the issue by applying your advise. But (...and here comes > a big BUT !!!), why do I have to do this when calling tkinter inside a > COM server, meanwhile this is not necessarily when outside a COM? You shouldn't. I'm sure this is a bug, but it would take some digging to assign blame and come up with a fix. If you don't pass a baseName, the code in tkinter.__init__.py tries to create one from sys.argv[0]. In a COM server, there may not be a clear value in sys.argv[0]. The call will fail is baseName ends up None; my guess is that's what is happening. > If my COM Server were using tkinter directly I could rely on this > trick. However, my originally problem came up by trying to use pyplot > from Matplotlib. I found that pyplot.figure() launches a tk > instance. Therefore, in order to use this library (and any other that > uses tkinter) within COMs, I must modify the source codes. It doesn't > seem this to be a feasible solution. Is there any other solution? You should be able to modify lib\tkinter\__init.py, and just before the call at line 1851 insert this: if baseName is None: baseName = 'xxx' -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From divelez69 at gmail.com Tue May 19 00:06:49 2015 From: divelez69 at gmail.com (=?UTF-8?Q?Diego_V=C3=A9lez_Torres?=) Date: Mon, 18 May 2015 17:06:49 -0500 Subject: [python-win32] Issues with tkinter, COM servers and Python 3.x In-Reply-To: <555A480A.30202@probo.com> References: <555A20BF.5060202@probo.com> <555A480A.30202@probo.com> Message-ID: Hi Tim: I finally was able to fix this issue in my code. Thanks for your advise. Now I want to share with the community exactly what I did by posting the whole "__init__" method of tkinter's "__init__.py" file: def __init__(self, screenName=None, baseName=None, className='Tk', useTk=1, sync=0, use=None): """Return a new Toplevel widget on screen SCREENNAME. A new Tcl interpreter will be created. BASENAME will be used for the identification of the profile file (see readprofile). It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME is the name of the widget class.""" self.master = None self.children = {} self._tkloaded = 0 # to avoid recursions in the getattr code in case of failure, we # ensure that self.tk is always _something_. self.tk = None if baseName is None: import os baseName = os.path.basename(sys.argv[0]) # Condition added by Diego Velez so 'tkinter' can be called from COM Servers. --May 18th, 2015 if isinstance(baseName, bytes): baseName = baseName.decode() baseName, ext = os.path.splitext(baseName) if ext not in ('.py', '.pyc', '.pyo'): baseName = baseName + ext interactive = 0 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) if useTk: self._loadtk() if not sys.flags.ignore_environment: # Issue #16248: Honor the -E flag to avoid code injection. self.readprofile(baseName, className) As you can see, I added a condition as soon baseName gets sys.argv[0]. If its of a bytes type it encodes to a string type. I'm sure that my COM servers will work. However, I wonder if this should be the final solution to this "bug"; since I don't know if tkinter should deal with these cases, or the COM servers should not send byte types to python codes. Shouldn't we inform to the guys of Python? Best regards, 2015-05-18 15:14 GMT-05:00 Tim Roberts : > Diego V?lez Torres wrote: > > > > I just fixed the issue by applying your advise. But (...and here comes > > a big BUT !!!), why do I have to do this when calling tkinter inside a > > COM server, meanwhile this is not necessarily when outside a COM? > > You shouldn't. I'm sure this is a bug, but it would take some digging > to assign blame and come up with a fix. If you don't pass a baseName, > the code in tkinter.__init__.py tries to create one from sys.argv[0]. > In a COM server, there may not be a clear value in sys.argv[0]. The > call will fail is baseName ends up None; my guess is that's what is > happening. > > > > If my COM Server were using tkinter directly I could rely on this > > trick. However, my originally problem came up by trying to use pyplot > > from Matplotlib. I found that pyplot.figure() launches a tk > > instance. Therefore, in order to use this library (and any other that > > uses tkinter) within COMs, I must modify the source codes. It doesn't > > seem this to be a feasible solution. Is there any other solution? > > You should be able to modify lib\tkinter\__init.py, and just before the > call at line 1851 insert this: > if baseName is None: > baseName = 'xxx' > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > -- Diego V?lez Torres divelez69 at gmail.com Tel?fono: 098 28 57 58 Cuenca, Ecuador -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue May 19 01:02:27 2015 From: timr at probo.com (Tim Roberts) Date: Mon, 18 May 2015 16:02:27 -0700 Subject: [python-win32] Issues with tkinter, COM servers and Python 3.x In-Reply-To: References: <555A20BF.5060202@probo.com> <555A480A.30202@probo.com> Message-ID: <555A6F83.7080803@probo.com> Diego V?lez Torres wrote: > > I finally was able to fix this issue in my code. Thanks for your > advise. Now I want to share with the community exactly what I did by > posting the whole "__init__" method of tkinter's "__init__.py" file: > > def __init__(self, screenName=None, baseName=None, className='Tk', > useTk=1, sync=0, use=None): > ... # Condition added by Diego Velez so 'tkinter' can be called > from COM Servers. --May 18th, 2015 > if isinstance(baseName, bytes): > baseName = baseName.decode() That's very bizarre. Did you print out the value of baseName to see what it was? I'm wondering if something in the Python COM machinery is faking os.path.basename and didn't get the memo about strings in Python 3. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From divelez69 at gmail.com Tue May 19 01:28:25 2015 From: divelez69 at gmail.com (divelez69) Date: Mon, 18 May 2015 18:28:25 -0500 Subject: [python-win32] Issues with tkinter, COM servers and Python 3.x Message-ID: Yes, I did. In normal situations the value is a string, but when I call from a COM is bytes. Sent from Samsung Mobile
-------- Original message --------
From: Tim Roberts
Date:05-18-2015 6:02 PM (GMT-05:00)
To: Python-Win32 List
Subject: Re: [python-win32] Issues with tkinter, COM servers and Python 3.x
Diego V?lez Torres wrote: > > I finally was able to fix this issue in my code. Thanks for your > advise. Now I want to share with the community exactly what I did by > posting the whole "__init__" method of tkinter's "__init__.py" file: > > def __init__(self, screenName=None, baseName=None, className='Tk', > useTk=1, sync=0, use=None): > ... # Condition added by Diego Velez so 'tkinter' can be called > from COM Servers. --May 18th, 2015 > if isinstance(baseName, bytes): > baseName = baseName.decode() That's very bizarre. Did you print out the value of baseName to see what it was? I'm wondering if something in the Python COM machinery is faking os.path.basename and didn't get the memo about strings in Python 3. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org https://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue May 19 02:33:32 2015 From: timr at probo.com (Tim Roberts) Date: Mon, 18 May 2015 17:33:32 -0700 Subject: [python-win32] Issues with tkinter, COM servers and Python 3.x In-Reply-To: References: Message-ID: <555A84DC.3090603@probo.com> divelez69 wrote: > Yes, I did. In normal situations the value is a string, but when I > call from a COM is bytes. I meant, what was the actual VALUE of the string? Was it a fake value, or was it approximately correct? If Python itself is generating os.path.basename, it's hard for me to understand how it could get the wrong type. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue May 19 19:31:06 2015 From: timr at probo.com (Tim Roberts) Date: Tue, 19 May 2015 10:31:06 -0700 Subject: [python-win32] Issues with tkinter, COM servers and Python 3.x In-Reply-To: References: <555A84DC.3090603@probo.com> Message-ID: <555B735A.7080106@probo.com> Diego V?lez Torres wrote: > > The VALUES were an empty string and an empty bytes respectively. > > Before applying your advise, I put some 'prints' in order to > understand what is happening to 'baseName' variable. What I found was > that when I initiate an instance of tkinter app: app = tkinter.Tk() > outside a COM object (eg. directly from the interactive window), the > value was '' (I mean an empty string). The same code, but called from > a COM the value was a b'' (an empty variable of the type bytes). I > don't know if I'm answering your question. I hope I do. Absolutely, yes. Thanks. I have to think this is a bug in the Python COM interface layer, injecting a value into sys.argv without implementing the Python 3 string changes. I don't see the problem in 5 minutes of perusal, but we should get this on a bug list. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From divelez69 at gmail.com Tue May 19 22:08:02 2015 From: divelez69 at gmail.com (divelez69) Date: Tue, 19 May 2015 15:08:02 -0500 Subject: [python-win32] Issues with tkinter, COM servers and Python 3.x Message-ID: Well, at least I feel very proud to have discovered a bug. ?I guess someone else might have step with it before. Sent from Samsung Mobile
-------- Original message --------
From: Tim Roberts
Date:05-19-2015 12:31 PM (GMT-05:00)
To: Python-Win32 List
Subject: Re: [python-win32] Issues with tkinter, COM servers and Python 3.x
Diego V?lez Torres wrote: > > The VALUES were an empty string and an empty bytes respectively. > > Before applying your advise, I put some 'prints' in order to > understand what is happening to 'baseName' variable. What I found was > that when I initiate an instance of tkinter app: app = tkinter.Tk() > outside a COM object (eg. directly from the interactive window), the > value was '' (I mean an empty string). The same code, but called from > a COM the value was a b'' (an empty variable of the type bytes). I > don't know if I'm answering your question. I hope I do. Absolutely, yes. Thanks. I have to think this is a bug in the Python COM interface layer, injecting a value into sys.argv without implementing the Python 3 string changes. I don't see the problem in 5 minutes of perusal, but we should get this on a bug list. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org https://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Wed May 20 08:32:11 2015 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 20 May 2015 16:32:11 +1000 Subject: [python-win32] Issues with tkinter, COM servers and Python 3.x In-Reply-To: <555A6F83.7080803@probo.com> References: <555A20BF.5060202@probo.com> <555A480A.30202@probo.com> <555A6F83.7080803@probo.com> Message-ID: <555C2A6B.2080803@gmail.com> On 19/05/2015 9:02 AM, Tim Roberts wrote: > Diego V?lez Torres wrote: >> >> I finally was able to fix this issue in my code. Thanks for your >> advise. Now I want to share with the community exactly what I did by >> posting the whole "__init__" method of tkinter's "__init__.py" file: >> >> def __init__(self, screenName=None, baseName=None, className='Tk', >> useTk=1, sync=0, use=None): >> ... # Condition added by Diego Velez so 'tkinter' can be called >> from COM Servers. --May 18th, 2015 >> if isinstance(baseName, bytes): >> baseName = baseName.decode() > > That's very bizarre. Did you print out the value of baseName to see > what it was? I'm wondering if something in the Python COM machinery is > faking os.path.basename and didn't get the memo about strings in Python 3. Yeah - argv[0] is created inappropriately for py3k - http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/file/b57d0d7444fb/com/win32com/src/dllmain.cpp#l68 Mark From bifferos at yahoo.co.uk Sun May 31 13:07:05 2015 From: bifferos at yahoo.co.uk (bifferos) Date: Sun, 31 May 2015 11:07:05 +0000 (UTC) Subject: [python-win32] A slightly nutty idea I came up with, that may help with Win32 API wrapper development. Message-ID: <2008009814.3028647.1433070425130.JavaMail.yahoo@mail.yahoo.com> I've produced a script that lets you generate a python module containing the definitions in a windows header file. I do realise that gcc-xml can also help with stuff like this, but I wanted to try another approach to see where it got me. The script is here: https://github.com/bifferos/wrappers/blob/master/defines.py thanks, Biff.