Re: Cartoonify Myself
On 17/05/11 20:26, Chris M. Bartos wrote: Hi, Is there a Python module that can "cartoonify" a picture of myself? There's got to be an algorithm out there somewhere, right? If there is a way to cartoon a single picture, could you cartoonify a video, too? Thanks for your help. Chris You could have a look at the python automation module for the gimp (a free software image editor). See e.g.: http://starryalley.homelinux.net/blog/index.php?/archives/1248-Star-Trail-Automation-script-using-python-gimp.html -- http://mail.python.org/mailman/listinfo/python-list
indirect assignment question
Hi, I have some lines of code which currently look like this: self.window = self.wTree.get_widget("mainWindow") self.outputToggleMenu = self.wTree.get_widget("menuitem_output_on") self.outputToggleButton = self.wTree.get_widget("button_toggle_output") self.logView = self.wTree.get_widget("textview_log") self.logScrollWindow = self.wTree.get_widget("scrolledwindow_log") and I would like (for tidiness / compactness's sake) to replace them with something like this: widgetDic = { "mainWindow": self.window, "menuitem_output_on": self.outputToggleMenu, "button_toggle_output": self.outputToggleButton, "textview_log": self.logView, "scrolledwindow_log": self.logScrollWindow } for key in widgetDic: ... set the variable in dic[key] to point to self.wTree.get_widget(key) somehow what I need is some kind of indirect assignment where I can assign to a variable whose name is referenced in a dictionary value. Is there a way of doing this in python? thanks, andy baxter -- http://highfellow.org -- http://mail.python.org/mailman/listinfo/python-list
Re: regular expression i'm going crazy
On 16/05/11 17:25, Tracubik wrote: pls help me fixing this: import re s = "linka la baba" re_s = re.compile(r'(link|l)a' , re.IGNORECASE) print re_s.findall(s) output: ['link', 'l'] why? i want my re_s to find linka and la, he just find link and l and forget about the ending a. The round brackets define a 'capturing group'. I.e. when you do findall it returns those elements in the string that match what's inside the brackets. If you want to get linka and la, you need something like this: >>> re_s = re.compile(r'((link|l)a)' , re.IGNORECASE) >>> print re_s.findall(s) [('linka', 'link'), ('la', 'l')] Then just look at the first element in each of the tuples in the array (which matches the outside set of brackets). see: http://www.regular-expressions.info/python.html -- http://mail.python.org/mailman/listinfo/python-list
Re: threads with gtk gui problem
On 14/05/11 14:12, Andy Baxter wrote: Hi, I'm working on adding a Gtk GUI to a python program. Its main function is to read raw data from an arduino board over USB, and convert it to MIDI note/controller events to be sent to another program. I've had it working fine with just a command line interface, but when I replaced the command line with a Gtk interface, I started having problems getting the thread that reads the USB port to run. I'm not sure what the custom is on this list for pasting code - It's a long program so I don't want to paste the whole thing. The sequence of events I've coded is: - the program starts. - the port reader thread (which is a threading.Thread subclass) is initialised. - the object which controls the interface is initialised (i.e. the glade file is loaded.) - the port reader is started (i.e. the 'start' method is called, which calls the 'run' method in a thread). - then the gtk main loop is run. The behaviour I'm getting is that the port reader either fails to start, or stops running at the point where it tries to initialise the serial port. It then does nothing until I close the main window, at which point it starts running again. The port reader's run method begins like this: # the method called by the thread superclass to run the main loop of the thread. def run(self): # main loop of thread. print "Starting port reader." fhan=serial.Serial(port=keeper.config['usbPort'], baudrate=keeper.config['usbBaud'], timeout=0.1) print "1" fhan.open() print "2" seq=PySeq() # the sequencer library object port=seq.createOutPort(keeper.config['midiPortName']) # make a midi out port. midich=keeper.config['midich'] print "3" while True: inbuf=[] print ".", char=fhan.read(1) if self.quit: fhan.close() return if len(char)==0: continue ... (code to process the character read in) ('keeper' is a global object which stores the config data and references to a few key objects). When you start the program, the thread stops either before the first print statement, or on the line which initialises the serial port ( fhan=serial.Serial(...) ). '1', '2', and '3' only get printed /after/ you close the gtk main window. I've verified that the problem is due to the gtk main loop interfering with the thread I've started. If I use this code: if __name__ == "__main__": print "Starting mapper" keeper=Keeper() # initialise the keeper. (A global object which holds references to key objects) keeper.start() # tell the keeper to start the port reader. for n in xrange(10): # wait for 10 seconds. time.sleep(1) print "x" #gtk.main() # start the gtk main loop. keeper.stop() # tell the keeper to shut things down. the program runs correctly. I.e. values are read from the usb port when they come in. if I use this code: if __name__ == "__main__": print "Starting mapper" keeper=Keeper() # initialise the keeper. (A global object which holds references to key objects) keeper.start() # tell the keeper to start the port reader. #for n in xrange(10): # time.sleep(1) # print "x" gtk.main() # start the gtk main loop. keeper.stop() # tell the keeper to shut things down. The port reader thread blocks at the point it tries to open the serial port. I.e. 'Starting port reader' is printed straight away, but '1', '2', and '3' are only printed after you close the gtk main window. -- http://mail.python.org/mailman/listinfo/python-list
Re: threads with gtk gui problem
On 14/05/11 14:12, Andy Baxter wrote: Hi, I'm working on adding a Gtk GUI to a python program. Its main function is to read raw data from an arduino board over USB, and convert it to MIDI note/controller events to be sent to another program. I've had it working fine with just a command line interface, but when I replaced the command line with a Gtk interface, I started having problems getting the thread that reads the USB port to run. I've solved this by adding 'import gobject' and 'gobject.threads_init()' to the start of the program. Looks like if you don't do this then the gtk main loop never releases the python threading lock to other threads. andy -- http://mail.python.org/mailman/listinfo/python-list
threads with gtk gui problem
Hi, I'm working on adding a Gtk GUI to a python program. Its main function is to read raw data from an arduino board over USB, and convert it to MIDI note/controller events to be sent to another program. I've had it working fine with just a command line interface, but when I replaced the command line with a Gtk interface, I started having problems getting the thread that reads the USB port to run. I'm not sure what the custom is on this list for pasting code - It's a long program so I don't want to paste the whole thing. The sequence of events I've coded is: - the program starts. - the port reader thread (which is a threading.Thread subclass) is initialised. - the object which controls the interface is initialised (i.e. the glade file is loaded.) - the port reader is started (i.e. the 'start' method is called, which calls the 'run' method in a thread). - then the gtk main loop is run. The behaviour I'm getting is that the port reader either fails to start, or stops running at the point where it tries to initialise the serial port. It then does nothing until I close the main window, at which point it starts running again. The port reader's run method begins like this: # the method called by the thread superclass to run the main loop of the thread. def run(self): # main loop of thread. print "Starting port reader." fhan=serial.Serial(port=keeper.config['usbPort'], baudrate=keeper.config['usbBaud'], timeout=0.1) print "1" fhan.open() print "2" seq=PySeq() # the sequencer library object port=seq.createOutPort(keeper.config['midiPortName']) # make a midi out port. midich=keeper.config['midich'] print "3" while True: inbuf=[] print ".", char=fhan.read(1) if self.quit: fhan.close() return if len(char)==0: continue ... (code to process the character read in) ('keeper' is a global object which stores the config data and references to a few key objects). When you start the program, the thread stops either before the first print statement, or on the line which initialises the serial port ( fhan=serial.Serial(...) ). '1', '2', and '3' only get printed /after/ you close the gtk main window. Can anyone help with this? cheers, andy baxter -- http://highfellow.org -- http://mail.python.org/mailman/listinfo/python-list