SF.net SVN: fclient:[716] trunk/fclient/src/fclient/lib
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-21 12:49:29
|
Revision: 716
http://fclient.svn.sourceforge.net/fclient/?rev=716&view=rev
Author: jUrner
Date: 2008-07-21 12:45:47 +0000 (Mon, 21 Jul 2008)
Log Message:
-----------
add compactpath package, we might need it
Added Paths:
-----------
trunk/fclient/src/fclient/lib/compactpath/
trunk/fclient/src/fclient/lib/compactpath/LICENCE.MIT
trunk/fclient/src/fclient/lib/compactpath/README
trunk/fclient/src/fclient/lib/compactpath/__init__.py
trunk/fclient/src/fclient/lib/compactpath/compactpath.py
trunk/fclient/src/fclient/lib/compactpath/qt4/
trunk/fclient/src/fclient/lib/compactpath/qt4/__init__.py
trunk/fclient/src/fclient/lib/compactpath/qt4/pathlabelwrap.py
trunk/fclient/src/fclient/lib/compactpath/qt4/sample_gui.py
trunk/fclient/src/fclient/lib/compactpath/scripts/
trunk/fclient/src/fclient/lib/compactpath/scripts/__init__.py
trunk/fclient/src/fclient/lib/compactpath/scripts/gen_docs.py
Added: trunk/fclient/src/fclient/lib/compactpath/LICENCE.MIT
===================================================================
--- trunk/fclient/src/fclient/lib/compactpath/LICENCE.MIT (rev 0)
+++ trunk/fclient/src/fclient/lib/compactpath/LICENCE.MIT 2008-07-21 12:45:47 UTC (rev 716)
@@ -0,0 +1,24 @@
+"compactpath" is a python package to handle compacting of filepaths
+
+Copyright (c) 2006-2008 Juergen Urner
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in the
+Software without restriction, including without limitation the rights to use, copy,
+modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+and to permit persons to whom the Software is furnished to do so, subject to the
+following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+
Added: trunk/fclient/src/fclient/lib/compactpath/README
===================================================================
--- trunk/fclient/src/fclient/lib/compactpath/README (rev 0)
+++ trunk/fclient/src/fclient/lib/compactpath/README 2008-07-21 12:45:47 UTC (rev 716)
@@ -0,0 +1,71 @@
+"compactpath" is a python package to handle compacting of filepaths
+
+project web: https://sourceforge.net/projects/compactpath/
+
+
+
+Version history
+#*******************************************************************
+compactpath 0.5.0
+#********************************************************************
+release: 06/15/2008
+
+did a complete rewrite of the package. sorry for any inconveniences and incompatibilities
+
+news:
+
+ x. reimplemented compactpath algo. bells and whistels have gone. this makes it ~15x faster
+ x. combed over PathLabelWrap (qt4). styling and enabling / disabling works now
+ x. added a script to auto generate epydoc docs. you will find it in the [scripts] folder
+
+
+fixes:
+
+
+incompatibilieites:
+
+ x. the "compactPath" function is named "compactpath" now
+ x. the function takes the desired width as first parameter now --> compactpath(w, fpath)
+ x. the keyword parameters "type" has gone. use "path_module" now
+ x. the keyword "max_pardirs" has gone. not supported anymore
+
+ x. qt4 implementations of the algo have been moved to --> compactpath/qt4/*
+ use: from compactpath.qt4 import <whatever>
+
+ x. PathLabelWrap (qt3) has gone. that is, no more support for qt3
+
+ x. PathLabelWrap (qt4) getPath() method is now PathLabelWrap.path()
+ x. the keyword parameters "type" has gone. use "path_module" now
+ x. the keyword "max_pardirs" has gone. not supported anymore
+
+ x. documentation is now uses epydoc markup
+
+
+#*******************************************************************
+compactpath 0.4.2
+#********************************************************************
+news:
+ x. PathLabelWrap.setPath() now takes the same keywords as constructor
+
+fixes:
+
+ x. root of nt posix paths was chewed off emidiately - fixed
+ x. root of mac paths was chewed off to soon - fixed
+
+
+#*******************************************************************
+compactpath 0.4.1
+#********************************************************************
+news:
+
+ x. updated inline docs ("sep" keyword was still there. This has changed to "type")
+
+
+#*******************************************************************
+compactpath 0.4.0
+#********************************************************************
+news:
+
+ x. added support for mac paths.
+ x. removed the "sep" keyword argument. Use the "type" keyword to explicitely
+ specify the type of path to be compacted if required.
\ No newline at end of file
Added: trunk/fclient/src/fclient/lib/compactpath/__init__.py
===================================================================
--- trunk/fclient/src/fclient/lib/compactpath/__init__.py (rev 0)
+++ trunk/fclient/src/fclient/lib/compactpath/__init__.py 2008-07-21 12:45:47 UTC (rev 716)
@@ -0,0 +1,16 @@
+"""compact a filepath to fit into a desired width
+
+@note: the package is designed so you can drop it into any project
+and use it right away. no need to install it to --> lib/site-packages
+
+@note: you may use --> scripts/gen_docs.py to generate epydoc documentation for the package
+
+"""
+__author__ = 'Juergen Urner'
+__copyright__ = '(c) 2006-2008 Juergen Urner'
+__email__ = 'jU...@ar...'
+__licence__ = 'Mit'
+__version__ = '0.5.0'
+
+
+
Added: trunk/fclient/src/fclient/lib/compactpath/compactpath.py
===================================================================
--- trunk/fclient/src/fclient/lib/compactpath/compactpath.py (rev 0)
+++ trunk/fclient/src/fclient/lib/compactpath/compactpath.py 2008-07-21 12:45:47 UTC (rev 716)
@@ -0,0 +1,180 @@
+"""compactpath algorithm
+
+compacts a filepath to fit into a desired length by replacing chars with ellipsis. the funktion
+preserves the last component of the filepath as long as possible. assumption is that this component
+is of major importance for the user.
+"""
+
+import os
+#****************************************************************************************************
+# consts
+#****************************************************************************************************
+ELLIPSIS = '...'
+
+#****************************************************************************************************
+# helpers
+#****************************************************************************************************
+def rtrunc(n, chars, ellipsis=ELLIPSIS):
+ """truncates a string to from the right to the desired number of chars, replacing chars with ellipsis
+
+ @param n: (int) desired number of truncated chars
+ @param chars: (str) chars to truncate
+ @param ellipsis: (str) ellipsis to use for char substitution
+ @return: (str) the truncated string
+
+ >>> rtrunc(4, 'abcd')
+ '...d'
+
+ >>> rtrunc(99, 'abc')
+ '...'
+
+ >>> rtrunc(1, 'abc')
+ '.'
+
+ >>> rtrunc(0, 'abc')
+ ''
+
+ >>> rtrunc(-1, 'abc')
+ ''
+
+ >>> ellipsis = '01234'
+ >>> for n in range(len(ellipsis), 0, -1):
+ ... rtrunc(n, ellipsis, ellipsis=ellipsis)
+ '01234'
+ '1234'
+ '234'
+ '34'
+ '4'
+ """
+ if n > len(chars):
+ n = len(chars)
+ if n < 0:
+ n = 0
+ x = len(ellipsis) - n
+ if x < 0:
+ x = 0
+ e = ellipsis[x:]
+ return e + chars[len(chars) - n + len(e): ]
+
+
+def ltrunc(n, chars, ellipsis=ELLIPSIS):
+ """truncates a string to from the left to the desired number of chars, replacing chars with ellipsis
+
+ @param n: (int) desired number of truncated chars
+ @param chars: (str) chars to truncate
+ @param ellipsis: (str) ellipsis to use for char substitution
+ @return: (str) the truncated string
+
+ >>> ltrunc(4, 'abcd')
+ 'a...'
+
+ >>> ltrunc(99, 'abc')
+ '...'
+
+ >>> ltrunc(1, 'abc')
+ '.'
+
+ >>> ltrunc(0, 'abc')
+ ''
+
+ >>> ltrunc(-1, 'abc')
+ ''
+ >>> ellipsis = '01234'
+ >>> for n in range(len(ellipsis), 0, -1):
+ ... ltrunc(n, ellipsis, ellipsis=ellipsis)
+ '01234'
+ '0123'
+ '012'
+ '01'
+ '0'
+ """
+ if n > len(chars):
+ n = len(chars)
+ if n < 0:
+ n = 0
+ e = ellipsis[:n]
+ return chars[ :n - len(e)] + e
+
+#************************************************************************************************
+#
+#************************************************************************************************
+#NOTE:
+# a nicer but more complicated (and slower) implementation would preserve
+# components more intelligently. e.g. the emidiate parent component of the
+# last component would be preserved longer than some intermediate component
+
+def compactpath(w, fpath, measure=len, ellipsis=ELLIPSIS, path_module=os.path):
+ """compacts a filepath to fit into a desired width
+
+ @param fpath: (str) filepath to compact
+ @param measure: function to measure length of the filepath. the function
+ should take one parameter: the filepath and should return its length
+ @param ellipsis: (str) ellipsis to use for char substitution
+ @param path_module: path module to use to split and join filepath
+
+ @note: you can always assume that on return measure(fpath) is < w
+ for measure(fpath) > 0
+
+
+ >>> import posixpath
+ >>> compactpath(10, '/aaa/bbb/ccc', path_module=posixpath)
+ '/a.../ccc'
+
+ >>> compactpath(0, '', path_module=posixpath)
+ ''
+
+ >>> compactpath(-1, '', path_module=posixpath)
+ ''
+
+ >>> p = 'aaa/bbb/ccc'
+ >>> for n in range(len(p), 0, -1):
+ ... compactpath(n, p, path_module=posixpath)
+ 'aaa.../ccc'
+ 'aa.../ccc'
+ 'a.../ccc'
+ '.../ccc'
+ '...ccc'
+ '...cc'
+ '...c'
+ '...'
+ '..'
+ '.'
+ ''
+ """
+ if measure(fpath) < w:
+ return fpath
+
+ if w > 0:
+ head, tail = path_module.split(fpath)
+ n = len(head)
+
+ while n >= len(ellipsis):
+ head = ltrunc(n, head, ellipsis=ellipsis)
+ n -= 1
+ fpath = path_module.join(head, tail)
+ if measure(fpath) < w:
+ return fpath
+
+ if head == ellipsis:
+ tail = ellipsis + tail
+ n = len(tail) - 1
+ elif head:
+ tail = path_module.join(head, tail, ellipsis=ellipsis)
+ n = len(tail)
+ else:
+ n = len(tail)
+
+ while tail:
+ if measure(tail) < w:
+ return tail
+ tail = rtrunc(n, tail)
+ n -= 1
+
+ return ''
+
+#************************************************************************************************
+#
+#************************************************************************************************
+if __name__ == '__main__':
+ import doctest
+ print 'doctests failed: %s/%s' % doctest.testmod()
Added: trunk/fclient/src/fclient/lib/compactpath/qt4/__init__.py
===================================================================
--- trunk/fclient/src/fclient/lib/compactpath/qt4/__init__.py (rev 0)
+++ trunk/fclient/src/fclient/lib/compactpath/qt4/__init__.py 2008-07-21 12:45:47 UTC (rev 716)
@@ -0,0 +1 @@
+"""compactpath implementations for qt4"""
Added: trunk/fclient/src/fclient/lib/compactpath/qt4/pathlabelwrap.py
===================================================================
--- trunk/fclient/src/fclient/lib/compactpath/qt4/pathlabelwrap.py (rev 0)
+++ trunk/fclient/src/fclient/lib/compactpath/qt4/pathlabelwrap.py 2008-07-21 12:45:47 UTC (rev 716)
@@ -0,0 +1,226 @@
+"""QLabel wrapper to turn a QLabel into a label that displays a compacted filepath
+"""
+
+import os, sys
+from PyQt4 import QtCore, QtGui
+
+#--> rel import hack
+class SysPathHack(object):
+ def __init__(self, n):
+ fpath = os.path.abspath(__file__)
+ for i in xrange(n): fpath = os.path.dirname(fpath)
+ sys.path.insert(0, fpath)
+ def __del__(self): sys.path.pop(0)
+hack = SysPathHack(2)
+
+from compactpath import compactpath
+
+del hack
+#<-- rel import hack
+#********************************************************************************
+#
+#********************************************************************************
+class PathLabelWrap(object):
+ """class wrapping a QLabel to display a filepath or url that is compacted or decompacted on resizing of the label
+
+ usage::
+ # create a label in designer or wherever and wrap it afterwards
+ self.wrap = PathLabelWrap(self.myLabel, '/foo/bar/baz', prefix='MyPath: ')
+
+ @ivar fpath: filepath wrapped. setting this attr directly will not update the label. use L{setPath} instead
+ @ivar label: the QLabel wrapped
+ @ivar path_module: module to use to split and join the filepath. setting this attr directly will not update the label. use L{setPath} instead
+ @ivar prefix: fixed size string to prefix the filepath with. setting this attr directly will not update the label. use L{setPath} instead
+ """
+
+ def __init__(self, label, fpath='', prefix='', path_module=os.path):
+ """constructor
+
+ @param label: an initialized QLabel to wrap compactPath funktionality around
+ @param fpath: the filepath or url the label should display
+ @param path_module: module to use to split and join the filepath. hint: if you want
+ to display a macpath on linux pass macpath.
+ @param prefix: fixed size string to prefix the filepath with (will never be compacted)
+
+ @note: problem to tackle is that qt adjusts the size of any label to fit its contents. this wrapper
+ does it vice versa and adjusts the contents to the size of the label. so by default qt has to assume
+ the label is empty. you can set a text to the label (wich never gets displayed) to force a minimum label size
+
+ @note: currently the wrapper does not know how anything about rich text. no use to pass
+ a label containing rich text. the rich text it won't show up and behaviour of the label is undefined
+
+ @note: when used on a statusbar you may want to adjust the stretch facor. otherwise label
+ contents may not be visible because it never gets resized
+ """
+ self.fpath = fpath
+ self.label = label
+ self.path_module = path_module
+ self.prefix = prefix
+
+ self.label.paintEvent = self.paintEvent # overwrite
+
+
+ def setPath(self, fpath, prefix=None, path_module=None):
+ """sets the filepath to be displayed by the label
+
+ @param fpath: the filepath or url the label should display
+ @param path_module: module to use to split and join the filepath or None to keep the current one
+ @param prefix: fixed size string to prefix the filepath with (will never be compacted) or None to keep the current one
+ """
+ if prefix is not None:
+ self.prefix = prefix
+ if path_module is not None:
+ path_module = path_module
+ self.fpath = fpath
+ self.label.update()
+
+
+ def path(self):
+ """retrieves the (uncompacted) filepath wrapped
+ """
+ return self.fpath
+
+
+ def paintEvent(self, event):
+ """reimplemented QLabel.paintEvent()"""
+ style = self.label.style()
+ painter = QtGui.QPainter(self.label)
+ palette = self.label.palette()
+ fm = self.label.fontMetrics()
+ cr = self.label.contentsRect()
+ align = style.visualAlignment(self.label.layoutDirection(), self.label.alignment())
+
+ cr.adjust(self.label.margin(), self.label.margin(), -self.label.margin(), -self.label.margin())
+
+ indent = self.label.indent()
+ if indent < 0: # see Qt docs: label.indent()
+ if indent > 0:
+ indent = fm.width("x") / 2
+ else:
+ indent = 0
+ if indent > 0:
+ if align & QtCore.Qt.AlignLeft:
+ cr.setLeft( cr.left() + indent);
+ if align & QtCore.Qt.AlignRight:
+ cr.setRight(cr.right() - indent)
+ if align & QtCore.Qt.AlignTop:
+ cr.setTop(cr.top() + indent)
+ if align & QtCore.Qt.AlignBottom:
+ cr.setBottom(cr.bottom() - indent)
+
+ w = cr.width()
+ if self.prefix:
+ w -= fm.width(self.prefix)
+ fpath = compactpath(
+ w,
+ self.fpath,
+ measure=fm.width,
+ path_module=self.path_module
+ )
+ self.label.drawFrame(painter)
+ style.drawItemText(painter, cr, align, palette, self.label.isEnabled(), self.prefix + fpath, self.label.foregroundRole())
+
+
+ #************************************************************************************************
+ # the original QLabel.painEvent() handler (for readability pixmap and movie stuff removed)
+ # quite a beast with calls to obscure private methods ...the reason why PathLabelWrap() currently
+ # does not support rich text
+ #
+ # as a hint: QTextDocument can be retrieved like this:
+ ##textDocument = None
+ ##for i in self.label.children():
+ ## for j in i.children():
+ ## if isinstance(j, QtGui.QTextDocument):
+ ## textDocument = j
+ ##
+ ##if textDocument is not None:
+ ## # process
+
+ """
+ void QLabel::paintEvent(QPaintEvent *)
+ {
+ Q_D(QLabel);
+ QStyle *style = QWidget::style();
+ QPainter painter(this);
+ drawFrame(&painter);
+ QRect cr = contentsRect();
+ cr.adjust(d->margin, d->margin, -d->margin, -d->margin);
+ int align = QStyle::visualAlignment(layoutDirection(), QFlag(d->align));
+
+
+ if (d->isTextLabel) {
+ QRectF lr = d->layoutRect();
+ if (d->control) {
+ #ifndef QT_NO_SHORTCUT
+ const bool underline = (bool)style->styleHint(QStyle::SH_UnderlineShortcut, 0, this, 0);
+ if (d->shortcutId != 0
+ && underline != d->shortcutCursor.charFormat().fontUnderline()) {
+ QTextCharFormat fmt;
+ fmt.setFontUnderline(underline);
+ d->shortcutCursor.mergeCharFormat(fmt);
+ }
+ #endif
+ d->ensureTextLayouted();
+
+ QAbstractTextDocumentLayout::PaintContext context;
+ QStyleOption opt(0);
+ opt.init(this);
+
+ if (!isEnabled() && style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) {
+ context.palette = palette();
+ context.palette.setColor(QPalette::Text, context.palette.light().color());
+ painter.save();
+ painter.translate(lr.x() + 1, lr.y() + 1);
+ painter.setClipRect(lr.translated(-lr.x() - 1, -lr.y() - 1));
+ QAbstractTextDocumentLayout *layout = d->control->document()->documentLayout();
+ layout->draw(&painter, context);
+ painter.restore();
+ }
+
+ // Adjust the palette
+ context.palette = palette();
+ if (foregroundRole() != QPalette::Text && isEnabled())
+ context.palette.setColor(QPalette::Text, context.palette.color(foregroundRole()));
+
+ painter.save();
+ painter.translate(lr.topLeft());
+ painter.setClipRect(lr.translated(-lr.x(), -lr.y()));
+ d->control->setPalette(context.palette);
+ d->control->drawContents(&painter, QRectF(), this);
+ painter.restore();
+ } else {
+ int flags = align;
+ if (d->hasShortcut) {
+ flags |= Qt::TextShowMnemonic;
+ QStyleOption opt;
+ opt.initFrom(this);
+ if (!style->styleHint(QStyle::SH_UnderlineShortcut, &opt, this))
+ flags |= Qt::TextHideMnemonic;
+ }
+ style->drawItemText(&painter, lr.toRect(), flags, palette(), isEnabled(), d->text, foregroundRole());
+ }
+ } else
+ #ifndef QT_NO_PICTURE
+
+ (...)
+
+ """
+
+#******************************************************************************
+#
+#******************************************************************************
+if __name__ == "__main__":
+
+ # for playing around...
+ a = QtGui.QApplication(sys.argv)
+ QtCore.QObject.connect(a,QtCore.SIGNAL("lastWindowClosed()"),a,QtCore.SLOT("quit()"))
+ w = QtGui.QLabel('aaa')
+ w.setIndent(39)
+ w.setStyleSheet('QLabel {background: yellow; border: 1py solid black}')
+ w.setTextFormat(QtCore.Qt.RichText)
+
+ PathLabelWrap(w, os.path.join(*[i*5 for i in 'abcdefg']))
+ w.show()
+ a.exec_()
+
+
\ No newline at end of file
Added: trunk/fclient/src/fclient/lib/compactpath/qt4/sample_gui.py
===================================================================
--- trunk/fclient/src/fclient/lib/compactpath/qt4/sample_gui.py (rev 0)
+++ trunk/fclient/src/fclient/lib/compactpath/qt4/sample_gui.py 2008-07-21 12:45:47 UTC (rev 716)
@@ -0,0 +1,122 @@
+"""qt4 sample gui"""
+
+import os, sys
+import ntpath
+import macpath
+import posixpath
+
+from PyQt4 import QtCore, QtGui
+
+
+#--> rel import hack
+class SysPathHack(object):
+ def __init__(self, n):
+ fpath = os.path.abspath(__file__)
+ for i in xrange(n): fpath = os.path.dirname(fpath)
+ sys.path.insert(0, fpath)
+ def __del__(self): sys.path.pop(0)
+hack = SysPathHack(1)
+
+from pathlabelwrap import PathLabelWrap, compactpath
+
+del hack
+#<-- rel import hack
+#********************************************************************************
+# test GUI
+#*******************************************************************************
+CAPTION = "compactPath - [%s]"
+PATHS = (
+ (posixpath, "/my/very/long/path/containing/many/compoponents/here.txt"),
+ (ntpath, "c:\\my\\very\\long\\path\\containing\\many\\compoponents\\here.txt"),
+ (macpath, "my:very:long:path:containing:many:compoponents:here.txt"),
+ (posixpath, "http://my/very/long/path/containing/many/compoponents/here.txt"),
+ )
+BLINDTEXT = "xxxxxxxxxx" # this is set as text to the labels to force a minimum size. Adjust to your needs
+
+#******************************************************************************
+#
+#******************************************************************************
+class SampleGui(QtGui.QMainWindow):
+ """test gui"""
+
+ def __init__(self):
+ QtGui.QMainWindow.__init__(self)
+
+ self.mainWidget = QtGui.QWidget(self)
+ self.setCentralWidget(self.mainWidget)
+
+ # NOTE:
+ #
+ # too bad, no label or the like is retrievable for the caption bar. so no way to adjust it anything
+ # on the caption dynamically. best practice seems to be to init to some fixed width. plus is that
+ # the width of the caption bar label seems to have no effect on the GUI width. but this may
+ # vary from window manager to window manager.
+ #
+ pathModule, fpath = PATHS[0]
+ fpath = compactpath(50 - len(CAPTION), fpath, path_module=pathModule)
+ self.setWindowTitle(CAPTION % fpath)
+
+
+ def newPathlabelWrap(mainWidget, layout, frameStyle, pathModule, fpath, prefix=None):
+ label = QtGui.QLabel(BLINDTEXT, mainWidget)
+ label.setFrameStyle(frameStyle)
+ layout.addWidget(label)
+ if prefix is None:
+ prefix = pathModule.__name__ + ': '
+ wrap = PathLabelWrap(label, fpath=fpath, prefix=prefix, path_module=pathModule)
+ mainWidget.pathLabels.append(wrap)
+ return wrap
+
+ # throw labels into the Gui
+ layout = QtGui.QVBoxLayout(self.centralWidget())
+ frameStyle = QtGui.QLabel.Sunken | QtGui.QLabel.Box
+ self.pathLabels = []
+ for pathModule, fpath in PATHS:
+ newPathlabelWrap(self, layout, frameStyle, pathModule, fpath, prefix=None)
+
+ # add a disabled label
+ wrap = newPathlabelWrap(self, layout, frameStyle, pathModule, fpath, prefix='disabled: ')
+ wrap.label.setEnabled(False)
+
+ # for kicks a styled one
+ wrap = newPathlabelWrap(self, layout, frameStyle, pathModule, fpath, prefix='styled: ')
+ wrap.label.setStyleSheet('QLabel{border: 2px solid cyan; background: blue; color: white}')
+
+ # indent should work, too
+ wrap = newPathlabelWrap(self, layout, frameStyle, pathModule, fpath, prefix='indented: ')
+ wrap.label.setIndent(20)
+
+ # as should margin
+ wrap = newPathlabelWrap(self, layout, frameStyle, pathModule, fpath, prefix='margined: ')
+ wrap.label.setMargin(20)
+
+
+ # default QLabel to see test label to see if our owner drawn labels are ok
+ self.labelTest = QtGui.QLabel("no shortcuts, no rich text yet", self.mainWidget)
+ self.labelTest.setFrameStyle(frameStyle)
+ layout.addWidget(self.labelTest)
+
+ layout.addItem(QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Expanding))
+
+ # add another wrap on the statusbar
+ self.status = self.statusBar()
+ self.statusLabelWrap = PathLabelWrap(QtGui.QLabel(BLINDTEXT, self.status), fpath=fpath, prefix='status: ')
+ self.statusLabelWrap.label.setFrameStyle(frameStyle)
+ self.status.addWidget(self.statusLabelWrap.label, 10)
+ self.status.addWidget(QtGui.QLabel('foo-bar', self.status))
+
+
+ def styleChange(self, oldStyle):
+ """styleChange handler"""
+ self.update()
+
+
+#******************************************************************************
+#
+#******************************************************************************
+if __name__ == "__main__":
+ a = QtGui.QApplication(sys.argv)
+ QtCore.QObject.connect(a,QtCore.SIGNAL("lastWindowClosed()"),a,QtCore.SLOT("quit()"))
+ w = SampleGui()
+ w.show()
+ a.exec_()
Added: trunk/fclient/src/fclient/lib/compactpath/scripts/__init__.py
===================================================================
--- trunk/fclient/src/fclient/lib/compactpath/scripts/__init__.py (rev 0)
+++ trunk/fclient/src/fclient/lib/compactpath/scripts/__init__.py 2008-07-21 12:45:47 UTC (rev 716)
@@ -0,0 +1 @@
+"""scripts and helpers for the package"""
Added: trunk/fclient/src/fclient/lib/compactpath/scripts/gen_docs.py
===================================================================
--- trunk/fclient/src/fclient/lib/compactpath/scripts/gen_docs.py (rev 0)
+++ trunk/fclient/src/fclient/lib/compactpath/scripts/gen_docs.py 2008-07-21 12:45:47 UTC (rev 716)
@@ -0,0 +1,81 @@
+"""Generates epydoc documentation for the package in --> packageDir/doc
+
+gen_docs.py
+
+@note: the script assumes it is located in the <doc> or any other emidiate subdirectory of the package
+@note: Use gen_docs.py -? or --help to print out this help text
+
+@requires: epydoc
+"""
+
+import sys, os
+from epydoc import cli
+import subprocess
+#************************************************************************************
+# consts
+#************************************************************************************
+PACKAGE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+DOC_DIR = os.path.join(PACKAGE_DIR, 'doc')
+EPYDOC_FOLDER = 'epydoc'
+EPYDOC_DIR = os.path.join(DOC_DIR, EPYDOC_FOLDER)
+
+#************************************************************************************
+# helpers
+#************************************************************************************
+def save_create_dir(directory):
+ """creates a directory if it does not exist already"""
+ if not os.path.isdir(directory):
+ os.makedirs(directory)
+
+def enshure_doc_dir_dxists():
+ """enshures epydoc docdir exists"""
+ save_create_dir(EPYDOC_DIR)
+
+def pprint(msg, *params):
+ """helper to pprint user feedback"""
+ print '>' + msg
+ for i in params:
+ print ' ' + i
+
+#**************************************************************************
+#
+#**************************************************************************
+def main():
+ """"""
+ pprint('dumping docs to:', EPYDOC_DIR)
+ enshure_doc_dir_dxists()
+ pprint('calling epydoc')
+ sys.argv = [
+ __file__,
+ '-v',
+ '-o%s' % EPYDOC_DIR,
+ '--src-code-tab-width', '4',
+ #'--debug',
+ PACKAGE_DIR,
+ ]
+ cli.cli()
+
+ # create a redirect to 'epydoc/index.html'
+ html_index = os.path.join(DOC_DIR, 'index.html')
+ pprint('creating redirect:', html_index)
+ fp = open(html_index, 'w')
+ try:
+ fp.write('''<html>
+ <head>
+ <meta http-equiv="Refresh" content="0; URL=%s">
+ </head>
+</html>
+''' % (EPYDOC_FOLDER + '/' + 'index.html') )
+ finally:
+ fp.close()
+
+ pprint('done')
+
+#**************************************************************************************
+#
+#**************************************************************************************
+if __name__ == '__main__':
+ wantsHelp = len(sys.argv) > 1 and sys.argv[1] or None
+ if wantsHelp not in ('-?', '--help'):
+ sys.exit(main())
+ print __doc__
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|