def main(): """ creates a HAL component. parsees a glade XML file with gtk.builder or libglade calls gladevcp.makepins with the specified XML file to create pins and register callbacks. main window must be called "window1" """ global gladevcp_debug (progdir, progname) = os.path.split(sys.argv[0]) usage = "usage: %prog [options] myfile.ui" parser = OptionParser(usage=usage) parser.disable_interspersed_args() parser.add_options(options) (opts, args) = parser.parse_args() if not args: parser.print_help() sys.exit(1) gladevcp_debug = debug = opts.debug xmlname = args[0] #if there was no component name specified use the xml file name if opts.component is None: opts.component = os.path.splitext(os.path.basename(xmlname))[0] #try loading as a libglade project try: builder = gtk.glade.XML(xmlname) builder = GladeBuilder(builder) except: try: # try loading as a gtk.builder project dbg("**** GLADE VCP INFO: Not a libglade project, trying to load as a GTK builder project") builder = gtk.Builder() builder.add_from_file(xmlname) except Exception,e: print >> sys.stderr, "**** GLADE VCP ERROR: With xml file: %s : %s" % (xmlname,e) sys.exit(0)
def main(): """ creates a HAL component. parsees a glade XML file with gtk.builder or libglade calls gladevcp.makepins with the specified XML file to create pins and register callbacks. main window must be called "window1" """ global gladevcp_debug (progdir, progname) = os.path.split(sys.argv[0]) usage = "usage: %prog [options] myfile.ui" parser = OptionParser(usage=usage) parser.disable_interspersed_args() parser.add_options(options) (opts, args) = parser.parse_args() if not args: parser.print_help() sys.exit(1) gladevcp_debug = debug = opts.debug xmlname = args[0] if opts.instance > -1 and not remote_ok: print >> sys.stderr, "gladevcp: cant operate remotely - modules missing" sys.exit(1) #if there was no component name specified use the xml file name if opts.component is None: opts.component = os.path.splitext(os.path.basename(xmlname))[0] #try loading as a libglade project try: builder = gtk.Builder() builder.add_from_file(xmlname) except: try: # try loading as a gtk.builder project dbg("**** GLADE VCP INFO: Not a builder project, trying to load as a lib glade project" ) builder = gtk.glade.XML(xmlname) builder = GladeBuilder(builder) except Exception, e: print >> sys.stderr, "**** GLADE VCP ERROR: With xml file: %s : %s" % ( xmlname, e) sys.exit(0)
def main(): """ creates a HAL component. parsees a glade XML file with gtk.builder or libglade calls gladevcp.makepins with the specified XML file to create pins and register callbacks. main window must be called "window1" """ global gladevcp_debug (progdir, progname) = os.path.split(sys.argv[0]) usage = "usage: %prog [options] myfile.ui" parser = OptionParser(usage=usage) parser.disable_interspersed_args() parser.add_options(options) (opts, args) = parser.parse_args() if not args: parser.print_help() sys.exit(1) gladevcp_debug = debug = opts.debug xmlname = args[0] #if there was no component name specified use the xml file name if opts.component is None: opts.component = os.path.splitext(os.path.basename(xmlname))[0] #try loading as a libglade project try: builder = gtk.glade.XML(xmlname) builder = GladeBuilder(builder) except: try: # try loading as a gtk.builder project print "**** GLADE VCP INFO: Not a libglade project, trying to load as a GTK builder project" builder = gtk.Builder() builder.add_from_file(xmlname) except: print "**** GLADE VCP ERROR: With xml file: %s" % xmlname sys.exit(0) window = builder.get_object("window1") window.set_title(opts.component) try: halcomp = hal.component(opts.component) except: print "*** GLADE VCP ERROR: Asking for a HAL component using a name that already exists." sys.exit(0) panel = gladevcp.makepins.GladePanel(halcomp, xmlname, builder, None) # at this point, any glade HL widgets and their pins are set up. handlers = load_handlers(opts.usermod, halcomp, builder, opts.useropts) builder.connect_signals(handlers) if opts.parent: # block X errors since gdk error handling silently exits the # program without even the atexit handler given a chance gtk.gdk.error_trap_push() window = xembed.reparent(window, opts.parent) forward = os.environ.get('AXIS_FORWARD_EVENTS_TO', None) if forward: xembed.keyboard_forward(window, forward) window.connect("destroy", on_window_destroy) window.show() # for window resize and or position options if "+" in opts.geometry: try: j = opts.geometry.partition("+") pos = j[2].partition("+") window.move(int(pos[0]), int(pos[2])) except: print "**** GLADE VCP ERROR: With window position data" parser.print_usage() sys.exit(1) if "x" in opts.geometry: try: if "+" in opts.geometry: j = opts.geometry.partition("+") t = j[0].partition("x") else: t = window_geometry.partition("x") window.resize(int(t[0]), int(t[2])) except: print "**** GLADE VCP ERROR: With window resize data" parser.print_usage() sys.exit(1) if opts.gtk_workaround: # work around https://bugs.launchpad.net/ubuntu/+source/pygtk/+bug/507739 # this makes widget and widget_class matches in gtkrc and theme files actually work dbg("activating GTK bug workaround for gtkrc files") for o in builder.get_objects(): if isinstance(o, gtk.Widget): # retrieving the name works only for GtkBuilder files, not for # libglade files, so be cautious about it name = gtk.Buildable.get_name(o) if name: o.set_name(name) if opts.gtk_rc: dbg("**** GLADE VCP INFO: %s reading gtkrc file '%s'" % (opts.component, opts.gtk_rc)) gtk.rc_add_default_file(opts.gtk_rc) gtk.rc_parse(opts.gtk_rc) if opts.theme: dbg("**** GLADE VCP INFO: Switching %s to '%s' theme" % (opts.component, opts.theme)) settings = gtk.settings_get_default() settings.set_string_property("gtk-theme-name", opts.theme, "") # This needs to be done after geometry moves so on dual screens the window maxumizes to the actual used screen size. if opts.maximum: window.window.maximize() if opts.halfile: cmd = ["halcmd", "-f", opts.halfile] res = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr) if res: print >> sys.stderr, "'%s' exited with %d" % (' '.join(cmd), res) sys.exit(res) # User components are set up so report that we are ready halcomp.ready() if handlers.has_key(signal_func): dbg("Register callback '%s' for SIGINT and SIGTERM" % (signal_func)) signal.signal(signal.SIGTERM, handlers[signal_func]) signal.signal(signal.SIGINT, handlers[signal_func]) try: gtk.main() except KeyboardInterrupt: sys.exit(0) finally: halcomp.exit() if opts.parent: gtk.gdk.flush() error = gtk.gdk.error_trap_pop() if error: print "**** GLADE VCP ERROR: X Protocol Error: %s" % str(error)
def main(): """ creates a HAL component. parsees a glade XML file with Gtk.builder or libglade calls gladevcp.makepins with the specified XML file to create pins and register callbacks. main window must be called "window1" """ global gladevcp_debug (progdir, progname) = os.path.split(sys.argv[0]) usage = "usage: %prog [options] myfile.ui" parser = OptionParser(usage=usage) parser.disable_interspersed_args() parser.add_options(options) (opts, args) = parser.parse_args() if not args: parser.print_help() sys.exit(1) gladevcp_debug = debug = opts.debug xmlname = args[0] #if there was no component name specified use the xml file name if opts.component is None: opts.component = os.path.splitext(os.path.basename(xmlname))[0] #try loading as a libglade project try: builder = Gtk.Builder() builder.add_from_file(xmlname) except: try: # try loading as a Gtk.builder project dbg("**** GLADE VCP INFO: Not a builder project, trying to load as a lib glade project") builder = Gtk.glade.XML(xmlname) builder = GladeBuilder(builder) except Exception as e: print("**** GLADE VCP ERROR: With xml file: %s : %s" % (xmlname,e), file=sys.stderr) sys.exit(0) window = builder.get_object("window1") window.set_title(opts.component) try: halcomp = hal.component(opts.component) except: print("*** GLADE VCP ERROR: Asking for a HAL component using a name that already exists.", file=sys.stderr) sys.exit(0) panel = gladevcp.makepins.GladePanel( halcomp, xmlname, builder, None) # at this point, any glade HL widgets and their pins are set up. handlers, mod, obj = load_handlers(opts.usermod,halcomp,builder,opts.useropts) # so widgets can call handler functions - give them refeence to the handler object panel.set_handler(obj) builder.connect_signals(handlers) # This option puts the gladevcp panel into a plug and pushed the plug's # X window id number to standard output - so it can be reparented exterally # it also forwards events to qtvcp if opts.push_XID: if not opts.debug: # supress warnings when x window closes warnings.filterwarnings("ignore") # block X errors since Gdk error handling silently exits the # program without even the atexit handler given a chance Gdk.error_trap_push() forward = os.environ.get('QTVCP_FORWARD_EVENTS_TO', None) if forward: xembed.keyboard_forward(window, forward) # This option reparents gladevcp in a given X window id. # it also forwards keyboard events from gladevcp to AXIS if opts.parent: if not opts.debug: # supress warnings when x window closes warnings.filterwarnings("ignore") # block X errors since Gdk error handling silently exits the # program without even the atexit handler given a chance Gdk.error_trap_push() window = xembed.reparent(window, opts.parent) forward = os.environ.get('AXIS_FORWARD_EVENTS_TO', None) if forward: xembed.keyboard_forward(window, forward) window.connect("destroy", on_window_destroy) window.show() # for window resize and or position options if "+" in opts.geometry: try: j = opts.geometry.partition("+") pos = j[2].partition("+") window.move( int(pos[0]), int(pos[2]) ) except: print("**** GLADE VCP ERROR: With window position data", file=sys.stderr) parser.print_usage() sys.exit(1) if "x" in opts.geometry: try: if "+" in opts.geometry: j = opts.geometry.partition("+") t = j[0].partition("x") else: t = window_geometry.partition("x") window.resize( int(t[0]), int(t[2]) ) except: print("**** GLADE VCP ERROR: With window resize data", file=sys.stderr) parser.print_usage() sys.exit(1) if opts.gtk_rc: dbg( "**** GLADE VCP INFO: %s reading gtkrc file '%s'" %(opts.component,opts.gtk_rc)) Gtk.rc_add_default_file(opts.gtk_rc) Gtk.rc_parse(opts.gtk_rc) if opts.theme: dbg("**** GLADE VCP INFO: Switching %s to '%s' theme" %(opts.component,opts.theme)) settings = Gtk.Settings.get_default() settings.set_string_property("gtk-theme-name", opts.theme, "") # This needs to be done after geometry moves so on dual screens the window maxumizes to the actual used screen size. if opts.maximum: window.window.maximize() if opts.always_above_flag: window.set_keep_above(True) if opts.halfile: if opts.halfile[-4:] == ".tcl": cmd = ["haltcl", opts.halfile] else: cmd = ["halcmd", "-f", opts.halfile] res = subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr) if res: print("'%s' exited with %d" %(' '.join(cmd), res), file=sys.stderr) sys.exit(res) # User components are set up so report that we are ready halcomp.ready() GSTAT.forced_update() # push the XWindow id number to standard out if opts.push_XID or opts.parent: w_id = window.get_property('window').get_xid() print(w_id, file=sys.stdout) sys.stdout.flush() if signal_func in handlers: dbg("Register callback '%s' for SIGINT and SIGTERM" %(signal_func)) signal.signal(signal.SIGTERM, handlers[signal_func]) signal.signal(signal.SIGINT, handlers[signal_func]) try: Gtk.main() except KeyboardInterrupt: sys.exit(0) finally: halcomp.exit() if opts.parent or opts.push_XID: Gdk.flush() error = Gdk.error_trap_pop() if error and opts.debug: print("**** GLADE VCP ERROR: X Protocol Error: %s" % str(error), file=sys.stderr)