| 1 | #!/usr/bin/env python |
|---|
| 2 | # -* python -*- |
|---|
| 3 | # -*- coding: UTF-8 -*- |
|---|
| 4 | # |
|---|
| 5 | # File: config.py |
|---|
| 6 | # |
|---|
| 7 | # Copyright (C) 2006 Iacopo Pecchi <iacopo@truelite.it> |
|---|
| 8 | # |
|---|
| 9 | # This program is free software; you can redistribute it and/or modify |
|---|
| 10 | # it under the terms of the GNU General Public License version 2, as |
|---|
| 11 | # published by the Free Software Foundation. |
|---|
| 12 | |
|---|
| 13 | import gtk |
|---|
| 14 | import gnome |
|---|
| 15 | import gnome.ui |
|---|
| 16 | from octofuss import config, art |
|---|
| 17 | from gettext import gettext as _ |
|---|
| 18 | |
|---|
| 19 | class CheckConfigUI(gtk.Window): |
|---|
| 20 | def __init__(self, mandatory,initial_text=_("Welcome to Octofuss"),reconf=False): |
|---|
| 21 | gtk.Window.__init__(self) |
|---|
| 22 | self.missing = mandatory |
|---|
| 23 | self.druid = gnome.ui.Druid() |
|---|
| 24 | self.add(self.druid) |
|---|
| 25 | self.druid.add(self.build_page_edge(_("Welcome"),initial_text,True)) |
|---|
| 26 | self.entries = [] |
|---|
| 27 | for section in self.missing.keys(): |
|---|
| 28 | if reconf: |
|---|
| 29 | page = self.build_page(section,reconf) |
|---|
| 30 | else: |
|---|
| 31 | page = self.build_page(section) |
|---|
| 32 | |
|---|
| 33 | self.druid.add(page) |
|---|
| 34 | |
|---|
| 35 | last_page = self.build_page_edge(_("Done!"),_("Done!"),False) |
|---|
| 36 | last_page.connect('finish',self.complete) |
|---|
| 37 | self.druid.add(last_page) |
|---|
| 38 | |
|---|
| 39 | self.druid.connect('cancel', self.closeDruid) |
|---|
| 40 | |
|---|
| 41 | self.connect("delete_event", self.closeDruid) |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | def closeDruid(self, a, b=None): |
|---|
| 45 | self.destroy() |
|---|
| 46 | |
|---|
| 47 | def complete(self,obj,obj2): |
|---|
| 48 | for item in self.entries: |
|---|
| 49 | section = item[0] |
|---|
| 50 | key = item[1] |
|---|
| 51 | value = item[2].get_text() |
|---|
| 52 | config.set(section,key,value) |
|---|
| 53 | config.write() |
|---|
| 54 | self.destroy() |
|---|
| 55 | config.check_config_ui(_("Welcome to Octofuss.\n\nLooks like you've missed to enter some mandatory values.\n\nPlease try again!")) |
|---|
| 56 | |
|---|
| 57 | def build_page_edge(self,title,text,start=True): |
|---|
| 58 | """ Create a druid edge page """ |
|---|
| 59 | if start: |
|---|
| 60 | count = 0 |
|---|
| 61 | else: |
|---|
| 62 | count = 1 |
|---|
| 63 | p = gnome.ui.DruidPageEdge(count) |
|---|
| 64 | logo = art.get_pixbuf_from_name("cluster-new") |
|---|
| 65 | p.set_logo(logo) |
|---|
| 66 | p.set_title(title) |
|---|
| 67 | p.set_text(text) |
|---|
| 68 | return p |
|---|
| 69 | |
|---|
| 70 | def build_page(self,section, reconf=False): |
|---|
| 71 | |
|---|
| 72 | """ Create a druid page """ |
|---|
| 73 | p = gnome.ui.DruidPageStandard() |
|---|
| 74 | logo = art.get_pixbuf_from_name("cluster-new") |
|---|
| 75 | p.set_logo(logo) |
|---|
| 76 | p.set_title(section) |
|---|
| 77 | v = gtk.VBox() |
|---|
| 78 | size_group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) |
|---|
| 79 | p.append_item(_("Please fill in values for section")+" "+section,v,'') |
|---|
| 80 | for key in self.missing[section]: |
|---|
| 81 | h = gtk.HBox() |
|---|
| 82 | |
|---|
| 83 | label = gtk.Label(key[1]) |
|---|
| 84 | h.pack_start(label) |
|---|
| 85 | size_group.add_widget(label) |
|---|
| 86 | |
|---|
| 87 | entry = gtk.Entry() |
|---|
| 88 | if reconf: |
|---|
| 89 | entry.set_text(config.get(section, key[0])) |
|---|
| 90 | # we have a password field... |
|---|
| 91 | if 'asswor' in key[1]: |
|---|
| 92 | entry.set_visibility(False) |
|---|
| 93 | h.pack_start(entry) |
|---|
| 94 | |
|---|
| 95 | self.entries.append((section,key[0],entry)) |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | size_group.add_widget(entry) |
|---|
| 99 | label.set_mnemonic_widget(entry) |
|---|
| 100 | v.pack_start(h) |
|---|
| 101 | |
|---|
| 102 | v.show_all() |
|---|
| 103 | |
|---|
| 104 | return p |
|---|
| 105 | |
|---|
| 106 | |
|---|