On Thu, Oct 04, 2012 at 04:27:27PM +0200, Michele Gatti wrote:
> Il giorno 04 ottobre 2012 16:12, Vittorio Spina
> <[email protected]>ha scritto:
> > Il 04/10/2012 15:57, Michele Gatti ha scritto:
> > Il giorno 04 ottobre 2012 15:17, Vittorio Spina
> > <[email protected]>ha scritto:
> >> quasi, mi ci vorrebbe un programma grafico che fa il writing e poi io
> >> penso al reading.
> >> Perchè il problema è che un cliente dovrebbe farsi la configurazione da
> >> solo...
> >> Non so se mi spiego
> >> V.
> >>
> >> Il 04/10/2012 15:12, Daniele Varrazzo ha scritto:
> >>
> >> On 2012-10-04 14:03, Vittorio Spina wrote:
> >>>
> >>> in generale sviluppo applicazioni che sono configurabili da files txt
> >>>> in modo che dopo la compilazione con py2exe, sia possibile modificare
> >>>> alcune impostazioni senza dover "ricompilare".
> >>>> Per questo ho sviluppato una classe che prende un file txt e lo
> >>>> interpreta secondo una sintassi definita.
> >>>>
> >>>
> >>> Perché, questo non andava bene?
> >>> http://docs.python.org/library/configparser.html
> > e' lo so, ma è la meno elegante.
> > mi sarebbe piaciuto un programma grafico tipo qtstyle con i campi da
> > inserire...
> > sarebbe stato più figo, e una volta generalizzato l'avrei utilizzato per
> > tutti le app che scrivo...
> > mi sa che devo pianificare il parto...
> > grazie comunque
> > v.
> >
> Come mi hanno sempre risposto, l'eleganza a volte andrebbe messa da parte
> per la praticità, poi vedi tu.
forse ma non mi sembra molto impraticabile una cosa simile (vedi
allegati). è molto grezzo ma rende l'idea credo e inoltre puoi
sbizzarrirti un po' ed arrivare ad una cosa di ben altro livello:
class MySection:
a = Int()
b = Float(default=3.14)
app.add_section(ISection(MySection))
m.
"""
usage: python guiconfig.py [[file] ...]
"""
from __future__ import print_function
import sys
import getopt
import ConfigParser
from gi.repository import Gtk
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
class Application:
def __init__(self, config_parser):
self.config_parser = config_parser
def add_section(self, section):
box = Gtk.Box(spacing=5)
box.set_orientation(Gtk.Orientation.VERTICAL)
for option in self.config_parser.options(section):
hbox = Gtk.Box(spacing=5)
label = Gtk.Label(option)
entry = Gtk.Entry()
entry.set_text(self.config_parser.get(section, option))
hbox.pack_start(label, False, False, 5)
hbox.pack_start(entry, True, True, 0)
box.pack_start(hbox, False, False, 0)
self.notebook.append_page(box, Gtk.Label(section))
def run(self):
self.main_window = Gtk.Window()
self.main_window.connect("delete-event", Gtk.main_quit)
self.notebook = Gtk.Notebook()
self.main_window.add(self.notebook)
for section in self.config_parser.sections():
self.add_section(section)
self.main_window.show_all()
Gtk.main()
def main(args=None):
if args is None:
args = sys.argv[1:]
try:
try:
opts, files = getopt.getopt(args, "h", ["help"])
except getopt.error, msg:
raise Usage(msg)
for o, a in opts:
if o in ("h", "help"):
print(__doc__)
return 0
try:
parser = ConfigParser.RawConfigParser()
parser.read(args)
app = Application(parser)
app.run()
return 0
except ConfigParser.Error, err:
print("Error while parsing", file=sys.stderr)
print(err, file=sys.stderr)
return 1
except Exception, err:
print(err, file=sys.stderr)
return 1
except Usage, err:
print(err.msg, file=sys.stderr)
print("for help use --help", file=sys.stderr)
return 2
if __name__ == "__main__":
sys.exit(main())
[Section1]
int = 15
bool = true
float = 3.1415
baz = fun
bar = Python
foo = %(bar) is %(baz)
[Section2]
baz = fun
bar = Python
foo = %(bar) is %(baz)
[Section3]
int = 15
bool = true
float = 3.1415
_______________________________________________
Python mailing list
[email protected]
http://lists.python.it/mailman/listinfo/python