From 7a6f5b2c1d83fe62c62f0c30cad28eb091d52dfe Mon Sep 17 00:00:00 2001
From: necoro <>
Date: Fri, 20 Apr 2007 14:44:45 +0000
Subject: Made qt plugin-ready; lots of documentation
---
portato/gui/qt/helper.py | 13 +++++
portato/gui/qt/highlighter.py | 74 ++++++++++++++++++++++++---
portato/gui/qt/terminal.py | 71 ++++++++++++++++++++------
portato/gui/qt/ui/AboutDialog.ui | 105 ++++++++++++++++++++++++++++++---------
portato/gui/qt/ui/MainWindow.ui | 12 ++---
portato/gui/qt/windows.py | 67 +++++++++++++++++++++++--
6 files changed, 288 insertions(+), 54 deletions(-)
(limited to 'portato/gui/qt')
diff --git a/portato/gui/qt/helper.py b/portato/gui/qt/helper.py
index 1b7dbdc..fa1576a 100644
--- a/portato/gui/qt/helper.py
+++ b/portato/gui/qt/helper.py
@@ -13,10 +13,23 @@
from PyQt4 import Qt
def qCheck (check):
+ """Maps True or False to Qt.Checked or Qt.Unchecked.
+
+ @param check: boolean value
+ @type check: bool
+ @returns: CheckState-Constant
+ @rtype: int"""
+
if check:
return Qt.Qt.Checked
else:
return Qt.Qt.Unchecked
def qIsChecked (check):
+ """Maps Qt.Checked and Qt.Unchecked to True and False.
+
+ @param check: CheckState-Constant
+ @type check: int
+ @returns: appropriate boolean value
+ @rtype: bool"""
return check == Qt.Qt.Checked
diff --git a/portato/gui/qt/highlighter.py b/portato/gui/qt/highlighter.py
index 5572930..74d9ac9 100644
--- a/portato/gui/qt/highlighter.py
+++ b/portato/gui/qt/highlighter.py
@@ -19,30 +19,59 @@ from portato.helper import debug
import re # prefer Python-Module over Qt-one
class EbuildHighlighter (Qt.QSyntaxHighlighter):
+ """A QSyntaxHighlighter implementation for the use with ebuild-syntax."""
NORMAL_STATE = 0
STRING_STATE = 1
def __init__ (self, edit):
+ """Constructor.
+
+ @param edit: the EditWidget to use the highlighter with
+ @type edit: Qt.QTextEdit"""
+
Qt.QSyntaxHighlighter.__init__(self, edit)
+ #
+ # the regular expressions ... *muahahaha*
+ #
+
+ # comments
self.comment = self.__create(r'#.*', color = "steelblue", italic = True)
+
+ # bash variables
self.bashVar = self.__create(r'(\$\{.+?\})|(\$\w+)', color = "green")
+ # a string
+ self.string = self.__create(r'(? reload format
self.setCurrentCharFormat(self.get_format())
else:
@@ -97,13 +114,16 @@ class QtConsole (Console, Qt.QTextEdit):
self.ensureCursorVisible()
def write(self, text):
+ """Convenience function for emitting the writing signal."""
self.emit(Qt.SIGNAL("doSomeWriting"), text)
def start_new_thread (self):
- self.run = True
- self.current = Thread(target=self.__run, name="QtTerminal Listener")
- self.current.setDaemon(True) # close application even if this thread is running
- self.current.start()
+ """Starts a new thread, which will listen for some input.
+ @see: QtTerminal.__run()"""
+ self.run = True
+ self.current = Thread(target=self.__run, name="QtTerminal Listener")
+ self.current.setDaemon(True) # close application even if this thread is running
+ self.current.start()
def set_pty (self, pty):
if not self.running:
@@ -111,21 +131,22 @@ class QtConsole (Console, Qt.QTextEdit):
self.start_new_thread()
self.running = True
- else:
- # quit current thread
+ else: # quit current thread
self.run = False
- # self.current.join()
self.clear()
self.pty = pty # set this after clearing to lose no chars :)
self.start_new_thread()
def __run (self):
+ """This function is mainly a loop, which looks for some new input at the terminal,
+ and parses it for text attributes."""
+
while self.run:
s = read(self.pty, 1)
- if s == "": break
+ if s == "": break # nothing read -> finish
- if ord(s) == backspace:
+ if ord(s) == backspace: # BS
self.emit(Qt.SIGNAL("deletePrevChar()"))
continue
@@ -154,9 +175,16 @@ class QtConsole (Console, Qt.QTextEdit):
self.write(s)
def parse_seq (self, seq):
- global attr
+ """Parses a sequence of bytes.
+ If a new attribute has been encountered, a new format is created and added
+ to the internal format queue.
+
+ @param seq: sequence to parse
+ @type seq: string"""
+
+ global attr # the dict of attributes
- format = self.virgin_format()
+ format = self.virgin_format()
if seq != reset_seq: # resettet -> done
seq = seq.split(seq_sep)
@@ -178,10 +206,9 @@ class QtConsole (Console, Qt.QTextEdit):
break
self.add_format(format)
- self.write(esc_seq[0])
+ self.write(esc_seq[0]) # write \x1b to signal the occurence of a new format
def parse_title (self, seq):
-
if not seq.startswith("0;"):
return
@@ -191,15 +218,31 @@ class QtConsole (Console, Qt.QTextEdit):
return self.title
def add_format (self, format):
+ """Adds a format to the queue.
+ We have to take a queue, because the write-signals might occur asynchronus,
+ so we set a format for the wrong characters.
+
+ @param format: the format to add
+ @type format: Qt.QTextCharFormat"""
+
self.formatLock.acquire()
self.formatQueue.append(format)
self.formatLock.release()
def get_format (self):
+ """Returns a format from the queue.
+ We have to take a queue, because the write-signals might occur asynchronus,
+ so we set a format for the wrong characters.
+
+ @returns: the popped format
+ @rtype: Qt.QTextCharFormat"""
+
self.formatLock.acquire()
f = self.formatQueue.pop(0)
self.formatLock.release()
return f
def virgin_format (self):
+ """The normal standard format. It is necessary to create it as a new one for some
+ dubious reasons ... only Qt.QGod knows why."""
return Qt.QTextCharFormat(self.stdFormat)
diff --git a/portato/gui/qt/ui/AboutDialog.ui b/portato/gui/qt/ui/AboutDialog.ui
index 5ed35e2..1424270 100644
--- a/portato/gui/qt/ui/AboutDialog.ui
+++ b/portato/gui/qt/ui/AboutDialog.ui
@@ -9,7 +9,7 @@
0
0
369
- 279
+ 270
@@ -23,31 +23,90 @@
6
-
-
-
- TextLabel
-
-
- Qt::AlignCenter
-
-
- true
+
+
+ 0
+
+
+ About
+
+
+
+ 9
+
+
+ 6
+
+
-
+
+
+ TextLabel
+
+
+ Qt::AlignCenter
+
+
+ true
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+
+
+ Plugins
+
+
+
+ 9
+
+
+ 6
+
+ -
+
+
+ QAbstractItemView::NoEditTriggers
+
+
+ false
+
+
+ false
+
+
+ 2
+
+
+
+ 1
+
+
+
+
+ 1
+
+
+
+
+
+
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 40
-
-
-
-
-
diff --git a/portato/gui/qt/ui/MainWindow.ui b/portato/gui/qt/ui/MainWindow.ui
index 80c5c12..5b8d0d9 100644
--- a/portato/gui/qt/ui/MainWindow.ui
+++ b/portato/gui/qt/ui/MainWindow.ui
@@ -403,7 +403,7 @@ p, li { white-space: pre-wrap; }
27
-