diff options
Diffstat (limited to '')
-rw-r--r-- | portato/gui/gtk/windows.py | 177 |
1 files changed, 84 insertions, 93 deletions
diff --git a/portato/gui/gtk/windows.py b/portato/gui/gtk/windows.py index 11f245b..b630cb3 100644 --- a/portato/gui/gtk/windows.py +++ b/portato/gui/gtk/windows.py @@ -10,12 +10,13 @@ # # Written by René 'Necoro' Neumann <necoro@necoro.net> -from __future__ import absolute_import +from __future__ import absolute_import, with_statement # gtk stuff import gtk import gobject import gtksourceview2 +import pango # other import types, logging @@ -351,66 +352,51 @@ class PreferenceWindow (AbstractDialog): """Just closes - w/o saving.""" self.window.destroy() -class EbuildWindow (AbstractDialog): - """The window showing the ebuild.""" +class HighlightView (gtksourceview2.View): - def __init__ (self, parent, package): - """Constructor. + def __init__ (self, get_file_fn, languages = []): + self.get_fn = get_file_fn - @param parent: the parent window - @type parent: gtk.Window - @param package: the actual package - @type package: backend.Package""" - - AbstractDialog.__init__(self,parent) + man = gtksourceview2.LanguageManager() - # we want it to get minimized - self.window.set_transient_for(None) + language = None + old_lang = None + for lang in languages: + if old_lang and not language: + warning(_("No %(old)s language file installed. Falling back to %(new)s."), {"old" : old_lang, "new" : lang}) + language = man.get_language(lang) + old_lang = lang - self.window.set_title(package.get_cpv()) - - # set geometry (same as MainWindow) - mHeight = 800 - if gtk.gdk.screen_height() <= 800: mHeight = 600 - self.window.set_geometry_hints (self.window, min_width = 800, min_height = mHeight, max_height = gtk.gdk.screen_height(), max_width = gtk.gdk.screen_width()) + if not language and old_lang: + warning(_("No %(old)s language file installed. Disable highlighting."), {"old" : old_lang}) - self.package = package + buf = gtksourceview2.Buffer() + buf.set_language(language) - self._build_view() - self._show() + gtksourceview2.View.__init__(self, buf) - def _build_view(self): - """Creates the buffer and the view.""" + self.set_editable(False) + self.set_cursor_visible(False) + self.connect("map", self.cb_mapped) - man = gtksourceview2.LanguageManager() - language = man.get_language("gentoo") + self.pkg = None + self.updated = False - if language is None: - warning(_("No gentoo language file installed. Falling back to shell.")) - language = man.get_language("sh") - - # set buffer and view - self.buf = gtksourceview2.Buffer() - self.buf.set_language(language) - self.view = gtksourceview2.View(self.buf) - - def _show (self): - """Fill the buffer with content and shows the window.""" - self.view.set_editable(False) - self.view.set_cursor_visible(False) - - try: # read ebuild - f = open(self.package.get_ebuild_path(), "r") - lines = f.readlines() - f.close() - except IOError,e: - io_ex_dialog(e) - return + def update (self, pkg): + self.pkg = pkg + self.updated = True + + def cb_mapped (self, *args): + if self.updated and self.pkg: + try: + with open(self.get_fn(self.pkg)) as f: + lines = f.readlines() + except IOError, e: + lines = _("Error: %s") % e.strerror - self.buf.set_text("".join(lines)) + self.get_buffer().set_text("".join(lines)) - self.tree.get_widget("ebuildScroll").add(self.view) - self.window.show_all() + return False class PackageTable: """A window with data about a specfic package.""" @@ -643,6 +629,10 @@ class PackageTable: def cb_vers_list_changed (self, *args): pkg = self.actual_package() + self.main.ebuildView.update(pkg) + self.main.ebuildView.get_parent().show_all() + self.main.changelogView.update(pkg) + self.main.changelogView.get_parent().show_all() self.set_desc_label() @@ -653,6 +643,7 @@ class PackageTable: # set use list self.useList.get_model().clear() + self.useList.columns_autosize() self.fill_use_list() # @@ -743,11 +734,6 @@ class PackageTable: self.main.notebook.set_current_page(self.main.QUEUE_PAGE) return True - def cb_package_ebuild_clicked(self, button): - hook = plugin.hook("open_ebuild", package = self.actual_package(), parent = self.window) - hook(EbuildWindow)(self.window, self.actual_package()) - return True - def cb_testing_toggled (self, button): """Callback for toggled testing-checkbox.""" status = button.get_active() @@ -825,51 +811,50 @@ class PackageTable: return True -class LogWindow (AbstractDialog, logging.Handler): +class LogView (logging.Handler): - def __init__ (self, parent): - AbstractDialog.__init__(self, parent) - logging.Handler.__init__(self, logging.INFO) + colors = ( + (logging.DEBUG, "debug", "blue"), + (logging.INFO, "info", "green"), + (logging.WARNING, "warning", "yellow"), + (-1, "error", "red") + ) - self.logView = self.tree.get_widget("logView") - logging.getLogger("portatoLogger").addHandler(self) + def __init__ (self, view): + logging.Handler.__init__(self, logging.DEBUG) - self.deleteIsOk = False - - def format (self, record): + self.view = view + self.buf = view.get_buffer() + + # set tags + for lvl, name, color in self.colors: + self.buf.create_tag("log_%s" % name, foreground = color,weight = pango.WEIGHT_BOLD) - if (record.levelno > logging.INFO): - return "%s: %s" % (record.levelname, record.getMessage()) - else: - return record.getMessage() + logging.getLogger("portatoLogger").addHandler(self) def emit (self, record): - self.logView.get_buffer().insert_at_cursor(self.format(record)+"\n") - - def show (self): - self.window.show() - - def close (self): - self.window.hide() - - def destroy (self): - self.deleteIsOk = True - self.window.destroy() + iter = self.buf.get_end_iter() + + for lvl, name, color in self.colors: + if lvl == -1 or record.levelno <= lvl: + tag = "log_%s" % name + break - def cb_delete (self, *args): - if not self.deleteIsOk: - self.close() - return True - else: - return False + self.buf.insert_with_tags_by_name(iter, "* ", tag) + self.buf.insert_at_cursor(record.getMessage()+"\n") class MainWindow (Window): """Application main window.""" # NOTEBOOK PAGE CONSTANTS - PKG_PAGE = 0 - QUEUE_PAGE = 1 - CONSOLE_PAGE = 2 + ( + PKG_PAGE, + EBUILD_PAGE, + CHANGELOG_PAGE, + QUEUE_PAGE, + CONSOLE_PAGE, + LOG_PAGE + ) = range(6) def __init__ (self, splash = None): """Build up window""" @@ -895,7 +880,7 @@ class MainWindow (Window): self.instPixbuf = self.window.render_icon(gtk.STOCK_YES, gtk.ICON_SIZE_MENU) # get the logging window as soon as possible - self.logWindow = LogWindow(self.window) + self.logView = LogView(self.tree.get_widget("logView")) # config splash(_("Loading Config")) @@ -974,6 +959,16 @@ class MainWindow (Window): self.notebook = self.tree.get_widget("notebook") self.window.show_all() + ebuildScroll = self.tree.get_widget("ebuildScroll") + self.ebuildView = HighlightView(lambda p: p.get_ebuild_path(), ["gentoo", "sh"]) + ebuildScroll.add(self.ebuildView) + ebuildScroll.hide_all() + + changelogScroll = self.tree.get_widget("changelogScroll") + self.changelogView = HighlightView(lambda p: os.path.join(p.get_package_path(), "ChangeLog"), ["changelog"]) + changelogScroll.add(self.changelogView) + changelogScroll.hide_all() + # table self.packageTable = PackageTable(self) self.packageTable.hide() @@ -1390,9 +1385,6 @@ class MainWindow (Window): PluginWindow(self.window, queue) return True - def cb_show_log_clicked (self, btn): - self.logWindow.show() - def cb_show_updates_clicked (self, button): def __update(): @@ -1535,7 +1527,6 @@ class MainWindow (Window): def cb_destroy (self, widget): """Calls main_quit().""" - self.logWindow.destroy() gtk.main_quit() def main (self): |