def saveRealm(fi): if not defaults.get("set",False): setDefaults() lines = [] if fi is None or fi == "": fi = "default" print "Saving realm %s"% fi fi = "realms/%s.rlm"% fi line = getline(fi,1) comp = {} matchlike = config.get("matchlike",False) if "likerealm" in line: values = [a.strip() for a in line.split('=')] comp = loadRealm("realms/%s.rlm"% values[1]) lines.append(line) write = False for key in config.keys(): if key in rlmkeys and config[key] != defaults.get(key): write = False if matchlike == 2: write = True elif matchlike == 1 and config.get(key) != comp.get(key): write = True elif matchlike == 0 and key in rlmsavekeys: write = True if write: lines.append("%s = %s\n" % (key,config[key])) try: f = open(os.path.abspath(fi), 'w') if config['debug'] > 0: printPretty(lines) f.writelines(lines) except IOError as e: print " Could not write configuration file: %s" % e finally: f.close()
def updateAge(caller,s,e,t): start = s.get_text() deat = e.get_text() now = config.get("agedate") if now is None or start is None or start == "": return (y,m,d) = parseDate(start) start = datetime.date(y,m,d) (y,m,d) = parseDate(now) end = datetime.date(y,m,d) death = None if deat != None and deat != "": (y,m,d) = parseDate(deat) death = datetime.date(y,m,d) born = False died = False if start < end: born = True dead = 0 if death is not None and death < end: died = True dead = getAge(death,end) age = getAge(start,end) text = "%d at %s" % (age,end) if died: s = "s" if dead == 1: s = "" text = "%d at death, dead for %d year%s" % (age,dead,s) if not born: text = "Not yet born" if not config['hideage']: text = "(%s)" % text t.set_text(" %s" % text)
def storyPicker(parent,name,value): global picklist global stories picklist = common.csplit(str(value)) title = "Stories involving %s" % name if not len(stories): stories = myStories(config.get("realmdir")) askbox = gtk.Dialog(title,parent,gtk.DIALOG_DESTROY_WITH_PARENT,None) askbox.add_button("Cancel",1) askbox.add_button("Set",0) for key in sorted(stories.keys()): title = stories.get(key,"") if title and len(title) > 0: button = gtk.CheckButton(title) button.show() button.unset_flags(gtk.CAN_FOCUS) button.connect("toggled",updatePicklist,key) if not picklist: picklist = [] if key in picklist: button.set_active(True) askbox.vbox.pack_start(button,True,True,2) # OK button closes dialog, turns keys into a csv string and returns it (nondefined values, plus defined that are checked) askbox.move(config['pos'][0] + 50,config['pos'][1] + 50) value = askbox.run() askbox.destroy() if value == 0: output = "" for k in range(len(picklist)): if k > 0: output += ", " output += picklist[k] return output else: status.push(0,"Cancel: Stories not modified.") return None
def setTutorialSeen(caller,event = None): global config config['seenfirstrun'] = caller.get_active() if config['debug'] > 6: print "%s %s" % (caller,caller.get_active()) printPretty(config) backends.saveConfig(config.get("file","default.cfg"))
def seek(fn): NORM = '\033[0;37;40m' # normal gray SCOL = '\033[80C\033[12D\033[32;40m' # green FCOL = '\033[80C\033[12D\033[31;40m' # red if not config.get("termcolors",False): NORM = " " SCOL = " " FCOL = " " if os.path.exists(fn): return "%sFound%s" % (SCOL,NORM) else: return "%sNot Found!%s" % (FCOL,NORM)
def loadConfig(fn = None,recursion = 0): """Returns a dict containing the config options in the Minette config file.""" maxrecursion = 3 lines = [] global config global defaults if fn is None: fn = "default.cfg" # using 3-letter extension for MSWin compatibility, I hope. (found,fn) = findFile(lineno(),fn) if not found: print " [W] Config %s not loaded." % fn if not defaults.get("set",False): setDefaults() config.update(defaults) return config lines = readfile(fn) for line in lines: try: line = line.strip() if line: values = [x.strip() for x in line.split('=')] if values[0] != "loadconfig": if not config.get(values[0]): config[values[0]] = values[1] # existing options will not be clobbered elif recursion < maxrecursion and os.path.exists(values[1]): # loadconfig must be first option, or its options may be ignored. recursion += 1 loadConfig(values[1],recursion) except Exception as e: print " [E] There was an error in the configuration file: %s" % e config['file'] = fn config = validateConfig(config) config['realmfile'] = "" if len(config.get("loadrealm","")) > 0 and recursion <= maxrecursion: rf = "realms/%s.rlm" % config['loadrealm'] realm = loadRealm(rf) config.update(realm) else: config['realmloaded'] = False config.update(criticalDefaults()) return config
def storeWindow(caller,window): """Checks current window size against stored value in memory. If different, Checks for the existence of the config file, and if it exists, deletes old window definitions and writes a new set. Requires window argument specifying widget to read size/location info. """ global config if config.get("nowindowstore"): return # Allow config option to disable this behavior (x, y) = window.get_position() (w, h) = window.get_size() if config['pos'] == (x,y) and config['size'] == (w,h): if config['debug'] > 0: print "Window not moved/resized. Keeping existing values." return lines = [] found = [] if os.path.exists(os.path.abspath(config['file'])): # Don't create a config file if it doesn't exist. try: with codecs.open(os.path.abspath(config['file']),'rU','utf-8') as conf: lines = conf.readlines() conf.close() except IOError as e: print " Could not read configuration file: %s" % e return if config['debug'] > 3: print str(lines) + "\n" i = 0 for line in lines: line = line.strip() if line: values = [a.strip() for a in line.split('=')] if values[0] in ["pos","size"]: found.append(i) i += 1 if len(found): found.sort() found.reverse() for i in found: del lines[i] lines.append("pos = (%s,%s)\n" % (x,y)) lines.append("size = (%s,%s)\n" % (w,h)) if config['debug'] > 3: print lines try: f = open(os.path.abspath(config['file']), 'w') f.writelines(lines) f.close() except IOError as e: print " Could not write configuration file: %s" % e return print "Saving window: %s,%s; %sx%s" % (x,y,w,h) else: print "No config file. Not saving window."
def setStories(caller,data,fileid,x,parent): name = getInf(data,["info","commonname"]) cat = data.get("cat") value = "" if config.get('showstories') == "titlelist": value = getInf(data,["info","stories"]) else: value = x.get_text() value = story.storyPicker(parent,name,value) if value: if cat == 'p': global people if preRead(False,cat,[fileid,"info","stories"],3): people[fileid]['info']['stories'] = [value,True] people[fileid]['changed'] = True elif cat == 'l': global places if preRead(False,cat,[fileid,"info","stories"],3): places[fileid]['info']['stories'] = [value,True] places[fileid]['changed'] = True if config.get('showstories') == "titlelist": value = expandTitles(value) x.set_text(value)
def __init__(self,configfile): global status global config global mainWin global menuBar self.window = mainWin common.updateTitle() self.window.connect("delete_event", self.delete_event) self.window.connect("destroy", self.destroy) self.window.set_border_width(3) self.window.show() if not config.get("nowindowstore"): self.window.set_geometry_hints(None,config['size'][0],config['size'][1]) self.window.move(config['pos'][0],config['pos'][1]) mainWin = self.window self.box1 = gtk.VBox() self.window.add(self.box1) self.box1.show() self.tabs = gtk.Notebook() self.tabs.set_scrollable(True) if not config.get("seenfirstrun"): menu.firstRunTab(self,self.tabs) self.accgroup = gtk.AccelGroup() # for use on menus self.window.add_accel_group(self.accgroup) Base.makeMenus(self) self.box1.add(menuBar) self.box1.add(self.tabs) self.tabs.show() # self.menu1.connect("clicked", self.hello, None) # self.menu1.connect_object("clicked", gtk.Widget.destroy, self.window) status.set_border_width(2) status.show() self.box1.add(status) self.box1.set_child_packing(status,0,0,0,gtk.PACK_START) self.box1.set_child_packing(self.tabs,1,1,0,gtk.PACK_START) self.box1.set_child_packing(menuBar,0,0,0,gtk.PACK_START) # self.button1.set_border_width(2) menuBar.show()
def expandTitles(value): global stories titles = "" if not len(str(value)): return titles picklist = csplit(str(value)) if not len(stories): stories = myStories(config.get("realmdir")) for item in picklist: if config['debug'] > 5: print "'%s' - '%s'" % (item,stories.get(item)) if stories.get(item): titles += "%s\n" % stories[item] else: titles += "\'%s\'\n" % item titles = titles[:-1] # trim that last newline return titles
def validateConfig(config): """Checks some config values for validity. Returns adjusted dictionary.""" try: if not defaults.get("set",False): setDefaults() except NameError: setDefaults() keylist = [] keylist.extend(cfgkeys) if config.get("rlmincfg",False): keylist.extend(rlmkeys) for key in keylist: config[key] = config.get(key,defaults[key]) if config[key] == "True": config[key] = True if config[key] == "False": config[key] = False pos = config.get("pos",defaults['pos']) # default position siz = config.get("size",defaults['size']) # default size pattern = re.compile(r'\(\s?(\d+)\s?,\s?(\d+)\s?\)') match = False if pos == str(pos): # otherwise, must be reloading config, no need to reprocess match = pattern.search(pos) if match: config['pos'] = (int(match.group(1)),int(match.group(2))) else: config['pos'] = (0,0) match = False if siz == str(siz): # otherwise, must be reloading config, no need to reprocess match = pattern.search(siz) if match: config['size'] = (int(match.group(1)),int(match.group(2))) else: config['size'] = (620,440) keys = ["debug","matchlike",] for k in keys: config[k] = int(config.get(k,0)) return config
def buildarow(scroll,name,data,fileid,key,ar,alts,**kwargs): """Returns a row containing the given key description and value in a GTK HBox.""" style = 0 tiptext = None for kw in kwargs: if config['debug'] > 3: print "%s:%s" % (kw,kwargs[kw]) if kw == "style": style = kwargs[kw] if kw == "tooltip": tiptext = kwargs[kw] row = gtk.HBox() row.set_border_width(2) row.show() if tiptext: row.set_tooltip_text(tiptext) row.label = gtk.Label(name) row.label.set_width_chars(20) valign = 0.5 if style == 0 or style == 3: value = getInf(data,["info",key]) row.e = gtk.Entry() row.e.set_text(value) activateInfoEntry(row.e,ar,alts,scroll,data,fileid,key) if style == 1: valign = 0.03 row.e = buildaposition(scroll,data,fileid,key,ar,alts) if style == 2: value = getInf(data,["info",key]) row.e = gtk.Label() if config.get('showstories') == "titlelist": valign = 0.03 if len(str(value)): row.e.set_text(expandTitles(value)) else: # elif config['showstories'] == "idlist": row.e.set_text(value) stbut = gtk.Button("Set") stbut.show() stbut.connect("clicked",setStories,data,fileid,row.e,None) row.pack_end(stbut,False,False,2) row.e.set_alignment(0.05,0) row.label.set_alignment(1,valign) row.label.show() row.pack_start(row.label,0,0,2) row.e.show() row.pack_start(row.e,1,1,2) if style == 3: path = [fileid,"info",key] placeCalendarButton(data,row,row.e,path,alts,counter=ar) return row
def validateRealm(realm): for key in realm.keys(): if key not in rlmkeys: # Only allow keys in the realm-specific keys list del realm[key] for key in rlmkeys: # XML file options if key == "dtdurl": realm['dtdurl'] = realm.get("dtddir",os.path.join("../../",realm['dtddir'])) # other options else: realm[key] = realm.get(key,defaults[key]) if realm[key] == "True": realm[key] = True if realm[key] == "False": realm[key] = False if not os.path.exists(os.path.abspath(realm['realmdir'])): # must be a valid directory if not config.get("makerd",False): bsay("?","Fatal error. Realm directory %s does not exist! Exiting." % os.path.abspath(realm['realmdir'])) exit(-1) else: print "Stupid programmer: Function missing! Write function to create realmdir!" exit(-1) return realm
def setDate(cal,target): (y,m,d) = cal.get_date() t = (y,m,d,0,0,0,0,0,0) style = config.get('datestyle',"%Y/%m/%db") if True: style = re.sub(r'%y',r'%Y',style) target.set_text(time.strftime(style,t))
def optionSetter(caller,parent = "?",canskip = True): global config global status options = {} factor = 0.80 if parent == "?": parent = mainWin print "parent: %s" % parent title = "Setting Options" optbox = gtk.Dialog(title,parent,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_APPLY,gtk.RESPONSE_APPLY,gtk.STOCK_OK,gtk.RESPONSE_OK)) if not canskip: optbox.get_action_area().get_children()[2].set_sensitive(False) # buttons seem to number right to left applyBut = optbox.get_action_area().get_children()[1] applyBut.set_sensitive(False) # optbox.get_action_area().get_children()[0].set_sensitive(False) if not config.get("nowindowstore"): optbox.set_geometry_hints(None,int(config['size'][0] * factor),int(config['size'][1] * (factor - 0.05))) # optbox.set_decorated(False) sw = gtk.VBox() sw.show() sw.set_border_width(10) scroll = gtk.ScrolledWindow() scroll.show() scroll.set_policy(gtk.POLICY_NEVER,gtk.POLICY_AUTOMATIC) scroll.add_with_viewport(sw) optbox.vbox.add(scroll) rf = config['realmfile'] if rf == "": rf = "<unspecified>" label = gtk.Label("Realm-specific Options for %s" % rf) label.show() sw.pack_start(label,False,False,7) row = gtk.HBox() label = gtk.Label("Name of this realm/setting/world: ") e = gtk.Entry() e.show() e.set_text(config.get("realmname","Unnamed Realm")) optbox.set_title("Setting Options - %s" % e.get_text()) e.connect("changed",setOpt,None,options,"realmname",2) e.connect("changed",mayApply,applyBut) e.connect("focus-in-event",scrollOnTab,scroll) row.show() label.show() row.pack_start(label,False,False,2) row.pack_start(e,True,True,2) sw.pack_start(row) row = gtk.HBox() label = gtk.Label("Realm Directory: ") e = gtk.Entry() e.show() e.set_text(config.get("realmdir","")) e.connect("changed",setOpt,None,options,"realmdir",2) e.connect("changed",mayApply,applyBut) e.connect("focus-in-event",scrollOnTab,scroll) row.show() label.show() row.pack_start(label,False,False,2) row.pack_start(e,True,True,2) sw.pack_start(row) cb = gtk.CheckButton("Family name comes first (Eastern style names)") cb.set_active(config.get("familyfirst",False)) cb.connect("toggled",setOpt,None,options,"familyfirst",1) cb.connect("toggled",mayApply,applyBut) cb.connect("focus-in-event",scrollOnTab,scroll) cb.show() sw.pack_start(cb) cb = gtk.CheckButton("Use middle/maiden names") cb.set_active(config.get("usemiddle",True)) cb.connect("toggled",setOpt,None,options,"usemiddle",1) cb.connect("toggled",mayApply,applyBut) cb.connect("focus-in-event",scrollOnTab,scroll) cb.show() sw.pack_start(cb) sqlbox = gtk.Frame("SQL Options") xmlbox = gtk.Frame("XML Options") formats = ["xml","sql"] forms = [("informat","Input format"),("outformat","Output format")] for key in forms: label = key[1] key = key[0] group = None row = gtk.HBox() row.show() label = gtk.Label("%s:" % label) label.show() row.pack_start(label,False,False,2) c = gtk.combo_box_new_text() selected = -1 options[key] = config.get(key,"xml") i = 0 for f in formats: if f == options.get(key): selected = i c.append_text(f) i += 1 c.set_active(selected) c.connect("changed",setOpt,None,options,key,3) c.connect("changed",mayApply,applyBut) c.connect("changed",toggleBoxes,None,sqlbox,xmlbox,options) c.connect("move-active",setOpt,options,key,3) c.connect("move-active",toggleBoxes,sqlbox,xmlbox,options) c.connect("focus",scrollOnTab,scroll) c.connect("focus-in-event",scrollOnTab,scroll) c.show() row.pack_start(c,False,False,2) sw.pack_start(row) sw.pack_start(sqlbox) sw.pack_start(xmlbox) toggleBoxes(None,None,sqlbox,xmlbox,options) xb = gtk.VBox() xb.show() xmlbox.add(xb) sb = gtk.VBox() sb.show() sqlbox.add(sb) ####### SQL box options label = gtk.Label("SQL input/output is not yet implemented.\nPlease use XML for the time being.") label.show() sb.pack_start(label) ####### XML box options cb = gtk.CheckButton("Include empty tags when saving XML files") cb.set_active(config.get("printemptyXMLtags",False)) cb.connect("toggled",setOpt,None,options,"printemptyXMLtags",1) cb.connect("toggled",mayApply,applyBut) cb.connect("focus-in-event",scrollOnTab,scroll) cb.show() xb.pack_start(cb) row = gtk.HBox() label = gtk.Label("DTDs are found in this directory: ") e = gtk.Entry() e.show() e.set_text(config.get("dtddir","")) e.connect("changed",setOpt,None,options,"dtddir",2) e.connect("changed",mayApply,applyBut) e.connect("focus-in-event",scrollOnTab,scroll) row.show() label.show() row.pack_start(label,False,False,2) row.pack_start(e,True,True,2) xb.pack_start(row) row = gtk.HBox() label = gtk.Label("URL for DTD in XML files: ") e = gtk.Entry() e.show() e.set_text(config.get("dtdurl","")) e.connect("changed",setOpt,None,options,"dtdurl",2) e.connect("changed",mayApply,applyBut) e.connect("focus-in-event",scrollOnTab,scroll) row.show() label.show() row.pack_start(label,False,False,2) row.pack_start(e,True,True,2) xb.pack_start(row) row = gtk.HBox() label = gtk.Label("URL for XSL files in XML: ") e = gtk.Entry() e.show() e.set_text(config.get("xslurl","")) e.connect("changed",setOpt,None,options,"xslurl",2) e.connect("changed",mayApply,applyBut) e.connect("focus-in-event",scrollOnTab,scroll) row.show() label.show() row.pack_start(label,False,False,2) row.pack_start(e,True,True,2) xb.pack_start(row) row = gtk.HBox() label = gtk.Label("Century assumed for 2-digit years: ") test = gtk.Label("Test dates:") test.show() a = gtk.Adjustment(int(config.get("century",1900)/100),-499,500) s1 = gtk.SpinButton(a,1.0,0) s1.set_increments(1,10) s1.show() s1.connect("value-changed",setOpt,None,options,"century",5) s1.connect("value-changed",mayApply,applyBut) s1.connect("focus-in-event",scrollOnTab,scroll) row.show() label.show() row.pack_start(label,False,False,2) row.pack_start(s1,False,False,2) label = gtk.Label("Split year: ") label.show() a = gtk.Adjustment(int(config.get("centbreak",77)),0,99) s2 = gtk.SpinButton(a,1.0,0) s2.set_increments(1,10) s2.show() s2.connect("value-changed",setOpt,None,options,"centbreak",4) s2.connect("value-changed",mayApply,applyBut) s2.connect("focus-in-event",scrollOnTab,scroll) row.pack_start(label,False,False,2) row.pack_start(s2,True,True,2) setDates(None,s1,s2,test) s2.connect("value-changed",setDates,s1,s2,test) s1.connect("value-changed",setDates,s1,s2,test) sw.pack_start(row) sw.pack_start(test,True,True,2) cb = gtk.CheckButton("Show only calculated date") cb.set_active(config.get("hideage",True)) cb.connect("toggled",setOpt,None,options,"hideage",1) cb.connect("toggled",mayApply,applyBut) cb.connect("focus-in-event",scrollOnTab,scroll) cb.show() sw.pack_start(cb) row = gtk.HBox() label = gtk.Label("Date for age calculations: ") label.show() e = gtk.Entry() e.set_text(config.get("agedate","06/08/10b")) e.connect("changed",setOpt,None,options,"agedate",2) e.connect("changed",mayApply,applyBut) e.show() row.show() row.pack_start(label,0,0,2) row.pack_start(e,1,1,2) placeCalendarButton(None,row,e,None,[],nomark=True) sw.pack_start(row,0,0,2) row = gtk.HBox() label = gtk.Label("Expert: Style for dates in this realm: ") e = gtk.Entry() e.show() e.set_text(config.get("datestyle","%y/%m/%db")) e.connect("changed",setOpt,None,options,"datestyle",2) e.connect("changed",mayApply,applyBut) e.connect("focus-in-event",scrollOnTab,scroll) row.show() label.show() row.pack_start(label,False,False,2) row.pack_start(e,True,True,2) sw.pack_start(row) row = gtk.HBox() label = gtk.Label("Background color for a changed field: ") e = gtk.Entry() e.show() e.set_text(config.get("altcolor","#FFFFFF")) e.connect("changed",setOpt,None,options,"altcolor",2) e.connect("changed",mayApply,applyBut) e.connect("changed",setBack,e,gtk.STATE_NORMAL) setBack(None,e,gtk.STATE_NORMAL) e.connect("focus-in-event",scrollOnTab,scroll) b = gtk.Button("Choose Color") b.connect("clicked",selColor,e) b.show() row.show() label.show() row.pack_start(label,False,False,2) row.pack_start(e,True,True,2) row.pack_start(b,False,False,2) sw.pack_start(row) row = gtk.HBox() label = gtk.Label("Background color for a changed field after save: ") e = gtk.Entry() e.show() e.set_text(config.get("savecolor","#FFFFFF")) e.connect("changed",setOpt,None,options,"savecolor",2) e.connect("changed",mayApply,applyBut) e.connect("changed",setBack,e,gtk.STATE_NORMAL) setBack(None,e,gtk.STATE_NORMAL) e.connect("focus-in-event",scrollOnTab,scroll) b = gtk.Button("Choose Color") b.connect("clicked",selColor,e) b.show() row.show() label.show() row.pack_start(label,False,False,2) row.pack_start(e,True,True,2) row.pack_start(b,False,False,2) sw.pack_start(row) cb = gtk.CheckButton("Use list files for this realm") cb.set_active(config.get("uselistfile",True)) cb.connect("toggled",setOpt,None,options,"uselistfile",1) cb.connect("toggled",mayApply,applyBut) cb.connect("focus-in-event",scrollOnTab,scroll) cb.show() sw.pack_start(cb) cb = gtk.CheckButton("Use only realm-defined relationships, not free text") cb.set_active(config.get("specialrelsonly",True)) cb.connect("toggled",setOpt,None,options,"specialrelsonly",1) cb.connect("toggled",mayApply,applyBut) cb.connect("focus-in-event",scrollOnTab,scroll) cb.show() sw.pack_start(cb) row = gtk.HBox() row.show() label = gtk.Label("Story List Format:") label.show() row.pack_start(label,False,False,2) c = gtk.combo_box_new_text() selected = -1 options["showstories"] = config.get("showstories","idlist") i = 0 formats = ["idlist","titlelist"] for f in formats: if f == options.get("showstories"): selected = i c.append_text(f) i += 1 c.set_active(selected) c.connect("changed",setOpt,None,options,"showstories",3) c.connect("changed",mayApply,applyBut) c.connect("move-active",setOpt,options,"showstories",3) c.connect("move-active",mayApply,applyBut) c.connect("focus",scrollOnTab,scroll) c.connect("focus-in-event",scrollOnTab,scroll) c.show() row.pack_start(c,False,False,2) sw.pack_start(row) cb = gtk.CheckButton("If only one story, set default Story List value") cb.set_active(config.get("defaultstory",True)) cb.connect("toggled",setOpt,None,options,"defaultstory",1) cb.connect("toggled",mayApply,applyBut) cb.connect("focus-in-event",scrollOnTab,scroll) cb.show() sw.pack_start(cb) ####### >>>>>>> label = gtk.Label("Program-wide Options") label.show() sw.pack_start(label,False,False,7) cb = gtk.CheckButton("Don't store window size/position") cb.set_active(config.get("nowindowstore",False)) cb.connect("toggled",setOpt,None,options,"nowindowstore",1) cb.connect("toggled",mayApply,applyBut) cb.connect("focus-in-event",scrollOnTab,scroll) cb.show() sw.pack_start(cb) cb = gtk.CheckButton("Accept realm-specific options in the config file") cb.set_active(config.get("rlmincfg",False)) cb.connect("toggled",setOpt,None,options,"rlmincfg",1) cb.connect("toggled",mayApply,applyBut) cb.connect("focus-in-event",scrollOnTab,scroll) cb.show() sw.pack_start(cb) cb = gtk.CheckButton("Opening a new person file at startup") cb.set_active(config.get("startnewperson",False)) cb.connect("toggled",setOpt,None,options,"startnewperson",1) cb.connect("toggled",mayApply,applyBut) cb.connect("focus-in-event",scrollOnTab,scroll) cb.show() sw.pack_start(cb) cb = gtk.CheckButton("Allow opening duplicate tabs") cb.set_active(config.get("duplicatetabs",False)) cb.connect("toggled",setOpt,None,options,"duplicatetabs",1) cb.connect("toggled",mayApply,applyBut) cb.connect("focus-in-event",scrollOnTab,scroll) cb.show() sw.pack_start(cb) cb = gtk.CheckButton("Save the active realm file on exit") cb.set_active(config.get("saverealm",False)) cb.connect("toggled",setOpt,None,options,"saverealm",1) cb.connect("toggled",mayApply,applyBut) cb.connect("focus-in-event",scrollOnTab,scroll) cb.show() sw.pack_start(cb) row = gtk.HBox() row.show() label = gtk.Label("Load this realm automatically:") label.show() row.pack_start(label,False,False,2) d = gtk.Label() d.set_text(config.get("loadrealm","")) d.show() row.pack_start(d,True,True,2) but = gtk.Button("Select Realm") but.connect("clicked",chooseRealm,d,options) but.connect("clicked",mayApply,applyBut) but.show() row.pack_start(but,False,False,2) sw.pack_start(row) row = gtk.HBox() row.show() label = gtk.Label("Likerealm handling:") label.show() row.pack_start(label,False,False,2) c = gtk.combo_box_new_text() selected = -1 options["matchlike"] = config.get("matchlike",2) i = 0 formats = ["Keep likerealm and track which options are from where","Keep likerealm and save only options that differ","Save all options and omit likerealm"] for f in formats: if i == options.get("matchlike"): selected = i c.append_text(f) i += 1 if selected != -1: c.set_active(selected) c.connect("changed",setOpt,None,options,"matchlike",1) c.connect("changed",mayApply,applyBut) c.connect("move-active",setOpt,options,"matchlike",1) c.connect("move-active",mayApply,applyBut) c.connect("focus",scrollOnTab,scroll) c.connect("focus-in-event",scrollOnTab,scroll) c.show() row.pack_start(c,False,False,2) sw.pack_start(row) resp = 0 while resp not in [-6,-5]: resp = optbox.run() if resp == -10: t = "Options applied." print t status.push(0,t) copyOpts(options) if options.get("realmname") is not None: updateTitle() options = {} optbox.set_title("Setting Options - %s" % config.get("realmname","Unnamed Realm")) applyBut.set_sensitive(False) if resp == -6: t = "Cancelled" print t status.push(0,t) optbox.destroy() return elif resp == -5: t = "Options accepted." print t status.push(0,t) optbox.destroy() copyOpts(options) if options.get("realmname") is not None: updateTitle() # saveConfig() # saveRealm() return
def updateTitle(): global mainWin t = mainWin.get_title() r = config.get("realmname",None) if t != "Minette - %s" % r and r is not None: mainWin.set_title("Minette - %s" % config.get("realmname"))
def killRealmOpts(): for k in rlmkeys: del config[k] loadConfig(config.get("file",None),9)