Thread: SF.net SVN: fclient: [550] trunk/fclient/src/fclient/Ui_View.py
Status: Pre-Alpha
Brought to you by:
jurner
From: <jU...@us...> - 2008-07-08 10:54:06
|
Revision: 550 http://fclient.svn.sourceforge.net/fclient/?rev=550&view=rev Author: jUrner Date: 2008-07-08 03:53:00 -0700 (Tue, 08 Jul 2008) Log Message: ----------- started implementing view interface Added Paths: ----------- trunk/fclient/src/fclient/Ui_View.py Added: trunk/fclient/src/fclient/Ui_View.py =================================================================== --- trunk/fclient/src/fclient/Ui_View.py (rev 0) +++ trunk/fclient/src/fclient/Ui_View.py 2008-07-08 10:53:00 UTC (rev 550) @@ -0,0 +1,110 @@ + +from __future__ import absolute_import +if __name__ == '__main__': # see --> http://bugs.python.org/issue1510172 . works only current dir and below + import os; __path__ = [os.path.dirname(__file__)] + + +from PyQt4 import QtCore, QtGui + + +from . import config +from .lib import fcp2 +from .lib.qt4ex import settingsbase +from .tpls.Ui_ViewTpl import Ui_ViewTpl + +#********************************************************************************** +# +#********************************************************************************** +class UserSettings(settingsbase.SettingsBase): + + KEY_SETTINGS = 'UserSettingsView' + SETTINGS = [ + ] + +#*********************************************************************** +# +#*********************************************************************** +class ViewWidget(QtGui.QWidget, Ui_ViewTpl): + + IdTabTop = 'tabTop' + IdTabBottom = 'tabBottom' + + + + def __init__(self, parent, cfg=None): + QtGui.QWidget.__init__(self, parent) + + self.cfg = config.Config(self) if cfg is None else cfg + self.userSettings = UserSettings() + self.views = {} + + self.setupUi(self) + + tabTop = self.controlById(self.IdTabTop) + tabTop.removeTab(0) + tabBottom = self.controlById(self.IdTabBottom) + tabBottom.removeTab(0) + + + + def controlById(self, idControl): + return getattr(self, idControl) + + + def addViews(top=True, *views): + tab = self.controlById(self.IdTabTop) if top else self.controlById(self.IdTabBottom) + for view in views: + uuid = view.uuid() + if uuid in self.views: + raise ValueError('view is already present: %s' % uuid) + i = tab.addTab(view.widget(tab), view.displayName(), view.icon()) + self.views[uuid] = (i, tab, view) + + + def viewFromUuid(self, uuid): + return self.views[uuid] + + def setCurrentView(self, view): + index, tab, view = view + + +#********************************************************************************** +# +#********************************************************************************** +class View(object): + """base class for views""" + + UUID = '' + + def __init__(self): + pass + + + def displayName(self): + return 'tab' + + def icon(self): + pass + + def uuid(self): + return self.UUID + + def widget(self, parent): + pass + + +#********************************************************************************** +# +#********************************************************************************** +if __name__ == '__main__': + import sys + + app = QtGui.QApplication(sys.argv) + w = ViewWidget(None) + w.show() + res = app.exec_() + sys.exit(res) + + + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-07-11 16:33:15
|
Revision: 573 http://fclient.svn.sourceforge.net/fclient/?rev=573&view=rev Author: jUrner Date: 2008-07-11 09:33:24 -0700 (Fri, 11 Jul 2008) Log Message: ----------- too many changes to list Modified Paths: -------------- trunk/fclient/src/fclient/Ui_View.py Modified: trunk/fclient/src/fclient/Ui_View.py =================================================================== --- trunk/fclient/src/fclient/Ui_View.py 2008-07-11 16:32:57 UTC (rev 572) +++ trunk/fclient/src/fclient/Ui_View.py 2008-07-11 16:33:24 UTC (rev 573) @@ -1,4 +1,12 @@ - +#FIXES +#*************************************************************************** +# [0001] +# +# QTabWidget.closeEvent() does not seem to propagate close events +# to child widgets +# +# +#*************************************************************************** from __future__ import absolute_import if __name__ == '__main__': # see --> http://bugs.python.org/issue1510172 . works only current dir and below import os; __path__ = [os.path.dirname(__file__)] @@ -9,17 +17,14 @@ from . import config from .lib import fcp2 -from .lib.qt4ex import settingsbase from .tpls.Ui_ViewWidgetTpl import Ui_ViewWidget - #********************************************************************************** # #********************************************************************************** -class UserSettings(settingsbase.SettingsBase): - - KEY_SETTINGS = 'UserSettingsView' - SETTINGS = [ - ] +class Settings(config.SettingsBase): + _key_ = config.IdViewWidget + _settings_ = ( + ) #*********************************************************************** # @@ -31,15 +36,15 @@ - def __init__(self, parent, cfg=None): + def __init__(self, parent): QtGui.QWidget.__init__(self, parent) - self.cfg = config.Config(self) if cfg is None else cfg - self.userSettings = UserSettings() + self.settings = Settings() self.views = {} self.setupUi(self) config.ObjectRegistry.register(self) + self.settings.restore() tabTop = self.controlById(self.IdTabTop) tabTop.removeTab(0) @@ -68,7 +73,10 @@ def setCurrentView(self, view): index, tab, view = view - + def closeEvent(self, event): + for i, tab, view in self.views.values(): + view.close() + #********************************************************************************** # #********************************************************************************** @@ -105,6 +113,9 @@ note: if the widget is not already created _now_ is the right time to create it """ raise NotImplemetedError() + + def close(self): + """called when the view is about to be closed""" #********************************************************************************** # This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-07-12 19:58:43
|
Revision: 599 http://fclient.svn.sourceforge.net/fclient/?rev=599&view=rev Author: jUrner Date: 2008-07-12 12:58:48 -0700 (Sat, 12 Jul 2008) Log Message: ----------- add settings and a bit this and that Modified Paths: -------------- trunk/fclient/src/fclient/Ui_View.py Modified: trunk/fclient/src/fclient/Ui_View.py =================================================================== --- trunk/fclient/src/fclient/Ui_View.py 2008-07-12 19:58:19 UTC (rev 598) +++ trunk/fclient/src/fclient/Ui_View.py 2008-07-12 19:58:48 UTC (rev 599) @@ -24,6 +24,7 @@ class Settings(config.SettingsBase): _key_ = config.IdViewWidget _settings_ = ( + ('LastView', 'String', '', config.SettingScopePrivate), ) #*********************************************************************** @@ -50,8 +51,7 @@ tabTop.removeTab(0) tabBottom = self.controlById(self.IdTabBottom) tabBottom.removeTab(0) - - + def controlById(self, idControl): return getattr(self, idControl) @@ -67,7 +67,7 @@ self.views[ido] = (i, tab, view) - def viewFromUuid(self, uuid): + def viewFromName(self, name): return self.views[uuid] def setCurrentView(self, view): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-07-13 14:20:11
|
Revision: 624 http://fclient.svn.sourceforge.net/fclient/?rev=624&view=rev Author: jUrner Date: 2008-07-13 07:20:18 -0700 (Sun, 13 Jul 2008) Log Message: ----------- continued impl view widget Modified Paths: -------------- trunk/fclient/src/fclient/Ui_View.py Modified: trunk/fclient/src/fclient/Ui_View.py =================================================================== --- trunk/fclient/src/fclient/Ui_View.py 2008-07-13 14:19:49 UTC (rev 623) +++ trunk/fclient/src/fclient/Ui_View.py 2008-07-13 14:20:18 UTC (rev 624) @@ -24,7 +24,9 @@ class Settings(config.SettingsBase): _key_ = config.IdViewWidget _settings_ = ( - ('LastView', 'String', '', config.SettingScopePrivate), + ('LastViewTop', 'String', '', config.SettingScopePrivate), + ('LastViewBottom', 'String', '', config.SettingScopePrivate), + ('SplitterPos', 'ByteArray', QtCore.QByteArray(), config.SettingScopePrivate), ) #*********************************************************************** @@ -32,51 +34,127 @@ #*********************************************************************** class ViewWidget(QtGui.QWidget, Ui_ViewWidget): + IdSplitter = 'Splitter' IdTabTop = 'tabTop' IdTabBottom = 'tabBottom' + - - def __init__(self, parent): QtGui.QWidget.__init__(self, parent) - + + self._isCreated = False self.settings = Settings() self.views = {} - + self.setupUi(self) config.ObjectRegistry.register(self) self.settings.restore() + # setup tab widgets tabTop = self.controlById(self.IdTabTop) tabTop.removeTab(0) tabBottom = self.controlById(self.IdTabBottom) tabBottom.removeTab(0) + self.connect(tabTop, QtCore.SIGNAL('currentChanged(int)'), self.handleTabTopCurrentChanged) + self.connect(tabBottom, QtCore.SIGNAL('currentChanged(int)'), self.handleTabBottomCurrentChanged) + + # setup splitter + splitter = self.controlById(self.IdSplitter) + splitter.restoreState(self.settings.value('SplitterPos')) def controlById(self, idControl): return getattr(self, idControl) - def addViews(self, toTop, *views): + def _addViews(self, toTop, *views): tab = self.controlById(self.IdTabTop) if toTop else self.controlById(self.IdTabBottom) for view in views: - ido = str(view.objectName()) - if ido in self.views: - raise ValueError('view is already present: %s' % ido) - i = tab.addTab(view.widget(tab), view.icon(), view.displayName()) - self.views[ido] = (i, tab, view) + name = view.viewName() + if not name: + raise ValueError('view must have a name') + if name in self.views: + raise ValueError('view with that name is already present: %s' % name) + view.setParent(tab) + i = tab.addTab(view, view.viewIcon(), view.viewDisplayName()) + self.views[name] = (tab, view) + + def addBottomViews(self, *views): + return self._addViews(False, *views) + + def addTopViews(self, *views): + return self._addViews(True, *views) + + def viewFromName(self, name): - return self.views[uuid] - - def setCurrentView(self, view): - index, tab, view = view + result = self.views.get(name, None) + if result is not None: + return result[1] + return None + + #TODO: ... + #def setCurrentView(self, view): + # index, tab, view = view + + ######################################################### + ## + ######################################################### def closeEvent(self, event): - for i, tab, view in self.views.values(): - view.close() + splitter = self.controlById(self.IdSplitter) + self.settings.setValues(SplitterPos=splitter.saveState()) + for tab, view in self.views.values(): + view.viewClose() + + + def showEvent(self, event): + if self._isCreated: + return + self._isCreated = True + # restore current views + tabs = ( + (self.controlById(self.IdTabTop), 'LastViewTop'), + (self.controlById(self.IdTabBottom), 'LastViewBottom'), + ) + for tab, nameSetting in tabs: + lastName = self.settings.value(nameSetting) + if lastName: + lastView = self.viewFromName(lastName) + if lastView is not None: + tab.setCurrentWidget(lastView) + + # inform views about their current status + for tab, view in self.views.values(): + view.viewHandleCurrentChanged(tab.currentWidget() == view) + + ######################################################### + ## + ######################################################### + def _handleTabCurrentChanged(self, index, isTop=True): + lastName = self.settings.value('LastViewTop' if isTop else 'LastViewBottom') + if lastName: + lastView = self.viewFromName(lastName) + if lastView is not None: + lastView.viewHandleCurrentChanged(False) + tab = self.controlById(self.IdTabTop if isTop else self.IdTabBottom) + view = tab.currentWidget() + if isTop: + self.settings.setValues(LastViewTop=view.viewName()) + else: + self.settings.setValues(LastViewBottom=view.viewName()) + view.viewHandleCurrentChanged(True) + + + def handleTabTopCurrentChanged(self, index): + return self._handleTabCurrentChanged(index, isTop=True) + + + def handleTabBottomCurrentChanged(self, index): + return self._handleTabCurrentChanged(index, isTop=False) + #********************************************************************************** # #********************************************************************************** @@ -88,34 +166,29 @@ def __init__(self): raise NotImplemetedError() - def displayName(self): + def viewClose(self): + """called when the view is about to be closed""" + + def viewDisplayName(self): """should return the user visible name of the view @return: (QString) """ raise NotImplemetedError() - def icon(self): + def viewHandleCurrentChanged(self, isCurrent): + """called when the view is set to be the current view or looses its current view status""" + + def viewIcon(self): """should return the icon associated to the view @return: (QIcon) """ raise NotImplemetedError() - def objectName(self): + def viewName(self): """should return the internally used id of the view @return: (str) id """ raise NotImplemetedError() - - def widget(self, parent): - """should return the widget contained in the view - @param parent: (QWidget) parent - @return: (QWidget) - note: if the widget is not already created _now_ is the right time to create it - """ - raise NotImplemetedError() - - def close(self): - """called when the view is about to be closed""" #********************************************************************************** # This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jU...@us...> - 2008-07-15 23:56:42
|
Revision: 645 http://fclient.svn.sourceforge.net/fclient/?rev=645&view=rev Author: jUrner Date: 2008-07-15 16:56:30 -0700 (Tue, 15 Jul 2008) Log Message: ----------- this and that Modified Paths: -------------- trunk/fclient/src/fclient/Ui_View.py Modified: trunk/fclient/src/fclient/Ui_View.py =================================================================== --- trunk/fclient/src/fclient/Ui_View.py 2008-07-15 23:55:23 UTC (rev 644) +++ trunk/fclient/src/fclient/Ui_View.py 2008-07-15 23:56:30 UTC (rev 645) @@ -55,12 +55,11 @@ tabTop.removeTab(0) tabBottom = self.controlById(self.IdTabBottom) tabBottom.removeTab(0) - self.connect(tabTop, QtCore.SIGNAL('currentChanged(int)'), self.handleTabTopCurrentChanged) - self.connect(tabBottom, QtCore.SIGNAL('currentChanged(int)'), self.handleTabBottomCurrentChanged) - + # setup splitter splitter = self.controlById(self.IdSplitter) splitter.restoreState(self.settings.value('SplitterPos')) + self.connect(splitter, QtCore.SIGNAL('splitterMoved(int, int)'), self.handleSplitterMoved) def controlById(self, idControl): @@ -78,7 +77,9 @@ view.setParent(tab) i = tab.addTab(view, view.viewIcon(), view.viewDisplayName()) self.views[name] = (tab, view) - + + tab.tabBar().setVisible(tab.count() > 1) + def addBottomViews(self, *views): return self._addViews(False, *views) @@ -94,17 +95,19 @@ return result[1] return None - #TODO: ... - #def setCurrentView(self, view): - # index, tab, view = view - + def setCurrentView(self, name): + result = self.views.get(name, None) + if result is not None: + tab, view = result + tab.setCurrentWidget(view) + return True + return False + ######################################################### ## ######################################################### def closeEvent(self, event): - splitter = self.controlById(self.IdSplitter) - self.settings.setValues(SplitterPos=splitter.saveState()) for tab, view in self.views.values(): view.viewClose() @@ -115,24 +118,31 @@ self._isCreated = True # restore current views - tabs = ( - (self.controlById(self.IdTabTop), 'LastViewTop'), - (self.controlById(self.IdTabBottom), 'LastViewBottom'), - ) - for tab, nameSetting in tabs: - lastName = self.settings.value(nameSetting) - if lastName: - lastView = self.viewFromName(lastName) - if lastView is not None: - tab.setCurrentWidget(lastView) - + tabTop = self.controlById(self.IdTabTop) + lastName = self.settings.value('LastViewTop') + self.setCurrentView(lastName) + + tabBottom = self.controlById(self.IdTabBottom) + lastName = self.settings.value('LastViewBottom') + self.setCurrentView(lastName) + # inform views about their current status for tab, view in self.views.values(): view.viewHandleCurrentChanged(tab.currentWidget() == view) + + # finally connect... not to overwrite settings + self.connect(tabTop, QtCore.SIGNAL('currentChanged(int)'), self.handleTabTopCurrentChanged) + self.connect(tabBottom, QtCore.SIGNAL('currentChanged(int)'), self.handleTabBottomCurrentChanged) + ######################################################### ## ######################################################### + def handleSplitterMoved(self, pos, index): + splitter = self.controlById(self.IdSplitter) + self.settings.setValues(SplitterPos=splitter.saveState()) + + def _handleTabCurrentChanged(self, index, isTop=True): lastName = self.settings.value('LastViewTop' if isTop else 'LastViewBottom') if lastName: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |