Re: [Tutor] Executing a C Program from RH Linux in Python for Win
"Wayne Watson" wrote If you can execute a C program compiled on a Linux with SWIG, then that's what I'm looking for. Nope, you need the suprocess module not SWIG. What SWIG does (fairly easily!) is allow you to build a wrapper around your C program that python can import and call the C functions like normal Python code. I don;t think you want that, you just want to run the program. What you haven't made clear yet is whether you need to get your program to interact with the C program or whether you just want to run the executable with no interaction. (This is much easier obviously!) See my OS topic for various solutions to this. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
> likely will allow the user to enter the 12 or so parameters > on the command line, and execute the program as though > I had entered it at a Linux prompt. OK, In that case you only need the call() convenience function from the subprocess module. Capture the arguments in your GUI and build the command options into a list. Pass that to subprocess.call() See: http://docs.python.org/library/subprocess.html#convenience-functions HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fun with Label and Entry--Why N....(Command Prompt)
Title: Signature.html ALAN GAULD wrote: > It was a bit hard to verify your code, since when I copied it, > it had different indentation and I may not have assembled it > properly. Was the only change to the code? > See "nevertheless" comment below. > root = Tk() > DialogPrototype(root) It's currently fine. No extra window. I moved the call to withdraw from after root=Tk() up into the body method, at the very end of it. > never got clear on how to fill out a line in command line. > Using tab doesn't work. You have to turn that on, see the CMD help page for the registry keys to set I'm amazed that I still remember how to help>cmdHELP.txt. :-) Yikes, registry keys. Maybe I need a dose of >From Help, maybe this is the ticket. Delayed environment variable expansion is NOT enabled by default. You can enable or disable delayed environment variable expansion for a particular invocation of CMD.EXE with the /V:ON or /V:OFF switch. You can enable or disable completion for all invocations of CMD.EXE on a machine and/or user logon session by setting either or both of the following REG_DWORD values in the registry using REGEDT32.EXE: > F8 worked once, but never again. It should be F3 not F8... F3 seems to produce some copy from a prior line rather than allow me to extend something like: C:\abc to C|:\abcde.txt But I guess I need to do something to the registry to make that happen? > Yes, I know I can back up to previous lines and modify them. That's what I use rather than F3, I just hit Up-Arrow. > Then too there is no way to copy things out of that window. If you have QuickEdit selected you just grab it with the mouse and hit enter. You can then paste it wherever you like... QuickEdit is on, but dragging over the area to be copied is not very selective. It forms a rectangle. Further, Ctrl-C doesn't copy anything. Help gives no clue about copy. Alan G. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
Title: Signature.html "I think it this case it requires executing the program command line with parameters then executing it." That is, I likely will allow the user to enter the 12 or so parameters on the command line, and execute the program as though I had entered it at a Linux prompt. The program, Wolf, uses graphics only to produce a image like a jpg file. % ./wolf -h usage: wolf [-d|m|w|c|l|i|t|u|xN|yN|rN|bN|fFILENAME|h|qN|sN|g|e|v|pN] [julian_date] [observatory] input_image output_image type "wolf -h" for help -d: detect "unexpected" object but only draw star labels. -m: draw stars labels. -w: draw label on the target image without changing its content. -i: use inverted images (white sky and black stars). -c: draw constellations lines. -t: generate photometry files. -v: draw visibility levels. -l: draw RA and DEC lines. -h: show these lines. -xN: set the center of the input image N pixels left (use negative N for moving right). -yN: set the center of the input image N pixels down (use negative N for moving up). -rN: draw the labels N pixels right of its position. -bN: draw the label N pixels below its position. -fFILENAME: draw objects from an extrenal file FILENAME. -qN: set quality of the output image (0-100) -sN: set size of the output image (0-100) -g: Create a background fits image -e: Create a image of emissivity map -u: create photometry files for stars -pN: unwrap the fisheye image. N - scale of the output image (1=normal size) >From wolf.h #define wolf #include #include #include #include #include "cgi-draw.h" << #include "novas.h" #include "global.h" #include "calstars.h" #include "imatrix.h" #include "cnstl.h" Alan Gauld wrote: "Wayne Watson" wrote If you can execute a C program compiled on a Linux with SWIG, then that's what I'm looking for. Nope, you need the suprocess module not SWIG. What SWIG does (fairly easily!) is allow you to build a wrapper around your C program that python can import and call the C functions like normal Python code. I don;t think you want that, you just want to run the program. What you haven't made clear yet is whether you need to get your program to interact with the C program or whether you just want to run the executable with no interaction. (This is much easier obviously!) See my OS topic for various solutions to this. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
Good. See my follow up to Alan's post for more details on what I'm doing. Apparently, not SWIG. Thanks for the Alan link. Martin Walsh wrote: Wayne Watson wrote: If you can execute a C program compiled on a Linux with SWIG, then that's what I'm looking for. There's really no RH dependency according to the above posts. If it were compiled on Debian or Ubuntu, it appears it would not make any difference. That is, one could execute a RH executable from C on Ubuntu. Yeah, probably -- if it's a static build, or if the dependencies (required libraries/versions) are installed, assuming the program has dependencies. But, I suppose we may be drifting a bit OT. Is there a simple example of this in action from a Python program and some small C Linux executable program? http://docs.python.org/library/subprocess.html The subprocess module is commonly recommended for this type of task (as opposed to os.system, etc). In fact, I believe Alan already suggested it in this thread. And speaking of ... Alan's tutorial has several very good examples of using the subprocess module (OS topic under Manipulating Processes). http://www.freenetpages.co.uk/hp/alan.gauld/tutos.htm --- I'll hazard a wild guess that you don't really want SWIG based on your original question, and subsequent comments. IIUC, SWIG is intended to ease the creation of a python wrapper (extension module) for existing C/C++ code. And, I'm not sure you've given enough information about the C program to determine if SWIG would be useful. Regardless, I suggest you get a feel for running an external program using python first. HTH, Marty ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fun with Label and Entry--Why N....(Command Prompt)
Title: Signature.html I'm amazed that after years of not using DOS or Linux that I still recall how to use the > for output to a file. I put the output in the cmdHELP.txt file so I could more easily read it. ALAN GAULD wrote: >>You have to turn that on, see the CMD help page for the registry keys to set > I'm amazed that I still remember how to help>cmdHELP.txt. :-) What does that mean? I'm confused. I meant using the help command inside the DOS window C:\> HELP CMD You can also search for cmd in the GUI help system but I find that slower (although the HTML formatted text is easier to read I guess). Alan G. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Tkinter Geometry Management and Other Basics
Title: Signature.html As I understand it, there are three geometry managers: Grids, Pack and Place. Only the first two are of interest. Is it possible to mix them? I don't think so, but maybe I'm missing something. Generally, they seem to apply with respect to a Frame, so I would think only one geometry can be used in a Frame. However, if one is used for frameA and another for frameB, can they both be used with in a parent frame, which has its own geometry (grid or pack)? Suppose I want a parent frame to have a title and below it a 2 column grid with say a Label and Entry. I put the latter in a frame combo in a frame, and attach it to the parent. Do I need to put the title/label in a frame and do the same? Let' see if the following code clarifies this. First, the resulting dialog looks like this: --- Geographic Location Latitude:BOXLongitude:BOX Zenith x:Zenithy:BOXZenith Pixel Position OK Cancel <- Std buttons - BOX = a rectangle for data entry. There's very little separation between labels and entries. Title labels are in bold. Stuff is kind of jammed together, the "Zenith Pixel Position" title should be one line up. My guess is that I need to use the weight concept available with Grid, columnconfigure and rowconfigure to justify and open up the data entry rows. Perhaps there's a geometry tutor somewhere on the web. Bits and pieces of this stuff is scattered around the web. ===Start== # Location/Misc Dialog Prototype from Tkinter import * from tkSimpleDialog import Dialog import tkSimpleDialog import tkMessageBox class DialogPrototype(Dialog): def body(self, master): # Titles fLocationTitle = Frame(master) # fL... for frame fLocationTitle.pack() # Sub entries fCoords = Frame(master) fCoords.pack(side=TOP) fZenith = Frame(master) fZenith.pack(side=LEFT) self.title("Enter Site/Misc. Data") # Latitude and Longitude Label(fLocationTitle, text="Geographic Location").grid(row=0,column=0) Label(fCoords, text='Latitude:').grid(row=0, sticky=W) self.lat = Entry(fCoords, width=12) self.lat.grid(row=0, column=1) Label(fCoords, text='Longitude:').grid(row=0, column=2) self.long = Entry(fCoords, width=12) self.long.grid(row=0, column=3) # Zenith pixels fZenithTitle = Frame(master) fZenithTitle.pack(side=TOP) Label(fZenithTitle, text="Zenith Pixel Position").grid(row=0,column=0) Label(fZenith, text='Zenith x:').grid(row=0, sticky=W) self.zenith_x = Entry(fZenith, width=6) self.zenith_x.grid(row=0, column=1) Label(fZenith, text='Zenith y:').grid(row=0, column=2) self.zenith_y = Entry(fZenith, width=6) self.zenith_y.grid(row=0, column=3) return end== -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Trouble parsing email from Outlook
Hello, list! I hope it's not too much out of place to ask this question in the Tutor list. I'm trying to process some information from email messages that goes in a folder called: "SysAdmin". I could reproduce the recipe from Python Programming on Win32 sucessfully to read the subject line of the inbox, but not from a different folder: So far my code is this: import win32com.client ses = win32com.client.Dispatch("Mapi.Session") o = win32com.client.Dispatch("Outlook.Application") ses.Logon("Default") print ses.Inbox.Messages.Item(1).Subject How can I check stuff from the folder "SysAdmin", then? I get lost with the references from CDO, MAPI with Visual Basic code (I don't understad VB) I get from Microsoft and other sites. Thanks for any pointer. Eduardo ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter Geometry Management and Other Basics
With respect to grid and pack, all siblings must use the same manager. Do otherwise and your application will hang. Children/parents may use different managers. I don't believe there are any restrictions on place, as it doesn't do any negotiation. Cheers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter Geometry Management and Other Basics
"Wayne Watson" wrote As I understand it, there are three geometry managers: Grids, Pack and Place. Only the first two are of interest. Yes and a new Form one coming in the next Tk release... Is it possible to mix them? I don't think so, Yes but not in a single Frame. But my normal approach is to defie my top window using multiple frames. Each frame is packed into the top window. But within each subframe I may use either the packer or the grid depemnding on the widgets inside. So long as yyou stick to a single style inside a Frame you can mix n match to suit the layout. However, if one is used for frameA and another for frameB, can they both be used with in a parent frame, which has its own geometry (grid or pack)? Absolutely. Suppose I want a parent frame to have a title and below it a 2 column grid with say a Label and Entry. I put the latter in a frame combo in a frame, and attach it to the parent. I'd have two frames packed into the window (packer stacks vertically by default). In the top Frame I'd pack the title - centred is default with pack. In the second frame I'd use grid with a single row, one cell with label the other with the entry. First, the resulting dialog looks like this: --- Geographic Location Latitude:BOXLongitude:BOX Zenith x:Zenithy:BOXZenith Pixel Position OK Cancel <- Std buttons - BOX = a rectangle for data entry. There's very little separation between labels and entries. Title labels are in bold. Stuff is kind of jammed together, padx and pady should fix that. Take a look at the Exploring Layout section in my GUI programming topic for more ideas on that. It uses the packer exclusively but should give you some clues. My guess is that I need to use the weight concept available with Grid, columnconfigure and rowconfigure to justify and open up the data entry rows. You are best just experimenting. The way I do that is to write the simplest possible GUI with just a single frame and a button or label in it. Something like: ## # testTk.py from Tkinter import * top = Tk() w = Button(top, text="Button") w.pack() top.mainloop() ## Just play with the pack or grid options and observe the effect If you have the file open in an editor and name the file as .pyw you can then easily run the file from explorer and have multiple versions displayed at the same time to compare results. Perhaps there's a geometry tutor somewhere on the web. Try the Tcl/Tk web sites they tend to be good for that kind of stuff. Its easy to translate the Tk command to Tkinter. HTH, -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Executing a C Program from RH Linux in Python for Win
What is meant by "The arguments are the same as for the Popen constructor.", in Convenience Functions? In fact, what is such a function? This notation seems odd to me: class subprocess.Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False Why not just class Popen instead of subprocess.Popen? Is there a suggestion here that I need only do: myProg=Popen() myProg.call("wolf", "-h") where wolf is the executable C program? Wayne Watson wrote: Good. See my follow up to Alan's post for more details on what I'm doing. Apparently, not SWIG. Thanks for the Alan link. Martin Walsh wrote: Wayne Watson wrote: If you can execute a C program compiled on a Linux with SWIG, then that's what I'm looking for. There's really no RH dependency according to the above posts. If it were compiled on Debian or Ubuntu, it appears it would not make any difference. That is, one could execute a RH executable from C on Ubuntu. Yeah, probably -- if it's a static build, or if the dependencies (required libraries/versions) are installed, assuming the program has dependencies. But, I suppose we may be drifting a bit OT. Is there a simple example of this in action from a Python program and some small C Linux executable program? http://docs.python.org/library/subprocess.html The subprocess module is commonly recommended for this type of task (as opposed to os.system, etc). In fact, I believe Alan already suggested it in this thread. And speaking of ... Alan's tutorial has several very good examples of using the subprocess module (OS topic under Manipulating Processes). http://www.freenetpages.co.uk/hp/alan.gauld/tutos.htm --- I'll hazard a wild guess that you don't really want SWIG based on your original question, and subsequent comments. IIUC, SWIG is intended to ease the creation of a python wrapper (extension module) for existing C/C++ code. And, I'm not sure you've given enough information about the C program to determine if SWIG would be useful. Regardless, I suggest you get a feel for running an external program using python first. HTH, Marty ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Signature.html Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) “Life is one damn thing after another." -- Mark Twain ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] HI, #Include like in python
Hi \o I'm asking if there is any #include( C) like or any include('File.php') (php) like in python. I have 2 files: "usbconnection.py" and "listen.py", And i want to use some classes avaiable in "listen.py" on my main file "usbconnection.py". I've tryed to do __import__("listen.py") but obviously it gave me an error... "ImportError: No module named /home/andrefsp/projects/sigre/listen.py" So, if anybody knows how to do an include in python please reply me =) Bye the way, i've sent an email in last week asking how to read data from USB port. So, i've finally did it, yesterday i was able to read data from my USB port, if anybody is interested in some information about it just need to ask, i don't mind to help =) "it is impossible to make eggs without omelettes " ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HI, #Include like in python
2009/3/20 andré palma : > Hi \o > I'm asking if there is any #include( C) like or any include('File.php') > (php) like in python. > I have 2 files: "usbconnection.py" and "listen.py", And i want to use some > classes avaiable in "listen.py" on my main file "usbconnection.py". I've > tryed to do __import__("listen.py") but obviously it gave me an error... > "ImportError: No module named /home/andrefsp/projects/sigre/listen.py" > > So, if anybody knows how to do an include in python please reply me =) Drop the .py. Just type: import listen You can use the __import__ function if you want, but generally you want the import statement as above. The equivalent to 'import listen' is: listen = __import__('listen') See the tutorial here: http://docs.python.org/tutorial/modules.html -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] HI, #Include like in python
> import listen > > You can use the __import__ function if you want, but generally you > want the import statement as above. The equivalent to 'import listen' > is: > > listen = __import__('listen') > > See the tutorial here: http://docs.python.org/tutorial/modules.html you also have to make sure that your .py file is in one of the folders/directories listed in sys.path (to see it, import sys then do print sys.path). if the file is not in one of those folders, you will also get an import error. you can either add the correct directory to your PYTHONPATH environment variable, or manually add it at run-time using sys.path.append/insert. good luck! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 "Python Fundamentals", Prentice Hall, (c)2009 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor