#!/usr/bin/env python # # Use a slider to write values between 0 and 255 to /dev/rtf4 # import sys try: import pygtk # tell pyGTK, if possible that we want GTKv2 pygtk.require("2.0") except: # Some distributions come with GTK2, but not pyGTK pass try: import gtk import gtk.glade except: print "You need to install pyGTK or GTKv2 ", print "or set your PYTHONPATH correctly." print "try: export PYTHONPATH=", print "/usr/local/lib/python2.2/site-packages/" sys.exit(1) # now we have both gtk and gtk.glade imported # Also, we know we are running GTKv2 class appgui: def __init__(self): """ Initialize and display the main command window """ self.gladefile="proj3.glade" windowname="ServoWindow" self.wTree=gtk.glade.XML(self.gladefile, windowname) handlers = { "on_quit_button_clicked" : (gtk.mainquit), "on_ServoWindow_destroy" : (gtk.mainquit), "on_AngleScale_value_changed" : self.set_angle} self.wTree.signal_autoconnect(handlers) self.rtfifo = open('/dev/rtf4', 'w') return ###################################################################### ### Main Window Methods ###################################################################### def set_angle(self, range): """ Set the slider angle by writing to a real-time fifo """ angle = range.get_value() self.rtfifo.write(chr(int(round((angle + 90.0)/180.0*255)))) self.rtfifo.flush() return app=appgui() gtk.mainloop()