SF.net SVN: fclient:[930] trunk/fclient/fclient/impl
Status: Pre-Alpha
Brought to you by:
jurner
From: <jU...@us...> - 2008-08-16 10:57:27
|
Revision: 930 http://fclient.svn.sourceforge.net/fclient/?rev=930&view=rev Author: jUrner Date: 2008-08-16 10:57:37 +0000 (Sat, 16 Aug 2008) Log Message: ----------- isolated view Added Paths: ----------- trunk/fclient/fclient/impl/ViewView/ trunk/fclient/fclient/impl/ViewView/Ui_ViewWidget.py trunk/fclient/fclient/impl/ViewView/View.py trunk/fclient/fclient/impl/ViewView/ViewObject.py trunk/fclient/fclient/impl/ViewView/ViewWidget.ui trunk/fclient/fclient/impl/ViewView/__init__.py trunk/fclient/fclient/impl/ViewView/_fix_mexec.py Added: trunk/fclient/fclient/impl/ViewView/Ui_ViewWidget.py =================================================================== --- trunk/fclient/fclient/impl/ViewView/Ui_ViewWidget.py (rev 0) +++ trunk/fclient/fclient/impl/ViewView/Ui_ViewWidget.py 2008-08-16 10:57:37 UTC (rev 930) @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file '/home/me/src/fclient/trunk/fclient/fclient/impl/ViewView/ViewWidget.ui' +# +# Created: Sat Aug 16 11:03:09 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_ViewWidget(object): + def setupUi(self, ViewWidget): + ViewWidget.setObjectName("ViewWidget") + ViewWidget.resize(530, 237) + self.gridLayout = QtGui.QGridLayout(ViewWidget) + self.gridLayout.setMargin(0) + self.gridLayout.setSpacing(0) + self.gridLayout.setObjectName("gridLayout") + self.splitter = QtGui.QSplitter(ViewWidget) + self.splitter.setOrientation(QtCore.Qt.Vertical) + self.splitter.setObjectName("splitter") + self.tabTop = QtGui.QTabWidget(self.splitter) + self.tabTop.setObjectName("tabTop") + self.tab = QtGui.QWidget() + self.tab.setGeometry(QtCore.QRect(0, 0, 526, 72)) + self.tab.setObjectName("tab") + self.tabTop.addTab(self.tab, "") + self.tabBottom = QtGui.QTabWidget(self.splitter) + self.tabBottom.setObjectName("tabBottom") + self.tab_3 = QtGui.QWidget() + self.tab_3.setGeometry(QtCore.QRect(0, 0, 526, 103)) + self.tab_3.setObjectName("tab_3") + self.tabBottom.addTab(self.tab_3, "") + self.gridLayout.addWidget(self.splitter, 0, 0, 1, 1) + + self.retranslateUi(ViewWidget) + self.tabTop.setCurrentIndex(0) + self.tabBottom.setCurrentIndex(0) + QtCore.QMetaObject.connectSlotsByName(ViewWidget) + + def retranslateUi(self, ViewWidget): + ViewWidget.setWindowTitle(QtGui.QApplication.translate("ViewWidget", "Form", None, QtGui.QApplication.UnicodeUTF8)) + self.tabTop.setTabText(self.tabTop.indexOf(self.tab), QtGui.QApplication.translate("ViewWidget", "Tab 1", None, QtGui.QApplication.UnicodeUTF8)) + self.tabBottom.setTabText(self.tabBottom.indexOf(self.tab_3), QtGui.QApplication.translate("ViewWidget", "Tab 1", None, QtGui.QApplication.UnicodeUTF8)) + + +if __name__ == "__main__": + import sys + app = QtGui.QApplication(sys.argv) + ViewWidget = QtGui.QWidget() + ui = Ui_ViewWidget() + ui.setupUi(ViewWidget) + ViewWidget.show() + sys.exit(app.exec_()) + Added: trunk/fclient/fclient/impl/ViewView/View.py =================================================================== --- trunk/fclient/fclient/impl/ViewView/View.py (rev 0) +++ trunk/fclient/fclient/impl/ViewView/View.py 2008-08-16 10:57:37 UTC (rev 930) @@ -0,0 +1,320 @@ +#*************************************************************************** +#TODO: +# +# x. shortcuts for "Go to" menus and items +# x. detatch tabs +# +#*************************************************************************** +# 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 import fcp2 +from .Ui_ViewWidget import Ui_ViewWidget +#********************************************************************************** +# +#********************************************************************************** +class ViewActions(config.ActionsBase): + + def __init__(self, parent): + config.ActionsBase.__init__(self, parent) + + self.action( + name='ActionShowTopTabBar', + text=self.trUtf8('Show top &tabs'), + trigger=parent.onActionShowTabsTop, + isCheckable=True, + isChecked=True, + ) + self.action( + name='ActionShowBottomTabBar', + text=self.trUtf8('Show bottom &tabs'), + trigger=parent.onActionShowTabsBottom, + isCheckable=True, + isChecked=True, + ) + +class GlobalFeedback(config.GlobalFeedbackBase): + """wrapper for global statusbar widgets, menus""" + + def __init__(self, parent, idGlobalFeedback): + config.GlobalFeedbackBase.__init__(self, parent, idGlobalFeedback) + + # menus + self.menu = None + if self.menuBar is not None and hasattr(parent, 'fcViewObject'): + self.menu = QtGui.QMenu(parent.fcViewObject.displayName, self.menuBar) + parent.populateMenu(self.menu) + self.menuBar.addViewMenu(self.menu) + + def setVisible(self, flag): + if self.menu is not None: + self.menu.children()[0].setEnabled(flag) + + +class Settings(config.SettingsBase): + _key_ = config.IdViewWidget + _settings_ = ( + ('LastViewTop', 'String', QtCore.QString('')), + ('LastViewBottom', 'String', QtCore.QString('')), + ('SplitterPos', 'ByteArray', QtCore.QByteArray()), + ('ShowTopTabBar', 'Bool', True), + ('ShowBottomTabBar', 'Bool', True), + ) + + +class ViewData(object): + """data structure to hold data for a view""" + + def __init__(self, tab, view): + self.tab = tab + self.view = view + self.actions = { + 'ActionGoTo': None, + } + +#*********************************************************************** +# +#*********************************************************************** +class ViewWidget(QtGui.QWidget, Ui_ViewWidget): + + IdSplitter = 'splitter' + IdTabTop = 'tabTop' + IdTabBottom = 'tabBottom' + + def __init__(self, parent, idGlobalFeedback=config.IdMainWindow): + QtGui.QWidget.__init__(self, parent) + + # setup ui + self.isCreated = False + self.menuGoToTopView = QtGui.QMenu(self) + self.menuGoToBottomView = QtGui.QMenu(self) + self.setupUi(self) + + # setup ... + self.fcActions = ViewActions(self) + self.fcSettings = Settings().restore() + self.fcGlobalFeedback = GlobalFeedback(self, idGlobalFeedback) + + # setup views + self.viewData = {} # viewName --> ViewData + self.actionGroupGoToTopView = QtGui.QActionGroup(self.menuGoToTopView) + self.actionGroupGoToTopView.setExclusive(True) + self.actionGroupGoToBottomView = QtGui.QActionGroup(self.menuGoToBottomView) + self.actionGroupGoToBottomView.setExclusive(True) + + # setup tab widgets + tabWidgetTop = self.controlById(self.IdTabTop) + tabWidgetTop.removeTab(0) + tabWidgetBottom = self.controlById(self.IdTabBottom) + tabWidgetBottom.removeTab(0) + + # setup splitter + splitter = self.controlById(self.IdSplitter) + splitter.restoreState(self.fcSettings.value('SplitterPos')) + self.connect(splitter, QtCore.SIGNAL('splitterMoved(int, int)'), self.onSplitterMoved) + + ################################### + ## private methods + ################################### + def _addViews(self, toTop, *views): + """private method to add one or more views ro bottom or top tabs""" + tabWidget = self.controlById(self.IdTabTop) if toTop else self.controlById(self.IdTabBottom) + for view in views: + viewName = view.name() + if not viewName: + raise ValueError('view must have a name') + if viewName in self.viewData: + raise ValueError('view with that name is already present: %s' % viewName) + view.widget().setParent(tabWidget) + index = tabWidget.addTab(view.widget(), view.icon(), view.displayName()) + self.viewData[viewName] = viewData = ViewData(tabWidget, view) + tabWidget.tabBar().setTabData(index, QtCore.QVariant(viewName)) + + # add some actions dynamically + menu = self.menuGoToTopView if toTop else self.menuGoToBottomView + actionGroup = self.actionGroupGoToTopView if toTop else self.actionGroupGoToBottomView + act = QtGui.QAction(actionGroup) + act.setObjectName(viewName) + act.setText(view.displayName()) + act.setCheckable(True) + self.connect(act, QtCore.SIGNAL('triggered()'), self.onActionGoToView) + viewData.actions['ActionGoTo'] = act + menu.addAction(act) + actionGroup.addAction(act) + #tab.tabBar().setVisible(tab.count() > 1) + + ################################### + ## overwritten methods + ################################### + def retranslateUi(self, me): + Ui_ViewWidget.retranslateUi(self, me) + self.menuGoToTopView.setTitle(self.trUtf8('Top go to')) + self.menuGoToBottomView.setTitle(self.trUtf8('Bottom go to')) + + ################################### + ## methods + ################################### + def addBottomViews(self, *views): + """adds one or more L{View}s to the bottom area of the view widget""" + return self._addViews(False, *views) + + def addTopViews(self, *views): + """adds one or more L{View}s to the top area of the view widget""" + return self._addViews(True, *views) + + def controlById(self, idControl): + return getattr(self, idControl) + + def currentView(self, top=True): + """returns the name of the current view + @param top: if True, returns the name of the current view on the top tabWidget, else the name + of current view on the bottom tabWidget + @return: (QString) name or None + """ + tabWidget = self.controlById(self.IdTabTop) if top else self.controlById(self.IdTabBottom) + index = tabWidget.currentIndex() + if index > -1: + return tabWidget.tabBar().tabData(index).toString() + return None + + def populateMenu(self, menu): + """populates a menu with actions the view widget defines""" + menu.addAction(self.fcActions['ActionShowTopTabBar']) + menu.addAction(self.fcActions['ActionShowBottomTabBar']) + menu.addSeparator() + menu.addMenu(self.menuGoToTopView) + menu.addMenu(self.menuGoToBottomView) + return menu + + def setCurrentView(self, name): + """sets the current view on the tabWidgtes given the views name + @return: Lname of the current view or None + """ + viewData = self.viewData.get(name, None) + if viewData is not None: + viewData.tab.setCurrentWidget(viewData.view.widget()) + return name + return None + + def viewDataFromName(self, name): + """returns L{ViewData} associated to a view + @param name: (QString) name of the view + @return: L{ViewData} or None + """ + viewData = self.viewData.get(name, None) + if viewData is not None: + return viewData + return None + + ######################################################### + ## overwritten events + ######################################################### + def closeEvent(self, event): + for viewData in self.viewData.values(): + viewData.view.close() + + def hideEvent(self, event): + self.fcGlobalFeedback.setVisible(False) + + def showEvent(self, event): + self.fcGlobalFeedback.setVisible(True) + if self.isCreated: + return + self.isCreated = True + + # restore last selected views (could be costy, so do it here) + tabWidgetTop = self.controlById(self.IdTabTop) + viewName = self.fcSettings.value('LastViewTop') + viewName = self.setCurrentView(viewName) + if viewName is None: + viewName = self.currentView(top=True) + if viewName is not None: + viewData = self.viewDataFromName(viewName) + viewData.actions['ActionGoTo'].setChecked(True) + + tabWidgetBottom = self.controlById(self.IdTabBottom) + viewName = self.fcSettings.value('LastViewBottom') + viewName = self.setCurrentView(viewName) + if viewName is None: + viewName = self.currentView(top=False) + if viewName is not None: + viewData = self.viewDataFromName(viewName) + viewData.actions['ActionGoTo'].setChecked(True) + + # finally connect... not to overwrite settings + self.connect(tabWidgetTop, QtCore.SIGNAL('currentChanged(int)'), self.onTabTopCurrentChanged) + self.connect(tabWidgetBottom, QtCore.SIGNAL('currentChanged(int)'), self.onTabBottomCurrentChanged) + + # adjust tabWidgets + showTopTabBar = self.fcSettings.value('ShowTopTabBar') + self.fcActions['ActionShowTopTabBar'].setChecked(showTopTabBar) + tabWidgetTop.tabBar().setVisible(showTopTabBar) + + showBottomTabBar = self.fcSettings.value('ShowBottomTabBar') + self.fcActions['ActionShowBottomTabBar'].setChecked(showBottomTabBar) + tabWidgetBottom.tabBar().setVisible(showBottomTabBar) + + + ################################## + ## event handlers + ################################## + def onActionGoToView(self): + act = self.sender() + viewData = self.viewData[act.objectName()] + viewData.tab.setCurrentWidget(viewData.view) + + def onActionShowTabsBottom(self, action): + tabWidgetTop = self.controlById(self.IdTabBottom) + tabWidgetTop.tabBar().setVisible(action.isChecked()) + self.fcSettings.setValues(ShowBottomTabBar=action.isChecked()) + + def onActionShowTabsTop(self, action): + tabWidgetTop = self.controlById(self.IdTabTop) + tabWidgetTop.tabBar().setVisible(action.isChecked()) + self.fcSettings.setValues(ShowTopTabBar=action.isChecked()) + + def onSplitterMoved(self, pos, index): + splitter = self.controlById(self.IdSplitter) + self.fcSettings.setValues(SplitterPos=splitter.saveState()) + + def onTabTopCurrentChanged(self, index): + viewName = self.currentView(top=True) + viewData = self.viewData[viewName] + viewData.actions['ActionGoTo'].setChecked(True) + self.fcSettings.setValues(LastViewTop=viewName) + + def onTabBottomCurrentChanged(self, index): + viewName = self.currentView(top=False) + viewData = self.viewData[viewName] + viewData.actions['ActionGoTo'].setChecked(True) + self.fcSettings.setValues(LastViewTop=viewName) + +#********************************************************************************** +# +#********************************************************************************** +if __name__ == '__main__': + import sys + + app = QtGui.QApplication(sys.argv) + w = ViewWidget(None) + w.show() + res = app.exec_() + sys.exit(res) + + + + Added: trunk/fclient/fclient/impl/ViewView/ViewObject.py =================================================================== --- trunk/fclient/fclient/impl/ViewView/ViewObject.py (rev 0) +++ trunk/fclient/fclient/impl/ViewView/ViewObject.py 2008-08-16 10:57:37 UTC (rev 930) @@ -0,0 +1,51 @@ +# 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 QtGui + +from .. import config +from .. import ViewObject + +from . import View +#************************************************************************************ +# +#************************************************************************************ +class ViewObjectView(ViewObject.ViewObject): + + def __init__(self, parentView=None): + ViewObject.ViewObject.__init__(self, parentView) + self._widget = None + + def close(self): + pass + + def create(self): + self._widget = View.ViewWidget(self.parentWidget()) + return self.widget() + + def displayName(self): + return self.trUtf8('View') + + def icon(self): + return QtGui.QIcon() + + def name(self): + return config.IdViewObjectView + + def prefsPage(self): + pass + + + def widget(self): + return self._widget + Added: trunk/fclient/fclient/impl/ViewView/ViewWidget.ui =================================================================== --- trunk/fclient/fclient/impl/ViewView/ViewWidget.ui (rev 0) +++ trunk/fclient/fclient/impl/ViewView/ViewWidget.ui 2008-08-16 10:57:37 UTC (rev 930) @@ -0,0 +1,69 @@ +<ui version="4.0" > + <class>ViewWidget</class> + <widget class="QWidget" name="ViewWidget" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>530</width> + <height>237</height> + </rect> + </property> + <property name="windowTitle" > + <string>Form</string> + </property> + <layout class="QGridLayout" name="gridLayout" > + <property name="margin" > + <number>0</number> + </property> + <property name="spacing" > + <number>0</number> + </property> + <item row="0" column="0" > + <widget class="QSplitter" name="splitter" > + <property name="orientation" > + <enum>Qt::Vertical</enum> + </property> + <widget class="QTabWidget" name="tabTop" > + <property name="currentIndex" > + <number>0</number> + </property> + <widget class="QWidget" name="tab" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>526</width> + <height>72</height> + </rect> + </property> + <attribute name="title" > + <string>Tab 1</string> + </attribute> + </widget> + </widget> + <widget class="QTabWidget" name="tabBottom" > + <property name="currentIndex" > + <number>0</number> + </property> + <widget class="QWidget" name="tab_3" > + <property name="geometry" > + <rect> + <x>0</x> + <y>0</y> + <width>526</width> + <height>103</height> + </rect> + </property> + <attribute name="title" > + <string>Tab 1</string> + </attribute> + </widget> + </widget> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> Added: trunk/fclient/fclient/impl/ViewView/__init__.py =================================================================== --- trunk/fclient/fclient/impl/ViewView/__init__.py (rev 0) +++ trunk/fclient/fclient/impl/ViewView/__init__.py 2008-08-16 10:57:37 UTC (rev 930) @@ -0,0 +1 @@ + Added: trunk/fclient/fclient/impl/ViewView/_fix_mexec.py =================================================================== --- trunk/fclient/fclient/impl/ViewView/_fix_mexec.py (rev 0) +++ trunk/fclient/fclient/impl/ViewView/_fix_mexec.py 2008-08-16 10:57:37 UTC (rev 930) @@ -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. |