151 lines
3.6 KiB
Python
151 lines
3.6 KiB
Python
|
#! /usr/bin/python
|
||
|
|
||
|
# To change this template, choose Tools | Templates
|
||
|
# and open the template in the editor.
|
||
|
|
||
|
__author__="bjschuma"
|
||
|
__date__ ="$Mar 14, 2010 9:52:10 PM$"
|
||
|
|
||
|
|
||
|
import ocarina
|
||
|
from et import xm
|
||
|
from ct.call import write
|
||
|
#from oGtk import *
|
||
|
|
||
|
import gtk
|
||
|
|
||
|
global parts
|
||
|
parts = dict()
|
||
|
|
||
|
global buildFunc
|
||
|
buildFunc = None
|
||
|
|
||
|
global window
|
||
|
window = None
|
||
|
|
||
|
|
||
|
def setPacking(old,newVals):
|
||
|
for field in newVals:
|
||
|
if (field=="expand") or (field=="fill"):
|
||
|
if newVals[field]=="True":
|
||
|
old[field] = True
|
||
|
else:
|
||
|
old[field] = False
|
||
|
elif field=="padding":
|
||
|
old[field] = int(newVals[field])
|
||
|
elif field=="pack":
|
||
|
if newVals[field] == "Start":
|
||
|
old[field] = gtk.PACK_START
|
||
|
else:
|
||
|
old[field] = gtk.PACK_END
|
||
|
|
||
|
return old
|
||
|
|
||
|
|
||
|
|
||
|
def buildTabs(node,tabs):
|
||
|
global buildFunc
|
||
|
|
||
|
for child in xm.children(node):
|
||
|
if child.nodeName=="tab":
|
||
|
label = None
|
||
|
content = None
|
||
|
for gchild in xm.children(child):
|
||
|
if gchild.nodeName == "tablabel":
|
||
|
for ggchild in xm.children(gchild):
|
||
|
item = buildFunc(ggchild)
|
||
|
if item != None:
|
||
|
label = item
|
||
|
elif gchild.nodeName == "tabcontent":
|
||
|
for ggchild in xm.children(gchild):
|
||
|
item = buildFunc(ggchild)
|
||
|
if item != None:
|
||
|
content = item
|
||
|
|
||
|
if content != None:
|
||
|
tabs.addpage(content,label)
|
||
|
attrs = setPacking({"expand":False,"fill":False,"pack":gtk.PACK_START}, xm.attributes(child) )
|
||
|
tabs.set_tab_label_packing(content,attrs["expand"],attrs["fill"],attrs["pack"])
|
||
|
|
||
|
|
||
|
def buildMenu(node,menu):
|
||
|
global buildFunc
|
||
|
for child in xm.children(node):
|
||
|
item = buildFunc(child)
|
||
|
if item!=None:
|
||
|
if node.nodeName == "menu-bar":
|
||
|
menu.append(item)
|
||
|
elif node.nodeName == "menuitem":
|
||
|
menu.addSubMenu(item)
|
||
|
|
||
|
|
||
|
def fill(node,container):
|
||
|
global buildFunc
|
||
|
pack = True
|
||
|
packing = {"expand":False,"fill":False,"padding":0,"pack":gtk.PACK_START}
|
||
|
|
||
|
for child in xm.children(node):
|
||
|
viewport = False
|
||
|
if child.nodeName == "add" or child.nodeName == "add-viewport":
|
||
|
if child.nodeName == "add-viewport":
|
||
|
write("We are adding to "+node.nodeName+" with a viewport",2)
|
||
|
viewport = True
|
||
|
else:
|
||
|
write("We are adding to "+node.nodeName,2)
|
||
|
pack = False
|
||
|
for grandchild in xm.children(child):
|
||
|
item = buildFunc(grandchild)
|
||
|
if item != None:
|
||
|
if viewport == False:
|
||
|
container.add(item)
|
||
|
else:
|
||
|
container.add_with_viewport(item)
|
||
|
|
||
|
elif child.nodeName == "pack":
|
||
|
packing = setPacking( packing,xm.attributes(child) )
|
||
|
write("Now using packing: "+str(packing), 2)
|
||
|
|
||
|
else:
|
||
|
item = buildFunc(child)
|
||
|
if item != None:
|
||
|
if pack == False:
|
||
|
container.add(item)
|
||
|
else:
|
||
|
if packing["pack"] == gtk.PACK_START:
|
||
|
container.pack_start(item,packing["expand"],packing["fill"],packing["padding"])
|
||
|
else:
|
||
|
container.pack_end(item,packing["expand"],packing["fill"],packing["padding"])
|
||
|
|
||
|
|
||
|
def build(node):
|
||
|
global parts
|
||
|
tag = node.nodeName
|
||
|
|
||
|
if (tag in parts.keys()) == True:
|
||
|
write("Creating part from tag: "+tag,2)
|
||
|
part = parts[tag](xm.attributes(node))
|
||
|
if (tag=="hbox") or (tag=="vbox") or (tag=="window") or (tag=="scrolled-window") or (tag=="align"):
|
||
|
fill(node,part)
|
||
|
elif (tag=="menu-bar") or (tag=="menuitem"):
|
||
|
buildMenu(node,part)
|
||
|
elif (tag=="tabs"):
|
||
|
buildTabs(node,part)
|
||
|
return part
|
||
|
else:
|
||
|
write("Cannot make part: "+tag,3)
|
||
|
|
||
|
|
||
|
def init():
|
||
|
global window
|
||
|
if window != None:
|
||
|
window.hide()
|
||
|
write("Building gui from file: "+ocarina.vars.THEME,1)
|
||
|
doc = xm.load(ocarina.vars.THEME)
|
||
|
window = build( xm.child(doc) )
|
||
|
ocarina.events.start(ocarina.events.GUI_DONE)
|
||
|
window.show()
|
||
|
|
||
|
|
||
|
buildFunc = build
|
||
|
ocarina.events.invite(ocarina.events.OCARINA_START,init,50)
|
||
|
ocarina.events.invite(ocarina.events.OCARINA_QUIT,gtk.main_quit)
|