From jrs.idx at ntlworld.com Mon Mar 2 22:21:19 2015 From: jrs.idx at ntlworld.com (John Sampson) Date: Mon, 02 Mar 2015 21:21:19 +0000 Subject: [python-win32] Tkinter newbie Message-ID: <54F4D44F.4040205@ntlworld.com> Hello - I am trying to find out how to write code in Tkinter that opens a file-selection dialog so that I can open a file. It would be part of a program, not a whole program that does nothing else. I have found many examples of Tkinter code, each one using a different approach, some using a geometry manager, some not, some using an object-oriented approach, some not, etc. What I am looking for are examples of code with explicit explanations of each *term* in the code, explaining what it is, what it does and why it has to be there, why in one place it has to be self.x but in another it has to be x(self), why it has to be followed by '()' in one place but not in another, how the variables are scoped and similar questions. At the moment all my guesses are wrong. Are there any such examples? Regards John Sampson From A.Holtz at gmx.net Mon Mar 2 22:48:58 2015 From: A.Holtz at gmx.net (Andreas Holtz) Date: Mon, 02 Mar 2015 22:48:58 +0100 Subject: [python-win32] Tkinter newbie In-Reply-To: <54F4D44F.4040205@ntlworld.com> References: <54F4D44F.4040205@ntlworld.com> Message-ID: <54F4DACA.40806@gmx.net> Hi John, seems you lack basic understanding of Python (and perhaps programming languages at all?). I recommend you reading a book like "Learning Python" from Mark Lutz or check some courses on https://wiki.python.org/moin/BeginnersGuide/Programmers Then you will learn the differences between attributes/variables (no "()") and functions (with () ) and methods (self.x() and x(self)). Later you will ask Google "tkinter open file" and get as first result http://tkinter.unpythonic.net/wiki/tkFileDialog You will look at the example and understand that line 45 fullfill your needs: tkFileDialog.askopenfile(mode='r', **self.file_opt) But you'll ask yourself, where does **self.file_opt come from and you'll understand that line 20 is the interesting thing. Eventually you'll understand, that options = {} options['defaultextension'] = '.txt' options['filetypes'] = [('all files', '.*'), ('text files', '.txt')] options['initialdir'] = 'C:\\' options['initialfile'] = 'myfile.txt' options['parent'] = root options['title'] = 'This is a title' selectedFile = tkFileDialog.askopenfile(mode='r', **options) is the code you are looking for. And perhaps you'll ask yourself, why you wanted to waste the precious time of others at the beginning, when learning and exploring by yourself makes so much more fun. Best Regards Andreas John Sampson schrieb am 02.03.2015 um 22:21: > Hello - > > I am trying to find out how to write code in Tkinter that opens a file-selection dialog so that I > can open a file. It would be part of a program, not a whole program that does nothing else. > > I have found many examples of Tkinter code, each one using a different approach, some using a > geometry manager, some not, some using an object-oriented approach, some not, etc. > What I am looking for are examples of code with explicit explanations of each *term* in the code, > explaining what it is, what it does and why it has to be there, why in one place it has to be self.x > but in another it has to be x(self), why it has to be followed by '()' in one place but not in > another, how the variables are scoped and similar questions. At the moment all my guesses are wrong. > > Are there any such examples? > > Regards > > John Sampson > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > From ethan at stoneleaf.us Mon Mar 2 23:21:05 2015 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 02 Mar 2015 14:21:05 -0800 Subject: [python-win32] Tkinter newbie In-Reply-To: <54F4DACA.40806@gmx.net> References: <54F4D44F.4040205@ntlworld.com> <54F4DACA.40806@gmx.net> Message-ID: <54F4E251.1010606@stoneleaf.us> On 03/02/2015 01:48 PM, Andreas Holtz wrote: > And perhaps you'll ask yourself, why you wanted to waste the precious time of others at the > beginning, when learning and exploring by yourself makes so much more fun. The first 30 or so lines were great: instructive, pointers of where to go for more info, and good resources to aid in learning... but unless the OP is a known troll those last two lines were uncalled for (and if the OP is a known troll, better to not respond at all). -- ~Ethan~ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From A.Holtz at gmx.net Mon Mar 2 23:48:13 2015 From: A.Holtz at gmx.net (Andreas Holtz) Date: Mon, 02 Mar 2015 23:48:13 +0100 Subject: [python-win32] Tkinter newbie In-Reply-To: <54F4E251.1010606@stoneleaf.us> References: <54F4D44F.4040205@ntlworld.com> <54F4DACA.40806@gmx.net> <54F4E251.1010606@stoneleaf.us> Message-ID: <54F4E8AD.4070107@gmx.net> Thank you and you're right. In case of a troll, I still answered because perhaps someone is outhere that could make use of the hints, same as I could from this list and other free ressources when I started Python. In case of a real person that wanted help: "We reap what we sow" or "ask niceley and show that you tried yourself to find a solution". Andreas Ethan Furman schrieb am 02.03.2015 um 23:21: > On 03/02/2015 01:48 PM, Andreas Holtz wrote: > >> And perhaps you'll ask yourself, why you wanted to waste the precious time of others at the >> beginning, when learning and exploring by yourself makes so much more fun. > > The first 30 or so lines were great: instructive, pointers of where to go for more info, and good resources to aid in > learning... but unless the OP is a known troll those last two lines were uncalled for (and if the OP is a known troll, > better to not respond at all). > > -- > ~Ethan~ > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > From jrs.idx at ntlworld.com Tue Mar 3 09:28:31 2015 From: jrs.idx at ntlworld.com (John Sampson) Date: Tue, 03 Mar 2015 08:28:31 +0000 Subject: [python-win32] Tkinter newbie In-Reply-To: <54F4E8AD.4070107@gmx.net> References: <54F4D44F.4040205@ntlworld.com> <54F4DACA.40806@gmx.net> <54F4E251.1010606@stoneleaf.us> <54F4E8AD.4070107@gmx.net> Message-ID: <54F570AF.3000502@ntlworld.com> I had spent a day trying to find a solution. Still, I know now one place I won't look for help. JS >In case of a real person that wanted help: >"We reap what we sow" or "ask niceley and show that you tried yourself to find a solution". From breamoreboy at yahoo.co.uk Tue Mar 3 17:17:56 2015 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 03 Mar 2015 16:17:56 +0000 Subject: [python-win32] Tkinter newbie In-Reply-To: <54F570AF.3000502@ntlworld.com> References: <54F4D44F.4040205@ntlworld.com> <54F4DACA.40806@gmx.net> <54F4E251.1010606@stoneleaf.us> <54F4E8AD.4070107@gmx.net> <54F570AF.3000502@ntlworld.com> Message-ID: On 03/03/2015 08:28, John Sampson wrote: > I had spent a day trying to find a solution. Still, I know now one place > I won't look for help. > > JS > I don't understand why you've asked a tkinter question on a list targeted at Python on Windows. Either try the main python mailing list at https://mail.python.org/mailman/listinfo/python-list or gmane.comp.python.general, or the tkinter specific list at https://mail.python.org/mailman/listinfo/tkinter-discuss or gmane.comp.python.tkinter. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From planders at gmail.com Tue Mar 3 17:50:26 2015 From: planders at gmail.com (Preston Landers) Date: Tue, 3 Mar 2015 10:50:26 -0600 Subject: [python-win32] Tkinter newbie In-Reply-To: References: <54F4D44F.4040205@ntlworld.com> <54F4DACA.40806@gmx.net> <54F4E251.1010606@stoneleaf.us> <54F4E8AD.4070107@gmx.net> <54F570AF.3000502@ntlworld.com> Message-ID: It's not unusual for people to think this list is for general discussion of Python for Windows people, rather than specifically for the PyWin32 package. On Tue, Mar 3, 2015 at 10:17 AM, Mark Lawrence wrote: > On 03/03/2015 08:28, John Sampson wrote: > >> I had spent a day trying to find a solution. Still, I know now one place >> I won't look for help. >> >> JS >> >> > I don't understand why you've asked a tkinter question on a list targeted > at Python on Windows. Either try the main python mailing list at > https://mail.python.org/mailman/listinfo/python-list or > gmane.comp.python.general, or the tkinter specific list at > https://mail.python.org/mailman/listinfo/tkinter-discuss or > gmane.comp.python.tkinter. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence > > > _______________________________________________ > 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 mail at timgolden.me.uk Tue Mar 3 17:59:13 2015 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 03 Mar 2015 16:59:13 +0000 Subject: [python-win32] Tkinter newbie In-Reply-To: References: <54F4D44F.4040205@ntlworld.com> <54F4DACA.40806@gmx.net> <54F4E251.1010606@stoneleaf.us> <54F4E8AD.4070107@gmx.net> <54F570AF.3000502@ntlworld.com> Message-ID: <54F5E861.3030006@timgolden.me.uk> On 03/03/2015 16:50, Preston Landers wrote: > It's not unusual for people to think this list is for general discussion > of Python for Windows people, rather than specifically for the PyWin32 > package. That's because it is. From https://mail.python.org/mailman/listinfo/python-win32: "All issues related to programming Python on Windows. win32 extensions, COM, you name it." TJG From planders at gmail.com Tue Mar 3 20:29:48 2015 From: planders at gmail.com (Preston Landers) Date: Tue, 3 Mar 2015 13:29:48 -0600 Subject: [python-win32] Tkinter newbie In-Reply-To: <54F5E861.3030006@timgolden.me.uk> References: <54F4D44F.4040205@ntlworld.com> <54F4DACA.40806@gmx.net> <54F4E251.1010606@stoneleaf.us> <54F4E8AD.4070107@gmx.net> <54F570AF.3000502@ntlworld.com> <54F5E861.3030006@timgolden.me.uk> Message-ID: Fair enough. What I was getting at is that sometimes people think because they happen to be using Windows this is a good place for general Python questions, rather than stuff that is Windows platform specific. Or in this case he may not have realized that tkinter isn't specific to Windows. On Tue, Mar 3, 2015 at 10:59 AM, Tim Golden wrote: > On 03/03/2015 16:50, Preston Landers wrote: > >> It's not unusual for people to think this list is for general discussion >> of Python for Windows people, rather than specifically for the PyWin32 >> package. >> > > That's because it is. > > From https://mail.python.org/mailman/listinfo/python-win32: > > "All issues related to programming Python on Windows. win32 extensions, > COM, you name it." > > TJG > > _______________________________________________ > 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 pasc.marchand at free.fr Thu Mar 5 23:22:01 2015 From: pasc.marchand at free.fr (Pascal) Date: Thu, 05 Mar 2015 23:22:01 +0100 Subject: [python-win32] Python wn32com : How to give byRef parameters in object method and then get updated values Message-ID: <54F8D709.1010501@free.fr> Hello, I'm not an expert, I just want to experiment python with SolidWorks I'm trying to use its DLL with some success, but unfortunately, with some errors : File ">", line 2, in Get5 com_error: (-2147352571, 'Type mismatch', None, 5) I'm not sure about error comment, it's a translation because my python is in french language. Here is a simplified extract of code : app = win32com.client.Dispatch('Sldworks.Application') part = app.ActiveDoc docext = part.Extension custPropMgr = docext.CustomPropertyManager('ma_config') pNames = tuple(custPropMgr.GetNames) # return array of strings for item in pNames: print(item) # string is well printed var1='' var2='' var3=False custPropMgr.Get5(item, False, var1, var2, var3) <== error happens here I tried several things but I didn't reach to pass correctly the parameters to the Get5 method. I think the problem is with the ByRef parameters, because I already used many method with ByVal parameters and it works rather fine. I tried : var1, var2, var3 = custPropMgr.Get5(item, False) as suggested somewhere but it didn't works this method is described as below in the solidworks API help: Visual Basic (Declaration) Function Get5( _ ByVal/FieldName / As System.String, _ ByVal/UseCached / As System.Boolean, _ ByRef/ValOut / As System.String, _ ByRef/ResolvedValOut / As System.String, _ ByRef/WasResolved / As System.Boolean _ ) As System.Integer Visual Basic (Usage) Dim instance AsICustomPropertyManager Dim FieldName As System.String Dim UseCached As System.Boolean Dim ValOut As System.String Dim ResolvedValOut As System.String Dim WasResolved As System.Boolean Dim value As System.Integer value = instance.Get5(FieldName, UseCached, ValOut, ResolvedValOut, WasResolved) C# System.int Get5( System.string/FieldName /, System.bool/UseCached /, out System.string/ValOut /, out System.string/ResolvedValOut /, out System.bool/WasResolved / ) C++/CLI System.int Get5( & System.String^/FieldName /, & System.bool/UseCached /, & [Out] System.String^/ValOut /, & [Out] System.String^/ResolvedValOut /, & [Out] System.bool/WasResolved / ) Thanks for your help. Best regards. --- L'absence de virus dans ce courrier ?lectronique a ?t? v?rifi?e par le logiciel antivirus Avast. http://www.avast.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.antal at ata-e.com Fri Mar 6 01:49:05 2015 From: greg.antal at ata-e.com (Greg Antal) Date: Thu, 05 Mar 2015 16:49:05 -0800 Subject: [python-win32] Python wn32com : How to give byRef parameters in object method and then get updated values In-Reply-To: <54F8D709.1010501@free.fr> References: <54F8D709.1010501@free.fr> Message-ID: <54F8F981.6060702@ata-e.com> An HTML attachment was scrubbed... URL: From pasc.marchand at free.fr Sat Mar 7 14:50:05 2015 From: pasc.marchand at free.fr (Pascal) Date: Sat, 07 Mar 2015 14:50:05 +0100 Subject: [python-win32] Python wn32com : How to give byRef parameters in object method and then get updated values Message-ID: <54FB020D.5050208@free.fr> Hi, Sorry Greg, as I was the only recipient of the message, I didn't take care to dispatch email to full python-win32 list. I work a few since my last email and yes, I have several questions and comments about use of win32com through SolidWorks API. 1-/ I tried makepy and the result was the same, but with google and patience I found a way to make my functions work. There is for me some suprising behaviour : e.g. : Open a doc works as : def openDoc(self, path, docType): model, errors, warnings = sw.OpenDoc6(model_path, cst(docType), swconst.constants.swOpenDocOptions_Silent, '', pythoncom.Missing, pythoncom.Missing) model.Visible = True return model while getting parameters function get5 works as : def params(self,ipart,cfg): ext = ipart.Extension custPropMgr = ext.CustomPropertyManager(cfg) pNames = tuple(custPropMgr.GetNames) pValues = [] res=0 for item in pNames: valOut = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR,'F') resolvedValOut = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR,'R') wasResolved = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BOOL, 0) res = custPropMgr.Get5(item, False, resolvedValOut, valOut, wasResolved ) v_wR = wasResolved.value v_wasResolved = valOut.value v_valOut = v_wR v_resolvedValOut = resolvedValOut.value pValues.append([v_valOut, v_resolvedValOut, v_wasResolved]) return pValues In first case only byRef parameters are needed and then they are returned as triple with the normal result in usual language (model) In second case, if you don't give a correct typed parameter, it raise an error : type mismatch or missing (in case of pythoncom.missing) Moreover, it don't return as I hoped : normal_result, byref1, byref2, byref3 = custPropMgr.Get5(...) but only normal_result = custPropMgr.Get5(...) and byref results returned in defined variables (made with VARIANT) Note : returned parameters are not in the right order (seems to be in reverse order) not really important, except in loop, because types are not always the same, so you must init vars in the loop! 2-/ Note : this also works without making a makepy module (very interesting for future use because nothing special to do) We have a kind of common experience, because my first use of Python and solidworks (not together) happens when I worked with MSC Marc/autoforge Non-linear finite element softwares. Thanks for your support and your french encouragement. ______________________________________________________________ Greg wrote: I only use SolidWorks occasionally, and I have never tried to use its API. But, it's on my computer and I knew what to look for based on my prior experience with a finite element pre/post processor called Femap, so I was able to help. If you have further questions, it is best to send them to the discussion list rather than directly to me, even if I eventually answer them. Everything sent to the list is archived, so other people with similar problems may be able find answers in the archives. That's why I sent my answer to the list, too. Bonne chance, et bon courage. - Greg ------------------ Gregory W. Antal Senior Technical Advisor ATA Engineering, Inc. 13290 Evening Creek Drive South, Suite 250 San Diego, CA 92128 www.ata-e.com greg.antal at ata-e.com 858-480-2072 (Phone) 858-792-8932 (Fax) ------------------ Pascal wrote on 3/6/2015 12:20 AM: Hi, Thank you so much Greg for your quick reply. I will try it asap. I saw several times references to makepy but it was usually confuse for me and I didn't understand really what is behind it. Your explanation is very clear and I understand better its utility. Maybe, I'm a bit curious, but you seems to know Solidworks, do you use Python with it ? Thanks again and have a good day. Le 06/03/2015 01:47, Greg Antal a ?crit : > Pascal wrote on 3/5/2015 2:22 PM: >> Hello, >> >> I'm not an expert, I just want to experiment python with SolidWorks >> I'm trying to use its DLL with some success, but unfortunately, with >> some errors : >> File ">", line 2, in Get5 >> com_error: (-2147352571, 'Type mismatch', None, 5) >> >> I'm not sure about error comment, it's a translation because my >> python is in french language. >> >> Here is a simplified extract of code : >> >> app = win32com.client.Dispatch('Sldworks.Application') >> part = app.ActiveDoc >> >> docext = part.Extension >> custPropMgr = docext.CustomPropertyManager('ma_config') >> pNames = tuple(custPropMgr.GetNames) # return array of strings >> >> for item in pNames: >> print(item) # string is well printed >> var1='' >> var2='' >> var3=False >> custPropMgr.Get5(item, False, var1, var2, var3) <== error >> happens here >> >> I tried several things but I didn't reach to pass correctly the >> parameters to the Get5 method. >> I think the problem is with the ByRef parameters, because I already >> used many method with ByVal parameters and it works rather fine. >> >> I tried : var1, var2, var3 = custPropMgr.Get5(item, False) as >> suggested somewhere but it didn't works >> >> this method is described as below in the solidworks API help: >> >> Visual Basic (Declaration) >> Function Get5( _ >> ByVal/FieldName / As System.String, _ >> ByVal/UseCached / As System.Boolean, _ >> ByRef/ValOut / As System.String, _ >> ByRef/ResolvedValOut / As System.String, _ >> ByRef/WasResolved / As System.Boolean _ >> ) As System.Integer >> >> Visual Basic (Usage) >> Dim instance AsICustomPropertyManager >> Dim FieldName As System.String >> Dim UseCached As System.Boolean >> Dim ValOut As System.String >> Dim ResolvedValOut As System.String >> Dim WasResolved As System.Boolean >> Dim value As System.Integer >> >> value = instance.Get5(FieldName, UseCached, ValOut, ResolvedValOut, WasResolved) >> >> > > I'm not much of an expert either, but I also use an API with many > ByRef parameters in its method calls. The way I solved the problem was > to use "early binding" of the COM objects. > > To do that, you must first find the Type Library for your API. For > SolidWorks, this may be "sldworks.tlb", although I can't really be > sure. I see 20 "tlb" files in my [/SolidWorks_path/]\SolidWorks > folder, and I have no idea which one you might need, or even if you > need all of them. I would start with "sldworks.tlb". > > Next, from that type library, you create a Python file that you can > import into your code. You do that with the "makepy" utility that > comes with the Python COM package. > 1. Open a command window in the folder where you keep the Python code > you're developing. > 2. Enter the command > [/Python_path/]\Lib\site-packages\win32com\client\makepy.py -v -o > PySldworks.py [/SolidWorks_path/]\SolidWorks\sldworks.tlb > This will create a file called PySldworks.py (you can name it whatever > you want, of course). Now you can just add "Import PySldworks" to all > the Import statements you already use. > > Instead of > app = win32com.client.Dispatch('Sldworks.Application') > > you have something like > app = PySldworks.SldWorks > > Now those calls that return data using ByRef parameters should work > with the Python-like form you tried because PySldworks.py has already > defined it: > var1, var2, var3 = custPropMgr.Get5(item, False) > > If that method has a return code, it will appear before the ByRef > parameters: > rc, var1, var2, var3 = custPropMgr.Get5(item, False) > > If that doesn't work, you can look in PySldworks.py to understand > exactly what it thinks it should do with that method; it is, after > all, just another Python file. > > If there is another way to solve this problem, I don't know what it > is. One of the real experts who monitor this list will have to help > you with that. > > - Greg Antal > > ------------------ > Gregory W. Antal > Senior Technical Advisor > ATA Engineering, Inc. > 13290 Evening Creek Drive South, Suite 250 > San Diego, CA 92128 > www.ata-e.com > > greg.antal at ata-e.com > 858-480-2072 (Phone) > 858-792-8932 (Fax) > ------------------ --- L'absence de virus dans ce courrier ?lectronique a ?t? v?rifi?e par le logiciel antivirus Avast. http://www.avast.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jmfrank63 at gmail.com Sun Mar 8 04:46:57 2015 From: jmfrank63 at gmail.com (Johannes Frank) Date: Sun, 8 Mar 2015 03:46:57 +0000 Subject: [python-win32] Failure in calling ie.document.body.getElementsByTagName('div') Message-ID: Hello Mark, hello everyone, I just wanted to report that the following error occurs: Traceback (most recent call last): File "C:\Python27\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript exec codeObject in __main__.__dict__ File "C:\Users\jmfra_000\Documents\Python Scripts\IEControl.py", line 11, in divs = ie.Document.body.GetElementsByTagName('div') File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 192, in __call__ return self._get_good_object_(self._oleobj_.Invoke(*allArgs),self._olerepr_.defaultDispatchName,None) com_error: (-2147352319, 'OLE error 0x80020101', None, None) Here is my script: import win32com.client sh = win32com.client.Dispatch('Shell.Application') windows = sh.Windows() for window in windows: if 'iexplore' in window.FullName.lower(): ie = window divs = ie.Document.body.GetElementsByTagName('div') There is no hurry to fix this (if at all) because it can be easily avoided by calling: divs = ie.Document.body.all.tags('div') Calling the same in IronPython works both ways. I just thought you might be interested. Thank you for your attention Cheers Johannes -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Mon Mar 9 23:01:20 2015 From: timr at probo.com (Tim Roberts) Date: Mon, 9 Mar 2015 15:01:20 -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: <54FE1830.6010709@probo.com> Diego V?lez Torres wrote: > > I just purchased M. Hammond's "Python Programming on Win32" book. > Though a bit old the (1999) still is of great help. I have been able > to make simple COM servers so far. However, I have a question > regarding the code examples found in his http://starship.python.net/ > web site. Are they written in Python 1.x... or Python 2.x? I wonder > if there are code examples written for Python 3.x? They are almost certainly Python 2. Python 1 was quickly replaced by Python 2 in the 1990s. The differences between 2 and 3 are small enough that the samples are still useful. The most significant annoying difference is the print function, and you can fix that with a text editor. Occasionally, I'll have an issue with the change in string type to Unicode, but that's about it. The COM stuff still works exactly the same as it did before. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From divelez69 at gmail.com Mon Mar 9 22:55:21 2015 From: divelez69 at gmail.com (=?UTF-8?Q?Diego_V=C3=A9lez_Torres?=) Date: Mon, 9 Mar 2015 16:55:21 -0500 Subject: [python-win32] I need to make a COM object with py2exe. Please HELP! In-Reply-To: <54ECBDCD.1050103@probo.com> References: <54ECBDCD.1050103@probo.com> Message-ID: Thank you Tim. Your advise is been of great help. I just purchased M. Hammond's "Python Programming on Win32" book. Though a bit old the (1999) still is of great help. I have been able to make simple COM servers so far. However, I have a question regarding the code examples found in his http://starship.python.net/ web site. Are they written in Python 1.x... or Python 2.x? I wonder if there are code examples written for Python 3.x? Cheers to all in the mailing list. 2015-02-24 13:07 GMT-05:00 Tim Roberts : > Diego V?lez Torres wrote: > > > > I need to make a COM object upon my Python code, so I can call it from > > .NET programs (ie. Visual Basic, VB6). I need the COM object (or DLL) > > to be stand alone, because the target PCs where the final programs are > > going to run won't have Python installed. I know so far that py2exe > > supports this directly: > > http://www.py2exe.org/index.cgi/Py2exeAndCtypesComDllServer > > > > I've tried to make some samples with the given link's instructions, > > but I haven't been lucky. I only got empty 'dist' and 'build' folders. > > I've search for documentation on the web for quite a long time with no > > luck. I realized that I need more information besides the one provided > > by the above's link: > > > > 1. How the Python module that I want to compile must be written? I > > mean, all functions and classes in module will be available for > > the outside code through the COM Object? That module needs > > specific lines of code? > > > > What you are trying to create is a COM server. If you search for > "python COM server", you will find many examples. It does have to be > written in a particular way. You have to identify the functions you > want to be exposed, the registry program ID, and the registry GUID in > specially named class members (_public_methods_, _reg_progid_, > _reg_clsid_). > > I suggest you make the COM part work first. Once you have that working, > then you can dig in to py2exe to make it standalone. > > -- > 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 yanf at jiangdatech.com Sun Mar 29 14:35:32 2015 From: yanf at jiangdatech.com (=?gb2312?B?48a3yQ==?=) Date: Sun, 29 Mar 2015 20:35:32 +0800 Subject: [python-win32] howto get the typename of a comobject Message-ID: <000001d06a1c$d97b0110$8c710330$@jiangdatech.com> Hi,I have the same problem ,do u have a solution about it ? tks Best Regards, Fei Yan ?? Technical Engineer -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.png Type: image/png Size: 18353 bytes Desc: not available URL: From timr at probo.com Mon Mar 30 19:06:21 2015 From: timr at probo.com (Tim Roberts) Date: Mon, 30 Mar 2015 10:06:21 -0700 Subject: [python-win32] howto get the typename of a comobject In-Reply-To: <000001d06a1c$d97b0110$8c710330$@jiangdatech.com> References: <000001d06a1c$d97b0110$8c710330$@jiangdatech.com> Message-ID: <5519828D.8050603@probo.com> ?? wrote: > > Hi,I have the same problem ,do u have a solution about it ? tks > Did you read any of the responses in that thread? There was a very good explanation. Another possibility is to get the IDispatch interface from the object, call GetTypeInfo to fetch the ITypeInfo interface, then call GetDocumentation to fetch the object name. That's what VBA is doing behind the scenes. By the way, I can't believe you quoted the original message by grabbing a screen and posting it as an image. That's NOT how you quote a message in a technical forum. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From esj at harvee.org Mon Mar 30 22:40:13 2015 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 30 Mar 2015 16:40:13 -0400 Subject: [python-win32] getting Windows key codes Message-ID: <5519B4AD.3070103@harvee.org> https://docs.google.com/drawings/d/1M-TzfRaSaAhFXQk1OmcmHNOaW31_7W_7q0bf8CAJqSw/edit Set with some help for a friend of mine, I was able to implement the system illustrated above. As a result I can mostly successfully use speech recognition on Windows to dictate text into a variety of Linux applications. I discover some problems which make me think that the right solution is to capture windows events/key codes and translate them into the lyrics equivalents. This way I think I can handle many of the special function keys more easily. My question is two parts, first is how do I get access to these key codes (equivalent to what's in the Python uinput module). And what kind of framework does Windows demand (text window etc.) in order to be able to expose these key codes. I thought this should be a question Google can answer but I haven't found the right question. Thanks for any help or pointers --- eric From timr at probo.com Mon Mar 30 23:50:51 2015 From: timr at probo.com (Tim Roberts) Date: Mon, 30 Mar 2015 14:50:51 -0700 Subject: [python-win32] getting Windows key codes In-Reply-To: <5519B4AD.3070103@harvee.org> References: <5519B4AD.3070103@harvee.org> Message-ID: <5519C53B.2030800@probo.com> Eric S. Johansson wrote: > Set with some help for a friend of mine, I was able to implement the > system illustrated above. As a result I can mostly successfully use > speech recognition on Windows to dictate text into a variety of Linux > applications. I discover some problems which make me think that the > right solution is to capture windows events/key codes and translate them > into the lyrics equivalents. This way I think I can handle many of the > special function keys more easily. I assume that should be "Linux", rather than "lyrics". If you are doing speech recognition, where do Windows events and key codes come into play? > My question is two parts, first is how do I get access to these key > codes (equivalent to what's in the Python uinput module). And what kind > of framework does Windows demand (text window etc.) in order to be able > to expose these key codes. Your question isn't clear. What key codes and events do you want to grab? Perhaps you should give us a couple of specific scenarios that describe what you want to have happen. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From esj at harvee.org Tue Mar 31 01:41:47 2015 From: esj at harvee.org (Eric S. Johansson) Date: Mon, 30 Mar 2015 19:41:47 -0400 Subject: [python-win32] getting Windows key codes In-Reply-To: <5519C53B.2030800@probo.com> References: <5519B4AD.3070103@harvee.org> <5519C53B.2030800@probo.com> Message-ID: <5519DF3B.1060701@harvee.org> On 3/30/2015 5:50 PM, Tim Roberts wrote: > Eric S. Johansson wrote: >> Set with some help for a friend of mine, I was able to implement the >> system illustrated above. As a result I can mostly successfully use >> speech recognition on Windows to dictate text into a variety of Linux >> applications. I discover some problems which make me think that the >> right solution is to capture windows events/key codes and translate them >> into the lyrics equivalents. This way I think I can handle many of the >> special function keys more easily. > I assume that should be "Linux", rather than "lyrics". That's one of the ways you can tell someone is using speech recognition. If things look weird, just read it out loud and try to listen to what you're saying > > If you are doing speech recognition, where do Windows events and key > codes come into play? It's one of these side effect things. Speech recognition either generate straight text or in the case of a matching grammar, perform some action. As far as I can tell, NaturallySpeaking shoves events onto the Windows input queue. I think there may be two different types because in one case they have the general form that usually works but they also have a system input stream which is much lower down. I am guessing that they translate the normal Latin one character set spoken into Windows events much in the same way that I do in my code. > > >> My question is two parts, first is how do I get access to these key >> codes (equivalent to what's in the Python uinput module). And what kind >> of framework does Windows demand (text window etc.) in order to be able >> to expose these key codes. > Your question isn't clear. What key codes and events do you want to > grab? Perhaps you should give us a couple of specific scenarios that > describe what you want to have happen. Good idea. the problem that drove me to the conclusion is differentiating between backspace and delete not to mention control H in Emacs. There are also things like cut and paste whose key sequences are variable depending on the application. The ASCII character for delete is 7f it's keycode in uinput/ev.py is KEY_DELETE = (0x01, 111) the ASCII character for backspace is 08 it's keycode in uinput/ev.py is KEY_BACKSPACE = (0x01, 14) Lenox equivalent In a nutshell, what I want to do is given a Windows keycode, translate the keycode to the linux equivalent. I'm starting with handling the control H problem. The keycode gives me access to a whole bunch of additional information about which characters have been spoken versus the characters one can type. For example when I was trying to figure out the difference between backspace and delete inside of Emacs, I did the usual ^q to try and trap the next character and I always get the escape character. If the key codes are what's being used instead of the ASCII character equivalents that would explain why the delete key and control H still available for help. If I am able to translate from Windows key codes to the next key codes then I will have a less lossy conversion (theoretically and be able to handle more of the non-traditional keyboard characters like function keys and meta-keys etc. As for what key codes I need to trap and convert, it's a big I don't know. This exploration process is been one big "what the hell were they thinking" when I see what Nuance generates in response to what I say. --- eric