SF.net SVN: fclient:[941] trunk/fclient/fclient
Status: Pre-Alpha
Brought to you by:
jurner
From: <jU...@us...> - 2008-08-18 19:36:58
|
Revision: 941 http://fclient.svn.sourceforge.net/fclient/?rev=941&view=rev Author: jUrner Date: 2008-08-18 19:36:54 +0000 (Mon, 18 Aug 2008) Log Message: ----------- more package layout changes Modified Paths: -------------- trunk/fclient/fclient/fclient.py trunk/fclient/fclient/impl/MainWindow/MainWindow.py Added Paths: ----------- trunk/fclient/fclient/impl/dlgs/ trunk/fclient/fclient/impl/dlgs/DlgPrefs.py trunk/fclient/fclient/impl/dlgs/DlgSingleAppError.py trunk/fclient/fclient/impl/dlgs/DlgSingleAppErrorTpl.ui trunk/fclient/fclient/impl/dlgs/Ui_DlgSingleAppErrorTpl.py trunk/fclient/fclient/impl/dlgs/__init__.py trunk/fclient/fclient/impl/dlgs/_fix_mexec.py Removed Paths: ------------- trunk/fclient/fclient/impl/tpls/ Modified: trunk/fclient/fclient/fclient.py =================================================================== --- trunk/fclient/fclient/fclient.py 2008-08-17 13:00:14 UTC (rev 940) +++ trunk/fclient/fclient/fclient.py 2008-08-18 19:36:54 UTC (rev 941) @@ -20,7 +20,7 @@ from .impl.ViewLogger.ViewObject import ViewObjectLogger from .impl.ViewUploads.ViewObject import ViewObjectUploads -from .impl.DlgSingleAppError import DlgSingleAppError +from .impl.dlgs.DlgSingleAppError import DlgSingleAppError #************************************************************* # #************************************************************* Modified: trunk/fclient/fclient/impl/MainWindow/MainWindow.py =================================================================== --- trunk/fclient/fclient/impl/MainWindow/MainWindow.py 2008-08-17 13:00:14 UTC (rev 940) +++ trunk/fclient/fclient/impl/MainWindow/MainWindow.py 2008-08-18 19:36:54 UTC (rev 941) @@ -14,7 +14,7 @@ from PyQt4 import QtCore, QtGui from .. import config -from .. import Prefs +from ..dlgs import DlgPrefs from ..lib.qt4ex import dlgabout from . import Actions @@ -63,7 +63,7 @@ ## event onrs ################################### def onActPreferencesTriggered(self): - dlg = Prefs.PrefsDlg(self) + dlg = DlgPrefs.DlgPrefs(self) if dlg.exec_() == dlg.Accepted: pass @@ -94,8 +94,11 @@ #********************************************************************************** if __name__ == '__main__': import sys + app = QtGui.QApplication(sys.argv) - w = MainWindow(None) - w.show() + + mainWindow = MainWindow(None) + + mainWindow.show() res = app.exec_() - sys.exit(res) + sys.exit(res) \ No newline at end of file Added: trunk/fclient/fclient/impl/dlgs/DlgPrefs.py =================================================================== --- trunk/fclient/fclient/impl/dlgs/DlgPrefs.py (rev 0) +++ trunk/fclient/fclient/impl/dlgs/DlgPrefs.py 2008-08-18 19:36:54 UTC (rev 941) @@ -0,0 +1,96 @@ +# some fixes for relative imports +# see --> [http://bugs.python.org/issue1510172] absolute/rellative import not working (works only current dir and below) +# see --> [http://mail.python.org/pipermail/python-ideas/2007-February/000232.html] PEP for executing a module in a +# ...package containing relative imports +from __future__ import absolute_import +if __name__ == '__main__': + import os + __path__ = [os.path.dirname(__file__)] + from ._fix_mexec import fix_mexec + fix_mexec(__name__, __file__) + del fix_mexec + + +from PyQt4 import QtCore, QtGui + +from .. import config +from ..lib.qt4ex import dlgpreferences +#********************************************************************************** +# +#********************************************************************************** +class Settings(config.SettingsBase): + _key_ = config.IdDlgPrefs + _settings_ = ( + ('DlgState', 'String', QtCore.QString('')), + ) + + +#*********************************************************************** +# +#*********************************************************************** +class PrefsPageRoot(dlgpreferences.Page): + + UUID = '{a61e2758-4c66-11dd-a3e6-8814a37cbeed}' + + def __init__(self): + dlgpreferences.Page.__init__(self, self.UUID) + self._widget = None + self.setDirty(True) + + def displayName(self): + return QtGui.QApplication.translate("PreferencesGlobal", 'All', None, QtGui.QApplication.UnicodeUTF8) + + def canApply(self): return False + def canHelp(self): return False + + def setVisible(self, parent, flag): + createdNew = False + if flag and self._widget is None: + createdNew = True + self._widget = QtGui.QWidget(parent) + self._widget.setVisible(flag) + return (createdNew, self._widget) + +#********************************************************************************** +# +#********************************************************************************** +class DlgPrefs(dlgpreferences.DlgPreferencesFlatTree): + + def __init__(self, parent): + root = PrefsPageRoot() + for viewObject in config.ObjectRegistry: + prefsPage = viewObject.prefsPage() + if prefsPage is not None: + root(prefsPage) + dlgpreferences.DlgPreferencesFlatTree.__init__(self, + parent, + pages=root, + startPage=root.children()[0].uuid() if root.children() else None, + ) + self.setObjectName(config.IdDlgPrefs) + self.fcSettings = Settings(self).restore() + + + def showEvent(self, event): + self.restoreState(self.fcSettings.value('DlgState')) + + def hideEvent(self, event): + self.fcSettings.setValues(DlgState=self.saveState()) + + def closeEvent(self, event): + pass + + +#********************************************************************************** +# +#********************************************************************************** +if __name__ == '__main__': + import sys + + app = QtGui.QApplication(sys.argv) + w = DlgPrefs(None) + w.show() + res = app.exec_() + sys.exit(res) + + Added: trunk/fclient/fclient/impl/dlgs/DlgSingleAppError.py =================================================================== --- trunk/fclient/fclient/impl/dlgs/DlgSingleAppError.py (rev 0) +++ trunk/fclient/fclient/impl/dlgs/DlgSingleAppError.py 2008-08-18 19:36:54 UTC (rev 941) @@ -0,0 +1,139 @@ +#*************************************************************************************** +#TODO: +# x. error icon +# +#************************************************************************************* +# some fixes for relative imports +# see --> [http://bugs.python.org/issue1510172] absolute/rellative import not working (works only current dir and below) +# see --> [http://mail.python.org/pipermail/python-ideas/2007-February/000232.html] PEP for executing a module in a +# ...package containing relative imports +from __future__ import absolute_import +if __name__ == '__main__': + import os + __path__ = [os.path.dirname(__file__)] + from ._fix_mexec import fix_mexec + fix_mexec(__name__, __file__) + del fix_mexec + +import os +from PyQt4 import QtCore, QtGui + +from .. import config + +from .Ui_DlgSingleAppErrorTpl import Ui_DlgSingleAppError +#********************************************************************************** +# +#********************************************************************************** +class Settings(config.SettingsBase): + _key_ = 'DlgSingleAppError' + _settings_ = ( + ('Geometry', 'ByteArray', QtCore.QByteArray()), + ('SplitterPos', 'ByteArray', QtCore.QByteArray()), + ) + + +#********************************************************************************** +# +#********************************************************************************** +class DlgSingleAppError(QtGui.QDialog, Ui_DlgSingleAppError): + + IdTextEdit = 'textEdit' + IdEdHost = 'edHost' + IdSpinPort = 'spinPort' + IdSplitter = 'splitter' + + + def __init__(self, parent=None, fcpKey=None): + QtGui.QDialog.__init__(self, parent) + + self.setupUi(self) + self.fcSettings = Settings(self).restore() + + # setup dialog + self.restoreGeometry(self.fcSettings.value('Geometry')) + self.setWindowTitle(config.FcAppName + self.trUtf8(' - Error starting up')) + + + # setup host / port + edHost = self.controlById(self.IdEdHost) + edHost.setText(config.fcSettings.value('SingleAppHost')) + + spinPort = self.controlById(self.IdSpinPort) + spinPort.setRange(0, 0xFFFF) #TODO: no idea if port range (0, 0xFFFF) this is reasonable + spinPort.setValue(config.fcSettings.value('SingleAppPort')) + + + # setup text edit + ed = self.controlById(self.IdTextEdit) + text = self.trUtf8('<b>%1 could not be started!</b>').arg(config.FcAppName) + ed.insertHtml(text) + ed.insertHtml('<br><br>') + text = self.trUtf8('%1 could not establish a socket connection needed to enshure only one application is running at a time. Possible reasons are:').arg(config.FcAppName) + ed.insertHtml(text) + + text = '''<ol> + <li>%s</li> + <li>%s</li> + + </ol> + ''' % ( + self.trUtf8('Your firewall blocks the connection. Adjust your firewall to allow the connection as shown to the left.'), + self.trUtf8('Another application may already use host and port as shown. Adjust host and port to your needs. In most cases setting port to an arbitrary (high) number should do the job.'), + + ) + ed.insertHtml(text) + cursor = ed.textCursor() + cursor.movePosition(cursor.Start, cursor.MoveAnchor) + ed.setTextCursor(cursor) + + # setup splitter + splitter = self.controlById(self.IdSplitter) + splitter.restoreState(self.fcSettings.value('SplitterPos')) + self.connect(splitter, QtCore.SIGNAL('splitterMoved(int, int)'), self.onSplitterMoved) + + ############################## + ## methods + ############################## + def controlById(self, idControl): + return getattr(self, idControl) + + ############################## + ## overwritten methods + ############################## + def accept(self): + edHost = self.controlById(self.IdEdHost) + spinPort = self.controlById(self.IdSpinPort) + config.fcSettings.setValues( + SingleAppHost=edHost.text(), + SingleAppPort=spinPort.value(), + ) + + + self.done(self.Accepted) + + ############################## + ## overwritten events + ############################## + def hideEvent(self, event): + self.fcSettings.setValues(Geometry=self.saveGeometry()) + + ############################## + ## event handlers + ############################## + def onSplitterMoved(self, pos, index): + splitter = self.controlById(self.IdSplitter) + self.fcSettings.setValues(SplitterPos=splitter.saveState()) + +#********************************************************************************** +# +#********************************************************************************** +if __name__ == '__main__': + import sys + + app = QtGui.QApplication(sys.argv) + w = DlgSingleAppError() + w.show() + res = app.exec_() + sys.exit(res) + + Added: trunk/fclient/fclient/impl/dlgs/DlgSingleAppErrorTpl.ui =================================================================== --- trunk/fclient/fclient/impl/dlgs/DlgSingleAppErrorTpl.ui (rev 0) +++ trunk/fclient/fclient/impl/dlgs/DlgSingleAppErrorTpl.ui 2008-08-18 19:36:54 UTC (rev 941) @@ -0,0 +1,119 @@ +<ui version="4.0" > + <class>DlgSingleAppError</class> + <widget class="QDialog" name="DlgSingleAppError" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>410</width> + <height>277</height> + </rect> + </property> + <property name="windowTitle" > + <string>Dialog</string> + </property> + <layout class="QGridLayout" name="gridLayout" > + <item row="1" column="0" > + <widget class="Line" name="line" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="2" column="0" > + <widget class="QDialogButtonBox" name="buttonBox" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons" > + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + <item row="0" column="0" > + <widget class="QSplitter" name="splitter" > + <property name="orientation" > + <enum>Qt::Horizontal</enum> + </property> + <widget class="QTextEdit" name="textEdit" /> + <widget class="QWidget" name="layoutWidget" > + <layout class="QVBoxLayout" name="verticalLayout_2" > + <item> + <layout class="QVBoxLayout" name="verticalLayout" > + <item> + <widget class="QLabel" name="fieldHeader" > + <property name="text" > + <string>Host: </string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="edHost" /> + </item> + <item> + <widget class="QLabel" name="fieldHeader_2" > + <property name="text" > + <string>Port: </string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="spinPort" /> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer" > + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0" > + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>DlgSingleAppError</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>DlgSingleAppError</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> Added: trunk/fclient/fclient/impl/dlgs/Ui_DlgSingleAppErrorTpl.py =================================================================== --- trunk/fclient/fclient/impl/dlgs/Ui_DlgSingleAppErrorTpl.py (rev 0) +++ trunk/fclient/fclient/impl/dlgs/Ui_DlgSingleAppErrorTpl.py 2008-08-18 19:36:54 UTC (rev 941) @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file '/home/me/src/fclient/trunk/fclient/fclient/impl/tpls/DlgSingleAppErrorTpl.ui' +# +# Created: Thu Jul 31 20:24:37 2008 +# by: PyQt4 UI code generator 4.4.3-snapshot-20080705 +# +# WARNING! All changes made in this file will be lost! + +from PyQt4 import QtCore, QtGui + +class Ui_DlgSingleAppError(object): + def setupUi(self, DlgSingleAppError): + DlgSingleAppError.setObjectName("DlgSingleAppError") + DlgSingleAppError.resize(410, 277) + self.gridLayout = QtGui.QGridLayout(DlgSingleAppError) + self.gridLayout.setObjectName("gridLayout") + self.line = QtGui.QFrame(DlgSingleAppError) + self.line.setFrameShape(QtGui.QFrame.HLine) + self.line.setFrameShadow(QtGui.QFrame.Sunken) + self.line.setObjectName("line") + self.gridLayout.addWidget(self.line, 1, 0, 1, 1) + self.buttonBox = QtGui.QDialogButtonBox(DlgSingleAppError) + self.buttonBox.setOrientation(QtCore.Qt.Horizontal) + self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) + self.buttonBox.setObjectName("buttonBox") + self.gridLayout.addWidget(self.buttonBox, 2, 0, 1, 1) + self.splitter = QtGui.QSplitter(DlgSingleAppError) + self.splitter.setOrientation(QtCore.Qt.Horizontal) + self.splitter.setObjectName("splitter") + self.textEdit = QtGui.QTextEdit(self.splitter) + self.textEdit.setObjectName("textEdit") + self.layoutWidget = QtGui.QWidget(self.splitter) + self.layoutWidget.setObjectName("layoutWidget") + self.verticalLayout_2 = QtGui.QVBoxLayout(self.layoutWidget) + self.verticalLayout_2.setObjectName("verticalLayout_2") + self.verticalLayout = QtGui.QVBoxLayout() + self.verticalLayout.setObjectName("verticalLayout") + self.fieldHeader = QtGui.QLabel(self.layoutWidget) + self.fieldHeader.setObjectName("fieldHeader") + self.verticalLayout.addWidget(self.fieldHeader) + self.edHost = QtGui.QLineEdit(self.layoutWidget) + self.edHost.setObjectName("edHost") + self.verticalLayout.addWidget(self.edHost) + self.fieldHeader_2 = QtGui.QLabel(self.layoutWidget) + self.fieldHeader_2.setObjectName("fieldHeader_2") + self.verticalLayout.addWidget(self.fieldHeader_2) + self.spinPort = QtGui.QSpinBox(self.layoutWidget) + self.spinPort.setObjectName("spinPort") + self.verticalLayout.addWidget(self.spinPort) + self.verticalLayout_2.addLayout(self.verticalLayout) + spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) + self.verticalLayout_2.addItem(spacerItem) + self.gridLayout.addWidget(self.splitter, 0, 0, 1, 1) + + self.retranslateUi(DlgSingleAppError) + QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), DlgSingleAppError.accept) + QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), DlgSingleAppError.reject) + QtCore.QMetaObject.connectSlotsByName(DlgSingleAppError) + + def retranslateUi(self, DlgSingleAppError): + DlgSingleAppError.setWindowTitle(QtGui.QApplication.translate("DlgSingleAppError", "Dialog", None, QtGui.QApplication.UnicodeUTF8)) + self.fieldHeader.setText(QtGui.QApplication.translate("DlgSingleAppError", "Host: ", None, QtGui.QApplication.UnicodeUTF8)) + self.fieldHeader_2.setText(QtGui.QApplication.translate("DlgSingleAppError", "Port: ", None, QtGui.QApplication.UnicodeUTF8)) + + +if __name__ == "__main__": + import sys + app = QtGui.QApplication(sys.argv) + DlgSingleAppError = QtGui.QDialog() + ui = Ui_DlgSingleAppError() + ui.setupUi(DlgSingleAppError) + DlgSingleAppError.show() + sys.exit(app.exec_()) + Added: trunk/fclient/fclient/impl/dlgs/__init__.py =================================================================== --- trunk/fclient/fclient/impl/dlgs/__init__.py (rev 0) +++ trunk/fclient/fclient/impl/dlgs/__init__.py 2008-08-18 19:36:54 UTC (rev 941) @@ -0,0 +1 @@ + Added: trunk/fclient/fclient/impl/dlgs/_fix_mexec.py =================================================================== --- trunk/fclient/fclient/impl/dlgs/_fix_mexec.py (rev 0) +++ trunk/fclient/fclient/impl/dlgs/_fix_mexec.py 2008-08-18 19:36:54 UTC (rev 941) @@ -0,0 +1,99 @@ +'''in python 2.5 relative impports are srsly broken ..fix this to make relative imports work +when executing a module as main (-m), including relative imports up to the root package + +see: [http://mail.python.org/pipermail/python-ideas/2007-February/000232.html] + +@note: root package is the highest available package in the package hirarchy. +don't look at __name__ too closely. it gets adjusted for a module to just "do the right +thing" in __name__ == '__main__' comparisons +@note: this patch does not work if relative imports are done in __init__.py. no idea why +and to be honest, I don't wanna* know.. +@note: this is more or less a hack. so it may have unwanted side effects for example +when importing parent packages. use at your own risk. could improve this module +by adding a __main__.py to stop at this level or by fixing the __init__.py bug, but +I don't think its worth it. see what python2.6 or 3k brings.. + +usage:: + + # place this at the top a module, before doing any relative imports + from fix_mexec import fix_mexec + fix_mexec(__name__, __file__) + del fix_mexec + + from ...foo import bar + + + +##<-- copy and paste code, assuming _fix_mexec resides in the current dir.. + +# some fixes for relative imports +# see --> [http://bugs.python.org/issue1510172] absolute/rellative import not working (works only current dir and below) +# see --> [http://mail.python.org/pipermail/python-ideas/2007-February/000232.html] PEP for executing a module in a +# ...package containing relative imports +from __future__ import absolute_import +if __name__ == '__main__': + import os + __path__ = [os.path.dirname(__file__)] + from ._fix_mexec import fix_mexec + fix_mexec(__name__, __file__) + del fix_mexec + + +##--> copy and paste code +''' + +import imp, os, sys +#******************************************************************************** +# +#******************************************************************************** +class MainName(str): + def __eq__(self, other): + if other == '__main__': return True + return str.__eq__(self, other) + def __ne__(self, other): + if other == '__main__': return False + return str.__ne__(self, other) + + +def fix_mexec(_name_, _file_): + """bugfix for relative imports not working + @param _name_: __name__ of the module + @param _file_: __file__ of the module + + @note: not complete: relies on __init__.py, .pyo (...) is ignored currently + """ + if _name_ == '__main__': + out = [] + # find allparent packages + p = os.path.dirname(os.path.abspath(_file_)) + prev = p + while True: + pkg = os.path.join(p, '__init__.py') + if os.path.isfile(pkg): + out.append([pkg, os.path.basename(p)]) + else: + break + prev = p + p = os.path.dirname(p) + if p == prev: + break + out.reverse() + + # adjust sub package names an import parent modules + name = None + for n, (fpath, name) in enumerate(out): + if n > 0: + name = out[n][1] = out[n -1][1] + '.' + out[n][1] + m = imp.load_source(name, fpath) + m.__path__ = [os.path.dirname(fpath)] + + # adjust name of the __main__ module + if name is not None: + m = sys.modules.pop('__main__') + # 'foo.bar..__main__' does not work for some reason. 'foo.bar' seems to work as expected + ##m.__name__ = _Name_(name + '.' + '__main__') + m.__name__ = MainName(name) + sys.modules[m.__name__] = m + + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |