summaryrefslogtreecommitdiff
path: root/portato
diff options
context:
space:
mode:
authornecoro <>2007-03-10 19:19:33 +0000
committernecoro <>2007-03-10 19:19:33 +0000
commitc399a6690b7981f1bd6c513666c4b37d71b5a855 (patch)
treeef7139b59f315390811d2e8fc8c7e628e25e6449 /portato
parent50aa869c3f35a4646009f2cbc1a16f555f3914a8 (diff)
downloadportato-c399a6690b7981f1bd6c513666c4b37d71b5a855.tar.gz
portato-c399a6690b7981f1bd6c513666c4b37d71b5a855.tar.bz2
portato-c399a6690b7981f1bd6c513666c4b37d71b5a855.zip
First plugin support
Diffstat (limited to 'portato')
-rw-r--r--portato/constants.py3
-rw-r--r--portato/gui/gtk/windows.py53
-rw-r--r--portato/helper.py18
-rw-r--r--portato/plugins/__init__.py11
-rw-r--r--portato/plugins/highlight.py33
5 files changed, 90 insertions, 28 deletions
diff --git a/portato/constants.py b/portato/constants.py
index 0e18425..85fde6e 100644
--- a/portato/constants.py
+++ b/portato/constants.py
@@ -14,9 +14,8 @@ CONFIG_DIR = "/etc/portato/"
CONFIG_LOCATION = CONFIG_DIR+"portato.cfg"
DATA_DIR = "portato/gui/gtk/glade/"
+PLUGIN_DIR = "plugins/"
VERSION = 9999
FRONTENDS = ["gtk"]
STD_FRONTEND = "gtk"
-
-USE_GTKSOURCEVIEW = False
diff --git a/portato/gui/gtk/windows.py b/portato/gui/gtk/windows.py
index d5ea943..5638741 100644
--- a/portato/gui/gtk/windows.py
+++ b/portato/gui/gtk/windows.py
@@ -16,9 +16,6 @@ pygtk.require("2.0")
import gtk
import gtk.glade
import gobject
-from portato.constants import USE_GTKSOURCEVIEW
-if USE_GTKSOURCEVIEW:
- import gtksourceview
# our backend stuff
from portato.helper import *
@@ -26,6 +23,9 @@ from portato.constants import CONFIG_LOCATION, VERSION, DATA_DIR
from portato.backend import flags, system
from portato.backend.exceptions import *
+# plugins
+from portato.plugin import PluginQueue
+
# more GUI stuff
from portato.gui.gui_helper import Database, Config, EmergeQueue
from dialogs import *
@@ -272,6 +272,13 @@ class EbuildWindow (AbstractDialog):
"""The window showing the ebuild."""
def __init__ (self, parent, package):
+ """Constructor.
+
+ @param parent: the parent window
+ @type parent: gtk.Window
+ @param package: the actual package
+ @type package: backend.Package"""
+
AbstractDialog.__init__(self,parent)
# we want it to get minimized
@@ -284,34 +291,32 @@ class EbuildWindow (AbstractDialog):
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 USE_GTKSOURCEVIEW: # we want syntax highlighting
- # get language
- man = gtksourceview.SourceLanguagesManager()
- language = [l for l in man.get_available_languages() if l.get_name() == "Gentoo"]
-
- # set buffer and view
- buf = gtksourceview.SourceBuffer()
- buf.set_language(language[0])
- buf.set_highlight(True)
- view = gtksourceview.SourceView(buf)
- else:
- buf = gtk.TextBuffer()
- view = gtk.TextView(buf)
+ self.package = package
+
+ self._build_view()
+ self._show()
- view.set_editable(False)
- view.set_cursor_visible(False)
+ def _build_view(self):
+ """Creates the buffer and the view."""
+ self.buf = gtk.TextBuffer()
+ self.view = gtk.TextView(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(package.get_ebuild_path(), "r")
+ f = open(self.package.get_ebuild_path(), "r")
lines = f.readlines()
f.close()
except IOError,e:
io_ex_dialog(e)
return
- buf.set_text("".join(lines))
+ self.buf.set_text("".join(lines))
- self.tree.get_widget("ebuildScroll").add(view)
+ self.tree.get_widget("ebuildScroll").add(self.view)
self.window.show_all()
class PackageTable:
@@ -590,7 +595,8 @@ class PackageTable:
return True
def cb_package_ebuild_clicked(self, button):
- EbuildWindow(self.window, self.actual_package())
+ hook = self.main.pluginQueue.hook("open_ebuild", self.actual_package(), self.window)
+ hook(EbuildWindow)(self.window, self.actual_package())
return True
def cb_testing_toggled (self, button):
@@ -677,6 +683,9 @@ class MainWindow (Window):
self.cfg.modify_external_configs()
+ # plugins
+ self.pluginQueue = PluginQueue()
+
# set vpaned position
vpaned = self.tree.get_widget("vpaned")
vpaned.set_position(mHeight/2)
diff --git a/portato/helper.py b/portato/helper.py
index d66e256..b41dbbe 100644
--- a/portato/helper.py
+++ b/portato/helper.py
@@ -10,7 +10,7 @@
#
# Written by René 'Necoro' Neumann <necoro@necoro.net> et.al.
-import traceback, os.path
+import traceback, os.path, sys
DEBUG = True
@@ -33,7 +33,7 @@ def debug(*args, **kwargs):
If you pass the optional keyword-argument "name", it is used for the function-name instead of the original one."""
- if not DEBUG : return
+ if not DEBUG and not ("warn" in kwargs or "error" in kwargs): return
stack = traceback.extract_stack()
minus = -2
@@ -50,14 +50,24 @@ def debug(*args, **kwargs):
else:
text = 'In %s (%s:%s): %s' % (c, a, b, text)
- text = "***DEBUG*** %s ***DEBUG***" % text
+ outfile = sys.stdout
+ surround = "DEBUG"
+
+ if "warn" in kwargs:
+ outfile = sys.stderr
+ surround = "WARNING"
+ elif "error" in kwargs:
+ outfile = sys.stderr
+ surround = "ERROR"
+
+ text = ("***%s*** %s ***%s***" % (surround, text, surround))
if "file" in kwargs:
f = open(kwargs["file"], "a+")
f.write(text+"\n")
f.close()
else:
- print text
+ print >> outfile, text
def am_i_root ():
"""Returns True if the current user is root, False otherwise.
diff --git a/portato/plugins/__init__.py b/portato/plugins/__init__.py
new file mode 100644
index 0000000..fe95dbc
--- /dev/null
+++ b/portato/plugins/__init__.py
@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+#
+# File: portato/plugins/__init__.py
+# This file is part of the Portato-Project, a graphical portage-frontend.
+#
+# Copyright (C) 2007 René 'Necoro' Neumann
+# This is free software. You may redistribute copies of it under the terms of
+# the GNU General Public License version 2.
+# There is NO WARRANTY, to the extent permitted by law.
+#
+# Written by René 'Necoro' Neumann <necoro@necoro.net>
diff --git a/portato/plugins/highlight.py b/portato/plugins/highlight.py
new file mode 100644
index 0000000..bc8b839
--- /dev/null
+++ b/portato/plugins/highlight.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+#
+# File: portato/plugins/highlight.py
+# This file is part of the Portato-Project, a graphical portage-frontend.
+#
+# Copyright (C) 2007 René 'Necoro' Neumann
+# This is free software. You may redistribute copies of it under the terms of
+# the GNU General Public License version 2.
+# There is NO WARRANTY, to the extent permitted by law.
+#
+# Written by René 'Necoro' Neumann <necoro@necoro.net>
+
+from portato.gui.gtk.windows import EbuildWindow
+
+import gtksourceview
+
+class HighlightedEbuildWindow (EbuildWindow):
+ """An ebuild window with syntax highlighting, using the GtkSourceview."""
+
+ def __init__ (self, package, parent):
+ self.__class__.__name__ = "EbuildWindow" # make the Window-Class render the correct window
+ EbuildWindow.__init__(self, parent, package)
+
+ def _build_view (self):
+ # get language
+ man = gtksourceview.SourceLanguagesManager()
+ language = [l for l in man.get_available_languages() if l.get_name() == "Gentoo"]
+
+ # set buffer and view
+ self.buf = gtksourceview.SourceBuffer()
+ self.buf.set_language(language[0])
+ self.buf.set_highlight(True)
+ self.view = gtksourceview.SourceView(self.buf)