Re: [Tutor] Command line scripts
As you can tell, I was excited, and impressed by my own work, and therefore thought you should follow my wise and almighty work. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command line scripts
On Thu, Jan 13, 2011 at 8:41 AM, David Hutto smokefl...@gmail.com wrote: As you can tell, I was excited, and impressed by my own work, and therefore thought you should follow my wise and almighty work. On the flip side, it's like being an electrician, and seeing the lights come on when you hook the box up. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command line scripts
On Sun, Jan 9, 2011 at 9:03 AM, ALAN GAULD alan.ga...@btinternet.com wrote: The following line is what I mean by calling a command line from within the app using subprocess. self.espeak = subprocess.Popen(['espeak', word],stdout = subprocess.PIPE).communicate()[0] OK, Now I understand. You want to call an external application from within your code via subprocess. And you want to know if that will work ok in a wxPython application? In other words, is a command line app different from bindings in a compiled app? When you call an app using subprocess it spawns an entirely separate process in the OS. There is no linkage to your process apart from the redirection of stdin/stdout/stderr back to your app instead of to a console. So-called exe generators simply bundle the interpreter witrh the code and auto run it. So it's basically just installing a sandbox version of python? Sort of, its a minimalist version of python with only the modules needed to run the app. And you can't run the interpreter on its own you can only run the packaged app. Which ultimately is, if I have a standalone application, that doesn't come from a command line terminal launching(which I haven't gotten to yet), is using the command line calls going through subprocess going to be called without the terminal, or will it open a terminal automatically to make those calls? The app (eSpeak in your example) will see your app as its console. That is, it will send all output to your app and read all input from your app I was thinking that since the app is called from the command line with python(which is no different, than using any other command line script-just like espeak 'word' - python script.py), it would be go back to the shell window it was spawned/called from through python and utilize the command line there. Similar to how when I run the app, my data can be through the app text/label fields, or, through the terminal window itself. (so you need to make sure it gets any input it is expecting!) The other thing to watch in a wxPython (or any other GUI framework) is that if the app runs for a long time your app may freeze from the user's perspective, so you may want to run it in the background or as a separate thread in your app. Or will all of my python apps need to have a command line terminal open to launch them. No, your app takes over the job of the terminal. When you launch a program from the terninal the terminal app(for it is just an app like any other) is doing the same as you, it is spawning a subprocess that sends its output back to the teminal for it to display. In fact you might find it a useful exercise to build a very basic terminal app in wxPython first. Read commands from a command input field and display the output in a text widget... Execute the commands via subprocess. Its a good way to get used to using subprocess and experimenting with its various options. If you are very keen you can start adding command history and search etc to it too... I'll eventually get to the above(I have a lot of projects, some will involve command line/subprocess:), but thanks for the explanation. I'm guessing that something like cxfreezeI haven't looked it over thoroughly) might be what I was looking for. Although in the end, it's just for other to see your work, because most of my own apps are for me personally, which might be a good thing. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command line scripts
On Wed, Jan 12, 2011 at 9:29 PM, David Hutto smokefl...@gmail.com wrote: On Sun, Jan 9, 2011 at 9:03 AM, ALAN GAULD alan.ga...@btinternet.com wrote: The following line is what I mean by calling a command line from within the app using subprocess. self.espeak = subprocess.Popen(['espeak', word],stdout = subprocess.PIPE).communicate()[0] I came up with this as an example, I am still learning also :) [code] #!/usr/bin/python # wx python + espeak from subprocess import call import sys import wx class ESpeak(wx.Dialog): def __init__(self, parent, id, title): wx.Dialog.__init__(self, parent, id, title, size=(360, 370)) panel = wx.Panel(self, -1) vbox = wx.BoxSizer(wx.VERTICAL) hbox1 = wx.BoxSizer(wx.HORIZONTAL) st1 = wx.StaticText(panel, -1, 'Enter Saying: ') self.tc1 = wx.TextCtrl(panel, -1, size=(180, -1)) button_send = wx.Button(panel, 1, 'Say') hbox1.Add(st1, 0, wx.LEFT, 10) hbox1.Add(self.tc1, 0, wx.LEFT, 10) vbox.Add(hbox1, 0, wx.TOP, 50) vbox.Add(button_send, 0, wx.ALIGN_CENTER | wx.TOP | wx.TOP | wx.BOTTOM, 100) self.Bind(wx.EVT_BUTTON, self.OnSpeak, id=1) panel.SetSizer(vbox) self.Centre() self.ShowModal() self.Destroy() def OnSpeak(self, event): say = self.tc1.GetValue() if say != : espeak = /usr/bin/espeak call([espeak, say]) else: dlg = wx.MessageDialog(self, 'What did you say?', 'Error', wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() app = wx.App() ESpeak(None, -1, 'wxESpeak') app.MainLoop() [/code] -david ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command line scripts
I think it works great as an easy integration for the blind(although I'm sure there is already a python module for that somewhere), as long as they have espeak(or it can be easily adapted), but also if you just like the ai feel of a voice in your apps. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command line scripts
Although, I'd just go with a function that gets passed the text, that way it was reusable, like the one I gave. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command line scripts
Although, you did just that, didn't pay attention to the whole thing. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command line scripts
The following line is what I mean by calling a command line from within the app using subprocess. self.espeak = subprocess.Popen(['espeak', word],stdout = subprocess.PIPE).communicate()[0] OK, Now I understand. You want to call an external application from within your code via subprocess. And you want to know if that will work ok in a wxPython application? In other words, is a command line app different from bindings in a compiled app? When you call an app using subprocess it spawns an entirely separate process in the OS. There is no linkage to your process apart from the redirection of stdin/stdout/stderr back to your app instead of to a console. So-called exe generators simply bundle the interpreter witrh the code and auto run it. So it's basically just installing a sandbox version of python? Sort of, its a minimalist version of python with only the modules needed to run the app. And you can't run the interpreter on its own you can only run the packaged app. Which ultimately is, if I have a standalone application, that doesn't come from a command line terminal launching(which I haven't gotten to yet), is using the command line calls going through subprocess going to be called without the terminal, or will it open a terminal automatically to make those calls? The app (eSpeak in your example) will see your app as its console. That is, it will send all output to your app and read all input from your app (so you need to make sure it gets any input it is expecting!) The other thing to watch in a wxPython (or any other GUI framework) is that if the app runs for a long time your app may freeze from the user's perspective, so you may want to run it in the background or as a separate thread in your app. Or will all of my python apps need to have a command line terminal open to launch them. No, your app takes over the job of the terminal. When you launch a program from the terninal the terminal app(for it is just an app like any other) is doing the same as you, it is spawning a subprocess that sends its output back to the teminal for it to display. In fact you might find it a useful exercise to build a very basic terminal app in wxPython first. Read commands from a command input field and display the output in a text widget... Execute the commands via subprocess. Its a good way to get used to using subprocess and experimenting with its various options. If you are very keen you can start adding command history and search etc to it too... HTH, Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Command line scripts
David Hutto smokefl...@gmail.com wrote If I use as command line script, is there any disruption in the execution of the code using wxpython. I don't understand the question. wxPython is a GUI toolkit so how would you have a command line script using wxPython? Or do you mean running a wxPython GUI program from the command line? - that should work just fine. In other words, is a command line app different from bindings in a compiled app? What kind of bindings? And what do you mean by a compiled app? Python is interpreted (or actually compiled to byte code and the byte code is interpreted - but its the same principle). So-called exe generators simply bundle the interpreter witrh the code and auto run it. And wxPython is irrelevant to that debate since it is just a set of modules regardless of how you run it. @ trace def play(self, event = None, text = None): if event == None: self.textlist = [] for item in text.split(' '): self.textlist.append(item) print self.textlist for word in self.textlist: self.espeak = subprocess.Popen(['espeak', word], stdout = subprocess.PIPE).communicate()[0] if event != None: self.textlist = [] for item in self.text2speech.GetValue().split(' '): self.textlist.append(item) print self.textlist for word in self.textlist: self.espeak = subprocess.Popen(['espeak', word], stdout = subprocess.PIPE).communicate()[0] Sorry, I'm missing the significance of this function? Confused,. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor