Line 7... |
Line 7... |
import re
|
import re
|
|
|
import sys
|
import sys
|
import os.path
|
import os.path
|
|
|
|
INSTANCES = []
|
|
|
class ConfigFile:
|
class ConfigFile:
|
|
|
def __init__(self, filename):
|
def __init__(self, filename):
|
|
|
self.filename = filename
|
self.filename = filename
|
Line 220... |
Line 222... |
|
|
class ConfigWindow(gtk.Window):
|
class ConfigWindow(gtk.Window):
|
|
|
def __init__(self, cfgfilename = None):
|
def __init__(self, cfgfilename = None):
|
|
|
|
INSTANCES.append(self)
|
|
|
gtk.Window.__init__(self)
|
gtk.Window.__init__(self)
|
|
|
self.set_title("Configurator")
|
self.set_title("Configurator")
|
self.set_default_size(400, 600)
|
self.set_default_size(400, 600)
|
|
|
self.box = gtk.VBox()
|
self.box = gtk.VBox()
|
self.button = gtk.Button("Save")
|
|
self.notebook = gtk.Notebook()
|
self.notebook = gtk.Notebook()
|
|
self.toolbar = ConfigToolbar(self)
|
|
|
self.add(self.box)
|
self.add(self.box)
|
|
|
|
self.box.pack_start(self.toolbar, False)
|
self.box.pack_start(self.notebook, True)
|
self.box.pack_start(self.notebook, True)
|
self.box.pack_start(self.button, False)
|
|
|
|
self.button.connect('clicked', lambda b: self.save())
|
|
|
|
if cfgfilename is not None:
|
if cfgfilename is not None:
|
self.load(ConfigFile(cfgfilename))
|
self.load(cfgfilename)
|
|
else:
|
|
self.configfile = None
|
|
|
|
self.connect("delete_event", self.close)
|
|
self.show_all()
|
|
|
|
|
def load(self, cfg):
|
def load(self, cfgfilename):
|
|
|
|
cfg = ConfigFile(cfgfilename)
|
|
|
self.set_title(cfg.title + " - Configurator")
|
self.set_title(cfg.title + " - Configurator")
|
|
|
self.configfile = cfg
|
self.configfile = cfg
|
|
|
Line 264... |
Line 273... |
def save(self):
|
def save(self):
|
|
|
self.configfile.save()
|
self.configfile.save()
|
|
|
|
|
def run(self):
|
def close(self, *args):
|
|
|
|
# Maybe check if file modified and ask to save it?
|
|
|
def ondel(win, *args):
|
INSTANCES.remove(self)
|
|
self.destroy();
|
|
|
|
if len(INSTANCES) == 0:
|
gtk.main_quit()
|
gtk.main_quit()
|
win.hide()
|
|
return True
|
|
|
|
handler_id = self.connect("delete_event", ondel)
|
|
|
|
gtk.main()
|
|
|
|
self.disconnect(handler_id)
|
class ConfigToolbar(gtk.Toolbar):
|
|
|
|
def __init__(self, cfg):
|
|
|
|
self.cfg = cfg
|
|
|
|
gtk.Toolbar.__init__(self)
|
|
|
|
self.insert_stock(gtk.STOCK_OPEN, "Open a file", None, self.open, None, -1)
|
|
self.insert_stock(gtk.STOCK_SAVE, "Save the current file", None, self.save, None, -1)
|
|
self.insert_stock(gtk.STOCK_CLOSE, "Close the current file", None, self.close, None, -1)
|
|
|
|
|
|
def open(self, *args):
|
|
|
|
chooser = gtk.FileChooserDialog(
|
|
"Open file...", None,
|
|
gtk.FILE_CHOOSER_ACTION_OPEN, (
|
|
gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
|
gtk.STOCK_OPEN, gtk.RESPONSE_OK
|
|
))
|
|
|
|
if chooser.run() != gtk.RESPONSE_OK:
|
|
return
|
|
|
|
filename = chooser.get_filename()
|
|
|
|
chooser.destroy()
|
|
|
|
if self.cfg.configfile is None:
|
|
self.cfg.load(filename)
|
|
else:
|
|
ConfigWindow(filename)
|
|
|
|
|
|
def save(self, *args):
|
|
self.cfg.save()
|
|
|
|
def close(self, *args):
|
|
self.cfg.close()
|
|
|
|
|
if __name__ == '__main__':
|
if __name__ == '__main__':
|
ConfigWindow(sys.argv[1]).run()
|
|
|
if len(sys.argv) == 1:
|
|
ConfigWindow()
|
|
|
|
for f in sys.argv[1:]:
|
|
ConfigWindow(f)
|
|
|
|
gtk.main()
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|