summaryrefslogtreecommitdiff
path: root/geneticone/gui
diff options
context:
space:
mode:
authornecoro <>2006-11-12 19:13:28 +0000
committernecoro <>2006-11-12 19:13:28 +0000
commit580ebfccad88986c4f5f91f346ab5bf555f45ced (patch)
tree9ed5a71aee728c78928ca9a837d32d7b7b6fdea1 /geneticone/gui
parentccee291737673926730f8573c22bb348b10438eb (diff)
downloadportato-580ebfccad88986c4f5f91f346ab5bf555f45ced.tar.gz
portato-580ebfccad88986c4f5f91f346ab5bf555f45ced.tar.bz2
portato-580ebfccad88986c4f5f91f346ab5bf555f45ced.zip
rewritten config to take directly the const-keys; added io_ex_dialog
Diffstat (limited to 'geneticone/gui')
-rw-r--r--geneticone/gui/gtk/dialogs.py30
-rw-r--r--geneticone/gui/gtk/windows.py37
-rw-r--r--geneticone/gui/gui_helper.py46
3 files changed, 73 insertions, 40 deletions
diff --git a/geneticone/gui/gtk/dialogs.py b/geneticone/gui/gtk/dialogs.py
index cb643ce..7607fd4 100644
--- a/geneticone/gui/gtk/dialogs.py
+++ b/geneticone/gui/gtk/dialogs.py
@@ -12,20 +12,27 @@
import gtk
+def io_ex_dialog (io_ex):
+ string = io_ex.strerror
+ if io_ex.filename:
+ string = string+": "+io_ex.filename
+
+ dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, string)
+ ret = dialog.run()
+ dialog.destroy()
+ return ret
+
def blocked_dialog (blocked, blocks):
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, blocked+" is blocked by "+blocks+".\nPlease unmerge the blocking package.")
- dialog.run()
+ ret = dialog.run()
dialog.destroy()
+ return ret
def not_root_dialog ():
errorMB = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, "You cannot (un)merge without being root.")
- errorMB.run()
+ ret = errorMB.run()
errorMB.destroy()
-
-def masked_dialog (cpv):
- dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, cpv+" seems to be masked.\nPlease edit the appropriate file(s) to unmask it and restart Genetic/One.\n")
- dialog.run()
- dialog.destroy()
+ return ret
def unmask_dialog (cpv):
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, cpv+" seems to be masked.\nDo you want to unmask it and its dependencies?.\n")
@@ -35,19 +42,22 @@ def unmask_dialog (cpv):
def nothing_found_dialog ():
dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Package not found!")
- dialog.run()
+ ret = dialog.run()
dialog.destroy()
+ return ret
def changed_flags_dialog (what = "flags"):
hintMB = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
"You have changed %s. Genetic/One will write these changes into the appropriate files. Please backup them if you think it is necessairy." % what)
- hintMB.run()
+ ret = hintMB.run()
hintMB.destroy()
+ return ret
def remove_deps_dialog ():
infoMB = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "You cannot remove dependencies. :)")
- infoMB.run()
+ ret = infoMB.run()
infoMB.destroy()
+ return ret
def remove_queue_dialog ():
askMB = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "Do you really want to clear the whole queue?")
diff --git a/geneticone/gui/gtk/windows.py b/geneticone/gui/gtk/windows.py
index 8c6febb..8623e51 100644
--- a/geneticone/gui/gtk/windows.py
+++ b/geneticone/gui/gtk/windows.py
@@ -195,13 +195,11 @@ class PreferenceWindow (AbstractDialog):
for box in self.checkboxes:
self.tree.get_widget(box).\
- set_active(self.cfg.get_boolean(\
- self.cfg.const[self.checkboxes[box]]))
+ set_active(self.cfg.get_boolean(self.checkboxes[box]))
for edit in self.edits:
self.tree.get_widget(edit).\
- set_text(self.cfg.get(\
- self.cfg.const[self.edits[edit]]))
+ set_text(self.cfg.get(self.edits[edit]))
self.window.show_all()
@@ -209,19 +207,19 @@ class PreferenceWindow (AbstractDialog):
"""Sets all options in the Config-instance."""
for box in self.checkboxes:
- self.cfg.set_boolean(\
- self.cfg.const[self.checkboxes[box]],\
- self.tree.get_widget(box).get_active())
+ self.cfg.set_boolean(self.checkboxes[box], self.tree.get_widget(box).get_active())
for edit in self.edits:
- self.cfg.set(\
- self.cfg.const[self.edits[edit]],\
- self.tree.get_widget(edit).get_text())
+ self.cfg.set(self.edits[edit],self.tree.get_widget(edit).get_text())
def cb_ok_clicked(self, button):
"""Saves, writes to config-file and closes the window."""
self._save()
- self.cfg.write()
+ try:
+ self.cfg.write()
+ except IOError, e:
+ io_ex_dialog(e)
+
self.window.destroy()
def cb_cancel_clicked (self, button):
@@ -577,7 +575,12 @@ class MainWindow (Window):
self.db.populate()
# config
- self.cfg = Config(CONFIG_LOCATION)
+ try:
+ self.cfg = Config(CONFIG_LOCATION)
+ except IOError, e:
+ io_ex_dialog(e)
+ raise e
+
self.cfg.modify_external_configs()
# set vpaned position
@@ -746,7 +749,7 @@ class MainWindow (Window):
if not self.doUpdate:
self.queue.emerge(force=True)
else:
- self.queue.update_world(force=True, newuse = self.cfg.get_boolean(self.cfg.const["newuse_opt"]), deep = self.cfg.get_boolean(self.cfg.const["deep_opt"]))
+ self.queue.update_world(force=True, newuse = self.cfg.get_boolean("newuse_opt"), deep = self.cfg.get_boolean("deep_opt"))
self.doUpdate = False
def cb_unmerge_clicked (self, button):
@@ -762,7 +765,7 @@ class MainWindow (Window):
not_root_dialog()
else:
- updating = backend.update_world(newuse = self.cfg.get_boolean(self.cfg.const["newuse_opt"]), deep = self.cfg.get_boolean(self.cfg.const["deep_opt"]))
+ updating = backend.update_world(newuse = self.cfg.get_boolean("newuse_opt"), deep = self.cfg.get_boolean("deep_opt"))
debug("updating list:", [(x.get_cpv(), y.get_cpv()) for x,y in updating])
try:
@@ -802,7 +805,7 @@ class MainWindow (Window):
not_root_dialog()
else:
self.notebook.set_current_page(self.CONSOLE_PAGE)
- cmd = self.cfg.get(self.cfg.const["syncCmd_opt"])
+ cmd = self.cfg.get("syncCmd_opt")
if cmd != "emerge --sync":
cmd = cmd.split()
@@ -861,12 +864,12 @@ class MainWindow (Window):
store, it = sel.get_selected()
if it:
package = store.get_value(it, 0)
- if not self.cfg.get_local(package, self.cfg.const["oneshot_opt"]):
+ if not self.cfg.get_local(package, "oneshot_opt"):
set = True
else:
set = False
- self.cfg.set_local(package, self.cfg.const["oneshot_opt"], set)
+ self.cfg.set_local(package, "oneshot_opt", set)
self.queue.append(package, update = True, oneshot = set, forceUpdate = True)
def cb_destroy (self, widget):
diff --git a/geneticone/gui/gui_helper.py b/geneticone/gui/gui_helper.py
index edddc53..bbc4bb9 100644
--- a/geneticone/gui/gui_helper.py
+++ b/geneticone/gui/gui_helper.py
@@ -58,28 +58,38 @@ class Config:
# local configs
self.local = {}
- def get(self, name, section=const["main_sec"]):
+ def get(self, name, section=const["main_sec"], constName = True):
"""Gets an option.
@param name: name of the option
@type name: string
@param section: section to look in; default is Main-Section
@type section: string
+ @param constName: If True (the default), the option names are first looked up in the const-dict.
+ @type constName: boolean
@return: the option's value
@rtype: string"""
+ if constName:
+ name = self.const[name]
+
return self._cfg.get(name, section)
- def get_boolean(self, name, section=const["main_sec"]):
+ def get_boolean(self, name, section=const["main_sec"], constName = True):
"""Gets a boolean option.
@param name: name of the option
@type name: string
@param section: section to look in; default is Main-Section
@type section: string
+ @param constName: If True (the default), the option names are first looked up in the const-dict.
+ @type constName: boolean
@return: the option's value
@rtype: boolean"""
+ if constName:
+ name = self.const[name]
+
return self._cfg.get_boolean(name, section)
def modify_flags_config (self):
@@ -87,18 +97,18 @@ class Config:
@see: L{flags.set_config()}"""
flagCfg = {
- "usefile": self.get(self.const["useFile_opt"]),
- "usePerVersion" : self.get_boolean(self.const["usePerVersion_opt"]),
- "maskfile" : self.get(self.const["maskFile_opt"]),
- "maskPerVersion" : self.get_boolean(self.const["maskPerVersion_opt"]),
- "testingfile" : self.get(self.const["testingFile_opt"]),
- "testingPerVersion" : self.get_boolean(self.const["testingPerVersion_opt"])}
+ "usefile": self.get("useFile_opt"),
+ "usePerVersion" : self.get_boolean("usePerVersion_opt"),
+ "maskfile" : self.get("maskFile_opt"),
+ "maskPerVersion" : self.get_boolean("maskPerVersion_opt"),
+ "testingfile" : self.get("testingFile_opt"),
+ "testingPerVersion" : self.get_boolean("testingPerVersion_opt")}
flags.set_config(flagCfg)
def modify_debug_config (self):
"""Sets the external debug-config.
@see: L{helper.set_debug()}"""
- set_debug(self.get_boolean(self.const["debug_opt"]))
+ set_debug(self.get_boolean("debug_opt"))
def modify_external_configs (self):
"""Convenience function setting all external configs."""
@@ -137,7 +147,7 @@ class Config:
return self.local[cpv][name]
- def set(self, name, val, section=const["main_sec"]):
+ def set(self, name, val, section=const["main_sec"], constName = True):
"""Sets an option.
@param name: name of the option
@@ -145,11 +155,16 @@ class Config:
@param val: value to set the option to
@type val: string
@param section: section to look in; default is Main-Section
- @type section: string"""
+ @type section: string
+ @param constName: If True (the default), the option names are first looked up in the const-dict.
+ @type constName: boolean"""
+
+ if constName:
+ name = self.const[name]
self._cfg.set(name, val, section)
- def set_boolean (self, name, val, section=const["main_sec"]):
+ def set_boolean (self, name, val, section=const["main_sec"], constName = True):
"""Sets a boolean option.
@param name: name of the option
@@ -157,7 +172,12 @@ class Config:
@param val: value to set the option to
@type val: boolean
@param section: section to look in; default is Main-Section
- @type section: string"""
+ @type section: string
+ @param constName: If True (the default), the option names are first looked up in the const-dict.
+ @type constName: boolean"""
+
+ if constName:
+ name = self.const[name]
self._cfg.set_boolean(name, val, section)