summaryrefslogtreecommitdiff
path: root/portato/gui
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--portato/gui/gtk/usetips.py2
-rw-r--r--portato/gui/gtk/windows.py54
-rw-r--r--portato/gui/gui_helper.py95
-rw-r--r--portato/gui/qt/windows.py50
4 files changed, 87 insertions, 114 deletions
diff --git a/portato/gui/gtk/usetips.py b/portato/gui/gtk/usetips.py
index db970c1..1d8ce20 100644
--- a/portato/gui/gtk/usetips.py
+++ b/portato/gui/gtk/usetips.py
@@ -36,7 +36,7 @@ class UseTips (TreeViewTooltips):
# check config
if self.cfg is not None:
- if not self.cfg.get_boolean("useTips_opt", section = self.cfg.const["gtk_sec"]):
+ if not self.cfg.get_boolean("useTips", "GTK"):
return None
store = view.get_model()
diff --git a/portato/gui/gtk/windows.py b/portato/gui/gtk/windows.py
index 33948a1..6141ee4 100644
--- a/portato/gui/gtk/windows.py
+++ b/portato/gui/gtk/windows.py
@@ -186,25 +186,25 @@ class PreferenceWindow (AbstractDialog):
# all checkboxes in the window
# widget name -> option name
checkboxes = {
- "debugCheck" : "debug_opt",
- "deepCheck" : "deep_opt",
- "newUseCheck" : "newuse_opt",
- "maskPerVersionCheck" : "maskPerVersion_opt",
- "minimizeCheck" : ("minimize_opt", "gui_sec"),
- "systrayCheck" : ("systray_opt", "gui_sec"),
- "testPerVersionCheck" : "testingPerVersion_opt",
- "titleUpdateCheck" : ("updateTitle_opt", "gui_sec"),
- "usePerVersionCheck" : "usePerVersion_opt",
- "useTipsCheck" : ("useTips_opt", "gtk_sec")
+ "debugCheck" : "debug",
+ "deepCheck" : "deep",
+ "newUseCheck" : "newuse",
+ "maskPerVersionCheck" : "maskPerVersion",
+ "minimizeCheck" : ("minimize", "GUI"),
+ "systrayCheck" : ("systray", "GUI"),
+ "testPerVersionCheck" : "testingPerVersion",
+ "titleUpdateCheck" : ("updateTitle", "GUI"),
+ "usePerVersionCheck" : "usePerVersion",
+ "useTipsCheck" : ("useTips", "GTK")
}
# all edits in the window
# widget name -> option name
edits = {
- "maskFileEdit" : "maskFile_opt",
- "testFileEdit" : "testingFile_opt",
- "useFileEdit" : "useFile_opt",
- "syncCommandEdit" : "syncCmd_opt"
+ "maskFileEdit" : "maskFile",
+ "testFileEdit" : "testingFile",
+ "useFileEdit" : "useFile",
+ "syncCommandEdit" : "syncCmd"
}
def __init__ (self, parent, cfg, set_console_font):
@@ -234,7 +234,7 @@ class PreferenceWindow (AbstractDialog):
val = self.checkboxes[box]
if type(val) == types.TupleType:
self.tree.get_widget(box).\
- set_active(self.cfg.get_boolean(val[0], section = self.cfg.const[val[1]]))
+ set_active(self.cfg.get_boolean(val[0], section = val[1]))
else:
self.tree.get_widget(box).\
set_active(self.cfg.get_boolean(val))
@@ -246,7 +246,7 @@ class PreferenceWindow (AbstractDialog):
# the console font button
self.consoleFontBtn = self.tree.get_widget("consoleFontBtn")
- self.consoleFontBtn.set_font_name(self.cfg.get("consolefont_opt", section = self.cfg.const["gtk_sec"]))
+ self.consoleFontBtn.set_font_name(self.cfg.get("consolefont", section = "GTK"))
self.window.show_all()
@@ -256,7 +256,7 @@ class PreferenceWindow (AbstractDialog):
for box in self.checkboxes:
val = self.checkboxes[box]
if type(val) == types.TupleType:
- self.cfg.set_boolean(val[0], self.tree.get_widget(box).get_active(), section = self.cfg.const[val[1]])
+ self.cfg.set_boolean(val[0], self.tree.get_widget(box).get_active(), section = val[1])
else:
self.cfg.set_boolean(val, self.tree.get_widget(box).get_active())
@@ -264,7 +264,7 @@ class PreferenceWindow (AbstractDialog):
self.cfg.set(self.edits[edit],self.tree.get_widget(edit).get_text())
font = self.consoleFontBtn.get_font_name()
- self.cfg.set("consolefont_opt", font, section = self.cfg.const["gtk_sec"])
+ self.cfg.set("consolefont", font, section = "GTK")
self.set_console_font(font)
def cb_ok_clicked(self, button):
@@ -813,7 +813,7 @@ class MainWindow (Window):
self.trayPopup = self.create_popup("systrayPopup")
# systray
- if self.cfg.get_boolean("systray_opt", self.cfg.const["gui_sec"]):
+ if self.cfg.get_boolean("systray", "GUI"):
self.tray = gtk.status_icon_new_from_file(APP_ICON)
self.tray.connect("activate", self.cb_systray_activated)
self.tray.connect("popup-menu", lambda icon, btn, time: self.trayPopup.popup(None, None, None, btn, time))
@@ -833,7 +833,7 @@ class MainWindow (Window):
self.console.set_scrollback_lines(1024)
self.console.set_scroll_on_output(True)
- self.console.set_font_from_string(self.cfg.get("consolefont_opt", self.cfg.const["gtk_sec"]))
+ self.console.set_font_from_string(self.cfg.get("consolefont", "GTK"))
self.console.connect("button-press-event", self.cb_right_click)
termScroll = gtk.VScrollbar(self.console.get_adjustment())
self.termHB.pack_start(self.console, True, True)
@@ -925,7 +925,7 @@ class MainWindow (Window):
def title_update (self, title):
def window_title_update (title):
- if title is None or not self.cfg.get_boolean("updateTitle_opt", self.cfg.const["gui_sec"]):
+ if title is None or not self.cfg.get_boolean("updateTitle", "GUI"):
self.window.set_title(self.main_title)
else:
title = title.strip()
@@ -1011,7 +1011,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("newuse_opt"), deep = self.cfg.get_boolean("deep_opt"))
+ self.queue.update_world(force=True, newuse = self.cfg.get_boolean("newuse"), deep = self.cfg.get_boolean("deep"))
self.doUpdate = False
def cb_unmerge_clicked (self, button):
@@ -1027,7 +1027,7 @@ class MainWindow (Window):
not_root_dialog()
else:
- updating = system.update_world(newuse = self.cfg.get_boolean("newuse_opt"), deep = self.cfg.get_boolean("deep_opt"))
+ updating = system.update_world(newuse = self.cfg.get_boolean("newuse"), deep = self.cfg.get_boolean("deep"))
debug("updating list:", [(x.get_cpv(), y.get_cpv()) for x,y in updating],"--> length:",len(updating))
try:
@@ -1073,7 +1073,7 @@ class MainWindow (Window):
not_root_dialog()
else:
self.notebook.set_current_page(self.CONSOLE_PAGE)
- cmd = self.cfg.get("syncCmd_opt")
+ cmd = self.cfg.get("syncCmd")
if cmd != "emerge --sync":
cmd = cmd.split()
@@ -1152,12 +1152,12 @@ class MainWindow (Window):
store, it = sel.get_selected()
if it:
package = store.get_value(it, 0)
- if not self.cfg.get_local(package, "oneshot_opt"):
+ if not self.cfg.get_local(package, "oneshot"):
set = True
else:
set = False
- self.cfg.set_local(package, "oneshot_opt", set)
+ self.cfg.set_local(package, "oneshot", set)
self.queue.append(package, update = True, oneshot = set, forceUpdate = True)
def cb_kill_clicked (self, action):
@@ -1178,7 +1178,7 @@ class MainWindow (Window):
return False
def cb_minimized (self, window, event):
- if self.tray and self.cfg.get_boolean("minimize_opt", self.cfg.const["gui_sec"]):
+ if self.tray and self.cfg.get_boolean("minimize", "GUI"):
if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED:
if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED:
self.window.hide()
diff --git a/portato/gui/gui_helper.py b/portato/gui/gui_helper.py
index 40f3cee..f914b55 100644
--- a/portato/gui/gui_helper.py
+++ b/portato/gui/gui_helper.py
@@ -30,31 +30,18 @@ import time
import os
import signal
-class Config: # XXX: This needs to be replaced - the const-dict is just messy
+class Config:
"""Wrapper around a ConfigParser and for additional local configurations."""
+ # this const-dict holds all the values which are named differently in the sourcecode and in the cfg-file
+ # note: the keys are lowered before being looked up
const = {
- "main_sec" : "Main",
- "gtk_sec" : "Gtk",
- "qt_sec" : "Qt",
- "gui_sec" : "Gui",
- "usePerVersion_opt" : "usePerVersion",
- "useFile_opt" : "usefile",
- "maskFile_opt" : "maskfile",
- "maskPerVersion_opt" : "maskPerVersion",
- "testingFile_opt" : "keywordfile",
- "testingPerVersion_opt" : "keywordperversion",
- "debug_opt" : "debug",
- "oneshot_opt" : "oneshot",
- "deep_opt" : "deep",
- "newuse_opt" : "newuse",
- "syncCmd_opt" : "synccommand",
- "useTips_opt" : "showusetips",
- "consolefont_opt" : "consolefont",
- "pkgIcons_opt" : "packageIcons",
- "system_opt" : "system",
- "systray_opt" : "showsystray",
- "minimize_opt" : "hideonminimize",
- "updateTitle_opt" : "updatetitle"
+ "minimize" : "hideonminimize",
+ "pkgicons" : "packageIcons",
+ "synccmd" : "synccommand",
+ "systray" : "showsystray",
+ "testingfile" : "keywordfile",
+ "testingperversion" : "keywordperversion",
+ "usetips" : "showusetips"
}
def __init__ (self, cfgFile):
@@ -72,62 +59,58 @@ class Config: # XXX: This needs to be replaced - the const-dict is just messy
# local configs
self.local = {}
- def get(self, name, section=const["main_sec"], constName = True):
+ def __get_val (self, name):
+ try:
+ return self.const[name.lower()]
+ except KeyError:
+ return name
+
+ def get(self, name, section="MAIN"):
"""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(self.__get_val(name), self.__get_val(section))
- return self._cfg.get(name, section)
-
- def get_boolean(self, name, section=const["main_sec"], constName = True):
+ def get_boolean(self, name, section="MAIN"):
"""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)
+ return self._cfg.get_boolean(self.__get_val(name), self.__get_val(section))
def modify_flags_config (self):
"""Sets the internal config of the L{flags}-module.
@see: L{flags.set_config()}"""
flagCfg = {
- "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")}
+ "usefile": self.get("useFile"),
+ "usePerVersion" : self.get_boolean("usePerVersion"),
+ "maskfile" : self.get("maskFile"),
+ "maskPerVersion" : self.get_boolean("maskPerVersion"),
+ "testingfile" : self.get("testingFile"),
+ "testingPerVersion" : self.get_boolean("testingPerVersion")}
flags.set_config(flagCfg)
def modify_debug_config (self):
"""Sets the external debug-config.
@see: L{helper.set_debug()}"""
- set_debug(self.get_boolean("debug_opt"))
+ set_debug(self.get_boolean("debug"))
def modify_system_config (self):
"""Sets the system config.
@see: L{backend.set_system()}"""
- set_system(self.get("system_opt"))
+ set_system(self.get("system"))
def modify_external_configs (self):
"""Convenience function setting all external configs."""
@@ -167,7 +150,7 @@ class Config: # XXX: This needs to be replaced - the const-dict is just messy
return self.local[cpv][name]
- def set(self, name, val, section=const["main_sec"], constName = True):
+ def set(self, name, val, section = "MAIN"):
"""Sets an option.
@param name: name of the option
@@ -175,16 +158,11 @@ class Config: # XXX: This needs to be replaced - the const-dict is just messy
@param val: value to set the option to
@type val: 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"""
-
- if constName:
- name = self.const[name]
+ @type section: string"""
- self._cfg.set(name, val, section)
+ self._cfg.set(self.__get_val(name), val, self.__get_val(section))
- def set_boolean (self, name, val, section=const["main_sec"], constName = True):
+ def set_boolean (self, name, val, section = "MAIN"):
"""Sets a boolean option.
@param name: name of the option
@@ -192,14 +170,9 @@ class Config: # XXX: This needs to be replaced - the const-dict is just messy
@param val: value to set the option to
@type val: boolean
@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"""
-
- if constName:
- name = self.const[name]
+ @type section: string"""
- self._cfg.set_boolean(name, val, section)
+ self._cfg.set_boolean(self.__get_val(name), val, self.__get_val(section))
def write(self):
"""Writes to the config file and modify any external configs."""
diff --git a/portato/gui/qt/windows.py b/portato/gui/qt/windows.py
index d701893..e02a3c5 100644
--- a/portato/gui/qt/windows.py
+++ b/portato/gui/qt/windows.py
@@ -178,25 +178,25 @@ class PreferenceWindow (Window):
# all checkboxes in the window
# widget name -> option name
checkboxes = {
- "debugCheck" : "debug_opt",
- "deepCheck" : "deep_opt",
- "newUseCheck" : "newuse_opt",
- "maskCheck" : "maskPerVersion_opt",
- "useCheck" : "usePerVersion_opt",
- "testingCheck" : "testingPerVersion_opt",
- "pkgIconsCheck" : ("pkgIcons_opt", "qt_sec"),
- "minimizeCheck" : ("minimize_opt", "gui_sec"),
- "systrayCheck" : ("systray_opt", "gui_sec"),
- "titleUpdateCheck" : ("updateTitle_opt", "gui_sec")
+ "debugCheck" : "debug",
+ "deepCheck" : "deep",
+ "newUseCheck" : "newuse",
+ "maskCheck" : "maskPerVersion",
+ "useCheck" : "usePerVersion",
+ "testingCheck" : "testingPerVersion",
+ "pkgIconsCheck" : ("pkgIcons", "QT"),
+ "minimizeCheck" : ("minimize", "GUI"),
+ "systrayCheck" : ("systray", "GUI"),
+ "titleUpdateCheck" : ("updateTitle", "GUI")
}
# all edits in the window
# widget name -> option name
edits = {
- "maskEdit" : "maskFile_opt",
- "testingEdit" : "testingFile_opt",
- "useEdit" : "useFile_opt",
- "syncCmdEdit" : "syncCmd_opt"
+ "maskEdit" : "maskFile",
+ "testingEdit" : "testingFile",
+ "useEdit" : "useFile",
+ "syncCmdEdit" : "syncCmd"
}
def __init__ (self, parent, cfg):
@@ -221,7 +221,7 @@ class PreferenceWindow (Window):
val = self.checkboxes[box]
box = self.__getattribute__(box)
if type(val) == types.TupleType:
- box.setCheckState(qCheck(self.cfg.get_boolean(val[0], section = self.cfg.const[val[1]])))
+ box.setCheckState(qCheck(self.cfg.get_boolean(val[0], section = val[1])))
else:
box.setCheckState(qCheck(self.cfg.get_boolean(val)))
@@ -239,7 +239,7 @@ class PreferenceWindow (Window):
val = self.checkboxes[box]
box = self.__getattribute__(box)
if type(val) == types.TupleType:
- self.cfg.set_boolean(val[0], qIsChecked(box.checkState()), section = self.cfg.const[val[1]])
+ self.cfg.set_boolean(val[0], qIsChecked(box.checkState()), section = val[1])
else:
self.cfg.set_boolean(val, qIsChecked(box.checkState()))
@@ -668,7 +668,7 @@ class MainWindow (Window):
def _title_update (self, title):
def window_update (title):
- if title is None or not self.cfg.get_boolean("updateTitle_opt", self.cfg.const["gui_sec"]):
+ if title is None or not self.cfg.get_boolean("updateTitle", "GUI"):
self.setWindowTitle(self.main_title)
else:
title = title.strip()
@@ -696,7 +696,7 @@ class MainWindow (Window):
self.pkgDetails.update(cp, self.queue)
def fill_pkg_list (self, cat):
- use_icons = self.cfg.get_boolean("pkgIcons_opt", section = self.cfg.const["qt_sec"])
+ use_icons = self.cfg.get_boolean("pkgIcons", section = "QT")
# installed icon
if use_icons:
@@ -725,7 +725,7 @@ class MainWindow (Window):
self.catList.setSelectionModel(self.selCatListModel)
def build_systray (self):
- if self.cfg.get_boolean("systray_opt", self.cfg.const["gui_sec"]):
+ if self.cfg.get_boolean("systray", "GUI"):
self.systray = Qt.QSystemTrayIcon(Qt.QIcon(APP_ICON), self) # use this until Qt supports proper SVG images in the systray
self.trayIconMenu = Qt.QMenu(self)
self.trayIconMenu.addAction(self.quitAction)
@@ -778,7 +778,7 @@ class MainWindow (Window):
not_root_dialog(self)
else:
self.tabWidget.setCurrentIndex(self.CONSOLE_PAGE)
- cmd = self.cfg.get("syncCmd_opt")
+ cmd = self.cfg.get("syncCmd")
if cmd != "emerge --sync":
cmd = cmd.split()
@@ -793,12 +793,12 @@ class MainWindow (Window):
if self.queueTree.is_in_emerge(current) and self.queueTree.iter_has_parent(current):
pkg = self.queueTree.get_value(current, self.queueTree.get_cpv_column())
- if not self.cfg.get_local(pkg, "oneshot_opt"):
+ if not self.cfg.get_local(pkg, "oneshot"):
set = True
else:
set = False
- self.cfg.set_local(pkg, "oneshot_opt", set)
+ self.cfg.set_local(pkg, "oneshot", set)
self.queue.append(pkg, update = True, oneshot = set, forceUpdate = True)
@Qt.pyqtSignature("bool")
@@ -863,7 +863,7 @@ class MainWindow (Window):
if not self.doUpdate:
self.queue.emerge(force=True, options = ["--nospinner"])
else:
- self.queue.update_world(force=True, newuse = self.cfg.get_boolean("newuse_opt"), deep = self.cfg.get_boolean("deep_opt"), options = ["--nospinner"])
+ self.queue.update_world(force=True, newuse = self.cfg.get_boolean("newuse"), deep = self.cfg.get_boolean("deep"), options = ["--nospinner"])
self.doUpdate = False
@Qt.pyqtSignature("")
@@ -880,7 +880,7 @@ class MainWindow (Window):
not_root_dialog(self)
else:
- updating = system.update_world(newuse = self.cfg.get_boolean("newuse_opt"), deep = self.cfg.get_boolean("deep_opt"))
+ updating = system.update_world(newuse = self.cfg.get_boolean("newuse"), deep = self.cfg.get_boolean("deep"))
debug("updating list:", [(x.get_cpv(), y.get_cpv()) for x,y in updating],"--> length:",len(updating))
try:
@@ -943,7 +943,7 @@ class MainWindow (Window):
def changeEvent (self, event):
if event.type() == Qt.QEvent.WindowStateChange:
- if self.systray and self.cfg.get_boolean("minimize_opt", self.cfg.const["gui_sec"]):
+ if self.systray and self.cfg.get_boolean("minimize", "GUI"):
if self.windowState() & Qt.Qt.WindowMinimized: # going to be minimized
self.hide()
return