#!/usr/bin/python import gtk, sys, os, sre reg=sre.compile("^\s+--.*$") reg2=sre.compile("^\s+[^:space:].*$") #if len(sys.argv)==2: sys.exit(0) #file=sys.argv[1] #p=os.popen("/home/grzegorz/zsh-4.0.9/configure --help") configure=os.path.join(os.getcwd(),"configure") if os.path.isfile(configure): file=configure else: print "ERROR: ./configure not found." sys.exit(1) p=os.popen(file+" --help") #p=os.popen("/home/grzegorz/CVS/main/configure --help") a=p.readlines() options=[] tmp=-1 cont=0 for i in a: if sre.match(reg,i): tmp+=1 options+=[{}] line=i.strip() sep=line.find(" ") if(sep>0): name=line[:sep] desc=line[sep+1:] else: name=line desc="" sep=name.find("=") default="" arg=[] if sep > 0: arg=[name[sep+1:]] name=name[:sep+1] options[tmp]={"name": name, "desc": desc.strip(), "arg": arg, "def": default, "check": gtk.Widget, "entry": gtk.Widget} cont=1 else: if cont==1 and sre.match(reg2,i): options[tmp]["desc"]+="\n"+i.strip() else: cont=0 for i in options: if len(i["desc"])==0: continue if i["desc"][0]=="\n": i["desc"]=i["desc"][1:] mask={ "--cache-file=": {}, "--prefix=": {}, "--exec-prefix=": {}, "--bindir=": {}, "--sbindir=": {}, "--libexecdir=": {}, "--datadir=": {}, "--sysconfdir=": {}, "--sharedstatedir=": {}, "--localstatedir=": {}, "--libdir=": {}, "--includedir=": {}, "--oldincludedir=": {}, "--infodir=": {}, "--mandir=": {}, "--srcdir=": {}, "--program-prefix=": {}, "--program-suffix=": {}, "--program-transform-name=": {}, "--build=": {}, "--host=": {}, "--target=": {}, "--enable-FEATURE=": {}, "--with-PACKAGE=": {}, "--help": {}, "--version": {}, "--help=": {}, "--no-create": {}, "--quiet,": {}, "--quiet": {}, "--disable-FEATURE": {}, "--without-PACKAGE": {} } window = gtk.Window(gtk.WINDOW_TOPLEVEL) # create a top level window window.connect("destroy", gtk.mainquit) # quit the event loop on destruction window.set_border_width(2) # set padding round child widget box=gtk.VBox(False,0) boxu1=gtk.HBox(False,0) boxu2=gtk.HBox(False,0) boxu3=gtk.HBox(False,0) boxm1=gtk.VBox(True,0) boxm2=gtk.VBox(True,0) boxm3=gtk.VBox(True,0) boxm4=gtk.VBox(True,0) boxl1=gtk.VBox(True,0) boxl2=gtk.VBox(True,0) boxl3=gtk.VBox(True,0) boxr1=gtk.VBox(True,0) boxr2=gtk.VBox(True,0) boxr3=gtk.VBox(True,0) boxT=gtk.HBox(False,0) boxM=gtk.HBox(False,0) scrollT=gtk.ScrolledWindow() scrollT.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) ok=gtk.Button("OK", gtk.STOCK_APPLY) box.pack_start(boxT,False,False,0) box.pack_start(gtk.HSeparator(),False,False,5) scrollT.add_with_viewport(boxM) box.pack_start(scrollT,True,True,0) box.pack_start(gtk.HSeparator(),False,False,5) box.pack_start(ok,False,False,0) def activate(widget,data): if widget.get_active(): data.set_sensitive(1) else: data.set_sensitive(0) def reverse(widget,event): if event.button!=3: return tmp=widget.get_label() if tmp.find("--enable-")==0: widget.set_label(tmp.replace("--enable-","--disable-",1)) elif tmp.find("--disable-")==0: widget.set_label(tmp.replace("--disable-","--enable-",1)) elif tmp.find("--with-")==0: widget.set_label(tmp.replace("--with-","--without-",1)) elif tmp.find("--without-")==0: widget.set_label(tmp.replace("--without-","--with-",1)) def finish(widget, data): print "CONF_OPTS=\"" for i in data: if i["check"].get_active(): if i["entry"]!=gtk.Widget and i["entry"].get_text()!="": print i["check"].get_label()+i["entry"].get_text() else: tmp=i["check"].get_label() if tmp[-1:]=="=": tmp=tmp[:-1] print tmp print "\"" opts=[] opts2=[] rest=[] rest2=[] tooltips=gtk.Tooltips() for v,i in enumerate(options): if len(i["arg"])==0: if mask.has_key(i["name"]): rest2+=[i] else: opts2+=[i] else: if i["arg"][0][-1:]=="]" and i["name"][-2:]=="[=": i["arg"][0]="["+i["arg"][0] i["name"]=i["name"][:-2]+"=" if mask.has_key(i["name"]): rest+=[i] else: opts+=[i] del options def watch_input(entry,checkbox): label=checkbox.get_label() if entry.get_text()=="" and label[-1]=="=": checkbox.set_label(label[:-1]) elif entry.get_text()!="" and label[-1]!="=": checkbox.set_label(label+"=") for v, i in enumerate(opts): opts[v]["check"]=gtk.CheckButton(i["name"]) if len(opts[v]["desc"])>0: tooltips.set_tip(opts[v]["check"],opts[v]["desc"]) opts[v]["entry"]=gtk.Entry() opts[v]["entry"].set_width_chars(15) opts[v]["entry"].set_text(i["arg"][0]) opts[v]["entry"].set_sensitive(0) opts[v]["entry"].connect("changed",watch_input,opts[v]["check"]) opts[v]["check"].connect("toggled",activate,opts[v]["entry"]) opts[v]["check"].connect("button-release-event",reverse) for v, i in enumerate(opts2): opts2[v]["check"]=gtk.CheckButton(i["name"]) tooltips.set_tip(opts2[v]["check"],opts2[v]["desc"]) opts2[v]["check"].connect("button-release-event",reverse) tmp=int(len(opts)/3) if tmp*3!=len(opts): tmp+=1 addT=[0,0,0] for i in opts[:tmp]: boxl1.add(i["check"]) boxr1.add(i["entry"]) addT[0]=1 for i in opts[tmp:tmp*2]: boxl2.add(i["check"]) boxr2.add(i["entry"]) addT[1]=1 for i in opts[tmp*2:]: boxl3.add(i["check"]) boxr3.add(i["entry"]) addT[2]=1 tmp=int(len(opts2)/4) if tmp*4!=len(opts2): tmp+=1 addM=[0,0,0,0] for i in opts2[:tmp]: boxm1.add(i["check"]) addM[0]=1 for i in opts2[tmp:tmp*2]: boxm2.add(i["check"]) addM[1]=1 for i in opts2[tmp*2:tmp*3]: boxm3.add(i["check"]) addM[2]=1 for i in opts2[tmp*3:]: boxm4.add(i["check"]) addM[3]=1 if (addT[0]): tmp=gtk.Alignment(0,0,0,0) tmp.add(boxu1) boxu1.pack_start(boxl1,False,False,0) boxu1.pack_start(boxr1,True,True,0) boxT.pack_start(tmp,False,False,0) if (addT[1]): tmp=gtk.Alignment(0,0,0,0) tmp.add(boxu2) boxu2.pack_start(boxl2,False,False,0) boxu2.pack_start(boxr2,True,True,0) boxT.pack_start(gtk.VSeparator(),False,False,5) boxT.pack_start(tmp,False,False,0) if (addT[2]): tmp=gtk.Alignment(0,0,0,0) tmp.add(boxu3) boxu3.pack_start(boxl3,False,False,0) boxu3.pack_start(boxr3,True,True,0) boxT.pack_start(gtk.VSeparator(),False,False,5) boxT.pack_start(tmp,False,False,0) if (addM[0]): tmp=gtk.Alignment(0,0,0,0) tmp.add(boxm1) boxM.pack_start(tmp,False,False,0) if (addM[1]): tmp=gtk.Alignment(0,0,0,0) tmp.add(boxm2) boxM.pack_start(gtk.VSeparator(),False,False,5) boxM.pack_start(tmp,False,False,0) if (addM[2]): tmp=gtk.Alignment(0,0,0,0) tmp.add(boxm3) boxM.pack_start(gtk.VSeparator(),False,False,5) boxM.pack_start(tmp,False,False,0) if (addM[3]): tmp=gtk.Alignment(0,0,0,0) tmp.add(boxm4) boxM.pack_start(gtk.VSeparator(),False,False,5) boxM.pack_start(tmp,False,False,0) ok.connect("clicked", finish, opts+opts2) window.add(box) window.show_all() (x,y)=boxM.size_request() (x1,y1)=boxT.size_request() y1=600-y1 if y>y1: y=300; y+=20 scrollT.set_size_request(x,y) gtk.main() # enter the main event loop