Skip to content

Commit

Permalink
Update: gladevcp open file from linuxcnc/share
Browse files Browse the repository at this point in the history
  • Loading branch information
DDTRNG committed May 6, 2014
1 parent 2dd2d5b commit 3479f9f
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/hal/user_comps/gladevcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
from gladevcp.gladebuilder import GladeBuilder
from gladevcp import xembed

import gettext



options = [ Option( '-c', dest='component', metavar='NAME'
, help="Set component name to NAME. Default is basename of UI file")
, Option( '-d', action='store_true', dest='debug'
Expand Down Expand Up @@ -91,6 +95,7 @@ def __call__(self, *a, **kw):
def load_handlers(usermod,halcomp,builder,useropts):
hdl_func = 'get_handlers'


def add_handler(method, f):
if method in handlers:
handlers[method].append(f)
Expand Down Expand Up @@ -171,26 +176,44 @@ def main():
if not args:
parser.print_help()
sys.exit(1)


BASE = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), ".."))
libdir = os.path.join(BASE, "lib", "python")
sys.path.append(libdir)
arhmidir = os.path.join(BASE, "lib", "python", "arhmi")
sys.path.append(arhmidir)

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]

builder = gtk.Builder()
# try loading as a gtk.builder project
try:
builder = gtk.Builder()
builder.add_from_file(xmlname)
except:
#try loading as a libglade project
# #try loading as a libglade project
# try:
# dbg("**** GLADE VCP INFO: Not a GtkBuilder project, trying to load as a GTK builder project")
# builder = gtk.glade.XML(xmlname)
# builder = GladeBuilder(builder)
try:
dbg("**** GLADE VCP INFO: Not a GtkBuilder project, trying to load as a GTK builder project")
builder = gtk.glade.XML(xmlname)
builder = GladeBuilder(builder)
# for arhmi applications
LOCALEDIR = os.path.join(BASE, "share", "locale")
o = "plasma"
gettext.install(o, localedir=LOCALEDIR, unicode=True)
gtk.glade.bindtextdomain(o, LOCALEDIR)
gtk.glade.textdomain(o)

base = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), ".."))
sharedir = os.path.join(base, "share", "linuxcnc")
gladefile = os.path.join(sharedir, xmlname)
builder.add_from_file(gladefile)
except Exception,e:
print >> sys.stderr, "**** GLADE VCP ERROR: With xml file: %s : %s" % (xmlname,e)
print >> sys.stderr, "**** GLADE VCP ERROR: With xml file: %s : %s" % (xmlname, e)
sys.exit(0)

window = builder.get_object("window1")
Expand Down

0 comments on commit 3479f9f

Please sign in to comment.