summaryrefslogtreecommitdiff
path: root/portato/gui/qt
diff options
context:
space:
mode:
Diffstat (limited to 'portato/gui/qt')
-rw-r--r--portato/gui/qt/highlighter.py110
-rw-r--r--portato/gui/qt/ui/EbuildDialog.ui88
-rw-r--r--portato/gui/qt/ui/PreferenceWindow.ui4
-rw-r--r--portato/gui/qt/windows.py29
4 files changed, 229 insertions, 2 deletions
diff --git a/portato/gui/qt/highlighter.py b/portato/gui/qt/highlighter.py
new file mode 100644
index 0000000..5572930
--- /dev/null
+++ b/portato/gui/qt/highlighter.py
@@ -0,0 +1,110 @@
+# -*- coding: utf-8 -*-
+#
+# File: portato/gui/qt/highlighter.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>
+
+# The syntax is inspired by the gtksourceview syntax by
+# Leonardo Ferreira Fontenelle <leo.fontenelle@gmail.com>
+
+from PyQt4 import Qt
+from portato.helper import debug
+
+import re # prefer Python-Module over Qt-one
+
+class EbuildHighlighter (Qt.QSyntaxHighlighter):
+
+ NORMAL_STATE = 0
+ STRING_STATE = 1
+
+ def __init__ (self, edit):
+ Qt.QSyntaxHighlighter.__init__(self, edit)
+
+ self.comment = self.__create(r'#.*', color = "steelblue", italic = True)
+ self.bashVar = self.__create(r'(\$\{.+?\})|(\$\w+)', color = "green")
+
+ self.syntax = {}
+ self.syntax["bashSyn"] = self.__create(r'\b(case|do|done|elif|else|esac|exit|fi|for|function|if|in|local|read|return|select|shift|then|time|until|while)\b', color = "navy", underline = True)
+
+ self.syntax["bashCmd"] = self.__create(r'\b(make|awk|cat|cd|chmod|chown|cp|echo|env|export|grep|head|let|ln|mkdir|mv|rm|sed|set|tail|tar|touch|unset)\b', color = "navy", bold = True)
+
+ self.syntax["portVar"] = self.__create(r'\b((ARCH|HOMEPAGE|DESCRIPTION|IUSE|SRC_URI|LICENSE|SLOT|KEYWORDS|FILESDIR|WORKDIR|(P|R)?DEPEND|PROVIDE|DISTDIR|RESTRICT|USERLAND)|(S|D|T|PV|PF|P|PN|A)|C(XX)?FLAGS|LDFLAGS|C(HOST|TARGET|BUILD))\b', color = "saddlebrown", bold = True)
+
+ self.syntax["portCmd"] = self.__create(r'\b(e(begin|end|conf|install|make|warn|infon?|error|patch)|die|built_with_use|use(_(with|enable))?|inherit|hasq?|(has|best)_version|unpack|(do|new)(ins|s?bin|doc|lib(|\.so|\.a)|man|info|exe|initd|confd|envd|pam|menu|icon)|do(python|sed|dir|hard|sym|html|jar|mo)|keepdir|prepall(|docs|info|man|strip)|prep(info|lib|lib\.(so|a)|man|strip)|(|doc|ins|exe)into|f(owners|perms)|(exe|ins|dir)opts)\b', color = "saddlebrown", bold = True)
+
+ self.syntax["portFunc"] = self.__create(r'^(src_(unpack|compile|install|test)|pkg_(config|nofetch|setup|(pre|post)(inst|rm)))', color = "green")
+
+ self.string = self.__create(r'(?<!\\)"', color = "fuchsia")
+
+ def do_reg_exp (self, syntaxTuple, string):
+ regexp, format = syntaxTuple
+
+ match = regexp.search(string)
+
+ while match is not None:
+ span = match.span()
+ length = span[1]-span[0]
+
+ self.setFormat(span[0], length, format)
+ match = regexp.search(string, span[1])
+
+ def highlightBlock (self, string):
+ string = str(string) # we got a QString here
+
+ for t in self.syntax.values():
+ self.do_reg_exp(t, string)
+
+ self.setCurrentBlockState(self.NORMAL_STATE)
+
+ # look for strings
+ prevStart = 0
+ foundEnd = False
+ stringMatch = self.string[0].search(string)
+ if self.previousBlockState() == self.STRING_STATE:
+ if stringMatch is None:
+ self.setFormat(0, len(string), self.string[1])
+ self.setCurrentBlockState(self.STRING_STATE)
+ else:
+ foundEnd = True
+
+ while stringMatch is not None:
+
+ if foundEnd:
+ self.setCurrentBlockState(self.NORMAL_STATE)
+ self.setFormat(prevStart, stringMatch.end() - prevStart, self.string[1])
+ stringMatch = self.string[0].search(string, stringMatch.end())
+ foundEnd = False
+ else:
+ prevStart = stringMatch.start()
+ stringMatch = self.string[0].search(string, stringMatch.end())
+ if stringMatch is not None:
+ foundEnd = True
+ else:
+ self.setCurrentBlockState(self.STRING_STATE)
+ self.setFormat(prevStart, len(string) - prevStart, self.string[1])
+
+ self.do_reg_exp(self.bashVar, string) # replace bashVars in strings
+ self.do_reg_exp(self.comment, string) # do comments last
+
+ def __create (self, regexp, color = None, italic = False, bold = False, underline = False):
+
+ compRe = re.compile(regexp)
+ format = Qt.QTextCharFormat()
+
+ font = Qt.QFont()
+ font.setItalic(italic)
+ font.setBold(bold)
+ font.setUnderline(underline)
+ format.setFont(font)
+
+ if color is not None:
+ brush = Qt.QBrush(Qt.QColor(color))
+ format.setForeground(brush)
+
+ return (compRe, format)
diff --git a/portato/gui/qt/ui/EbuildDialog.ui b/portato/gui/qt/ui/EbuildDialog.ui
new file mode 100644
index 0000000..831a93b
--- /dev/null
+++ b/portato/gui/qt/ui/EbuildDialog.ui
@@ -0,0 +1,88 @@
+<ui version="4.0" >
+ <class>EbuildDialog</class>
+ <widget class="QDialog" name="EbuildDialog" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>481</width>
+ <height>603</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QTextEdit" name="ebuildEdit" >
+ <property name="undoRedoEnabled" >
+ <bool>false</bool>
+ </property>
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ <property name="cursorWidth" >
+ <number>0</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons" >
+ <set>QDialogButtonBox::Ok</set>
+ </property>
+ <property name="centerButtons" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>EbuildDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>EbuildDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/portato/gui/qt/ui/PreferenceWindow.ui b/portato/gui/qt/ui/PreferenceWindow.ui
index f65c2fa..6ac29e8 100644
--- a/portato/gui/qt/ui/PreferenceWindow.ui
+++ b/portato/gui/qt/ui/PreferenceWindow.ui
@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>582</width>
- <height>706</height>
+ <width>570</width>
+ <height>729</height>
</rect>
</property>
<property name="windowTitle" >
diff --git a/portato/gui/qt/windows.py b/portato/gui/qt/windows.py
index 3b1de2b..b2949bd 100644
--- a/portato/gui/qt/windows.py
+++ b/portato/gui/qt/windows.py
@@ -25,6 +25,7 @@ from portato.gui.gui_helper import Database, Config, EmergeQueue
# own GUI stuff
from terminal import QtConsole
from tree import QtTree
+from highlighter import EbuildHighlighter
from dialogs import *
from helper import qCheck, qIsChecked
@@ -112,6 +113,30 @@ class SearchDialog (Window):
self.done(0)
self.jumpTo(s)
+class EbuildDialog (Window):
+
+ __metaclass__ = WindowMeta
+
+ def __init__ (self, parent, package):
+
+ Window.__init__(self, parent)
+
+ self.setWindowTitle(package.get_cpv())
+
+ self.doc = Qt.QTextDocument()
+ self.hl = EbuildHighlighter(self.doc)
+
+ try: # read ebuild
+ f = open(package.get_ebuild_path(), "r")
+ lines = f.readlines()
+ f.close()
+ except IOError,e:
+ io_ex_dialog(self, e)
+ return
+
+ self.doc.setPlainText("".join(lines))
+ self.ebuildEdit.setDocument(self.doc)
+
class PreferenceWindow (Window):
"""Window displaying some preferences."""
@@ -202,6 +227,7 @@ class PackageDetails:
Qt.QObject.connect(self.window.pkgEmergeBtn, Qt.SIGNAL("clicked()"), self.cb_emerge_clicked)
Qt.QObject.connect(self.window.pkgUnmergeBtn, Qt.SIGNAL("clicked()"), self.cb_unmerge_clicked)
Qt.QObject.connect(self.window.pkgRevertBtn, Qt.SIGNAL("clicked()"), self.cb_revert_clicked)
+ Qt.QObject.connect(self.window.pkgEbuildBtn, Qt.SIGNAL("clicked()"), self.cb_ebuild_clicked)
# checkboxes
Qt.QObject.connect(self.window.maskedCheck, Qt.SIGNAL("clicked(bool)"), self.cb_masked_clicked)
@@ -326,6 +352,9 @@ class PackageDetails:
return self.packages[self.window.versCombo.currentIndex()]
+ def cb_ebuild_clicked (self):
+ EbuildDialog(self.window, self.actual_package()).exec_()
+
def cb_emerge_clicked (self):
"""Callback for pressed emerge-button. Adds the package to the EmergeQueue."""
if not am_i_root():