SF.net SVN: fclient: [624] trunk/fclient/src/fclient/Ui_View.py
Status: Pre-Alpha
Brought to you by:
jurner
|
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.
|