diff --git a/in-gen-glade/in-gen-glade.glade b/in-gen-glade/in-gen-glade.glade new file mode 100644 index 0000000..a6e7207 --- /dev/null +++ b/in-gen-glade/in-gen-glade.glade @@ -0,0 +1,333 @@ + + + + + + + 216 + True + Invoice Number Generator + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + False + + + + + + 10 + True + False + 15 + + + + True + True + GTK_POLICY_NEVER + GTK_POLICY_NEVER + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + 4 + 24 + True + True + False + False + False + GTK_JUSTIFY_CENTER + GTK_WRAP_NONE + False + 0 + 0 + 0 + 0 + 0 + 0 + Generated Number: + + + + + 0 + True + False + + + + + + 72 + True + True + GTK_POLICY_NEVER + GTK_POLICY_NEVER + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + False + False + GTK_JUSTIFY_CENTER + GTK_WRAP_NONE + False + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0 + True + True + + + + + + True + False + 0 + + + + True + True + GTK_POLICY_NEVER + GTK_POLICY_NEVER + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + False + True + GTK_JUSTIFY_CENTER + GTK_WRAP_WORD + False + 0 + 0 + 0 + 0 + 0 + 0 + If you used the generated number, then click Yes below. + + + + + 0 + True + True + + + + + + 9 + True + True + 37 + + + + True + True + GTK_RELIEF_NORMAL + True + + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-apply + 5 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + Yes, this number +has been used. + True + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + + + + 0 + False + False + + + + + + True + True + GTK_RELIEF_NORMAL + True + + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-cancel + 5 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + No, this button +has not been used. + True + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + + + + 0 + False + False + + + + + 0 + True + True + + + + + 0 + True + False + + + + + + + diff --git a/in-gen-glade/in-gen-glade.glade.bak b/in-gen-glade/in-gen-glade.glade.bak new file mode 100644 index 0000000..c1ec21a --- /dev/null +++ b/in-gen-glade/in-gen-glade.glade.bak @@ -0,0 +1,332 @@ + + + + + + + 216 + True + Invoice Number Generator + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + False + + + + + 10 + True + False + 15 + + + + True + True + GTK_POLICY_NEVER + GTK_POLICY_NEVER + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + 4 + 24 + True + True + False + False + False + GTK_JUSTIFY_CENTER + GTK_WRAP_NONE + False + 0 + 0 + 0 + 0 + 0 + 0 + Generated Number: + + + + + 0 + True + False + + + + + + 72 + True + True + GTK_POLICY_NEVER + GTK_POLICY_NEVER + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + False + False + GTK_JUSTIFY_CENTER + GTK_WRAP_NONE + False + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 0 + True + True + + + + + + True + False + 0 + + + + True + True + GTK_POLICY_NEVER + GTK_POLICY_NEVER + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + False + True + GTK_JUSTIFY_CENTER + GTK_WRAP_WORD + False + 0 + 0 + 0 + 0 + 0 + 0 + If you used the generated number, then click Yes below. + + + + + 0 + True + True + + + + + + 9 + True + True + 37 + + + + True + True + GTK_RELIEF_NORMAL + True + + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-apply + 5 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + Yes, this number +has been used. + True + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + + + + 0 + False + False + + + + + + True + True + GTK_RELIEF_NORMAL + True + + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-cancel + 5 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + No, this button +has not been used. + True + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + + + + 0 + False + False + + + + + 0 + True + True + + + + + 0 + True + False + + + + + + + diff --git a/in-gen-glade/in-gen-glade.gladep b/in-gen-glade/in-gen-glade.gladep new file mode 100644 index 0000000..0c87a36 --- /dev/null +++ b/in-gen-glade/in-gen-glade.gladep @@ -0,0 +1,8 @@ + + + + + In-gen-glade + in-gen-glade + FALSE + diff --git a/in-gen-glade/in-gen-glade.gladep.bak b/in-gen-glade/in-gen-glade.gladep.bak new file mode 100644 index 0000000..0c87a36 --- /dev/null +++ b/in-gen-glade/in-gen-glade.gladep.bak @@ -0,0 +1,8 @@ + + + + + In-gen-glade + in-gen-glade + FALSE + diff --git a/in-gen.conf.example b/in-gen.conf.example new file mode 100644 index 0000000..9950953 --- /dev/null +++ b/in-gen.conf.example @@ -0,0 +1,10 @@ +[Main] + +[Handrechnung] +prefix = hr-02006 +suffix = "" +#last used number +lastnumber = 12 + + +[Webshop] \ No newline at end of file diff --git a/in-gen.py b/in-gen.py new file mode 100644 index 0000000..b5d313f --- /dev/null +++ b/in-gen.py @@ -0,0 +1,160 @@ +#!/usr/bin/env python + +import os +import sys + +try: + import pygtk + pygtk.require("2.0") #wir wollen gtkv2 nutzen + #print "pygtk importiert" +except: + print "couldn't import 'pygtk'! Try 'apt-get install python-gtk2'." + sys.exit(1) + +try: + import gtk + import gtk.glade + #print "gtk.glade importiert" +except: + print "Mit GTKv2 kannst du den Schlafenden wecken!" + sys.exit(1) + + +try: + import configobj ## needed for reading and writing of the config file +except: + print "couldn't import 'configobj'! Try 'apt-get install python-configobj'." + sys.exit(1) + +############################ CONFIG FILE ########################## + +class SettingsClass(configobj.ConfigObj): + """ a class for handling the config file(s) using configobj""" + + CONF_LOCATIONS = [ + "./in-gen.conf", + "~/.in-gen.conf", + ] + + def __init__(self, config_file=None): + config_file = self.__getConfigFileName(config_file) + self.prefs = self.__getPreferences(config_file) + #TODO: a proper ConfigObj instance knows these variables, read them automatically! + + + def __getitem__(self, key): + """redirect all requests to the 'prefs' attribute""" + return self.prefs[key] + + def __getPreferences(self, config_file): + """read the config file and return a configobj object.""" + try: + prefs = configobj.ConfigObj(config_file) + if prefs: + pass + else: + raise "failed to load the config file: %s" % config_file + except IOError: + raise "unable to open the config file: %s" % config_file + return prefs + + + def __getConfigFileName(self, config_file): + # search for the configuration file + import types + if config_file is None: + # no config file was specified - we will look for it in the ususal locations + conf_file_list = [os.path.expanduser(f) + for f in self.CONF_LOCATIONS + if os.path.exists(os.path.expanduser(f))] + if not conf_file_list: + # no possible config file found in the usual locations + raise "could not find a config file" + config_file = conf_file_list[0] + else: + # a config file was specified (e.g. via command line) + if type(config_file) != types.StringType: + raise "invalid config file specified: %s" % config_file + if not os.path.exists(config_file): + raise "could not find the specified configuration file (%s)" % config_file + return config_file + + def safe(self): + """safe the current values of the config to file""" + return self.prefs.write() + + def createsection(self,newsection): + """adds a new empty section to config object""" + self.prefs[newsection] = {} + +################################# GUI ###################### + +class gtkgui: + def __init__(self,gtkext): + # gtk is given, it has to be known in the whole class + self.gtk = gtkext + # define which gladefile to use for frontend + gladefile = "in-gen-glade/in-gen-glade.glade" + self.gui = gtk.glade.XML(gladefile) + # set button handlers + actions = { "on_OkButton_clicked": self.clicked_ok, + "on_mainwindow_destroy": self.exit } + # connect the actions to the events + self.gui.signal_autoconnect (actions) + #load config + self.config = SettingsClass() + #display an unused invoice number + self.display_new_number() + + #### functions which get executed on startup + def display_new_number(self): + #get relevant variables + prefix = self.config[section]["prefix"] + lastnumber = self.config[section]["lastnumber"] + suffix = self.config[section]["suffix"] + newnumber = create_number(prefix, lastnumber, suffix) + + #display new number in GUI + self.outputfield = self.gui.get_widget("NumberDisplay") + self.textbuffer = self.outputfield.get_buffer() + self.textbuffer.set_text(newnumber) + + + #### implementation of actions + + def clicked_ok(self, widget): + """save last generated number in config file""" + #update "lastnumber" entry in config + self.config[section]["lastnumber"] = int(self.config[section]["lastnumber"]) + 1 + #write config to filesystem + self.config.safe() + + #notify user + self.outputfield = self.gui.get_widget("NumberDisplay") + self.textbuffer = self.outputfield.get_buffer() + self.textbuffer.set_text("Saved number has been updated.") + + + def exit(self, widget): + gtk.main_quit() + + + + +############################# INVOICE NUMBER HANDLING ################### + +def create_number(prefix, lastnumber, suffix): + """gets prefix string, last used number and suffix string. + returns new invoice number.""" + return str(prefix) + str(int(lastnumber)+1) + str(suffix) + + +############################ MAIN ################################# + + + +#section = str(sys.argv[1]) +section = "Handrechnung" + +app = gtkgui(gtk) +gtk.main()