SF.net SVN: fclient:[853] trunk/fclient/fclient/impl/View.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-08-02 09:42:36
|
Revision: 853
http://fclient.svn.sourceforge.net/fclient/?rev=853&view=rev
Author: jUrner
Date: 2008-08-02 09:42:45 +0000 (Sat, 02 Aug 2008)
Log Message:
-----------
more bells
Modified Paths:
--------------
trunk/fclient/fclient/impl/View.py
Modified: trunk/fclient/fclient/impl/View.py
===================================================================
--- trunk/fclient/fclient/impl/View.py 2008-08-02 09:41:53 UTC (rev 852)
+++ trunk/fclient/fclient/impl/View.py 2008-08-02 09:42:45 UTC (rev 853)
@@ -1,9 +1,7 @@
-#FIXES
#***************************************************************************
-# [0001]
+#TODO:
#
-# QTabWidget.closeEvent() does not seem to propagate close events
-# to child widgets
+# x. shortcuts for "Go to" menus and items
#
#
#***************************************************************************
@@ -21,7 +19,7 @@
#**********************************************************************************
#
#**********************************************************************************
-class Actions(config.ActionsBase):
+class ViewActions(config.ActionsBase):
def __init__(self, parent):
config.ActionsBase.__init__(self, parent)
@@ -33,8 +31,14 @@
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"""
@@ -42,19 +46,17 @@
config.GlobalFeedbackBase.__init__(self, parent, idGlobalFeedback)
# menus
- self.menus = []
+ self.menu = None
if self.menuBar is not None and hasattr(parent, 'fcViewObject'):
- menu = QtGui.QMenu(parent.fcViewObject.displayName, self.menuBar)
- parent.populateMenu(menu)
- self.menus.append(menu)
- self.menuBar.addViewMenu(menu)
+ self.menu = QtGui.QMenu(parent.fcViewObject.displayName, self.menuBar)
+ parent.populateMenu(self.menu)
+ self.menuBar.addViewMenu(self.menu)
def setVisible(self, flag):
- for menu in self.menus:
- menu.children()[0].setVisible(flag)
+ if self.menu is not None:
+ self.menu.children()[0].setEnabled(flag)
-
class Settings(config.SettingsBase):
_key_ = config.IdViewWidget
_settings_ = (
@@ -62,10 +64,11 @@
('LastViewBottom', 'String', '', config.SettingScopePrivate),
('SplitterPos', 'ByteArray', QtCore.QByteArray(), config.SettingScopePrivate),
('ShowTopTabBar', 'Bool', True, config.SettingScopePrivate),
+ ('ShowBottomTabBar', 'Bool', True, config.SettingScopePrivate),
)
-class ViewObject(config.ViewObject):
+class ViewViewObject(config.ViewObject):
def __init__(self, parent):
config.ViewObject. __init__(self, parent)
@@ -74,6 +77,17 @@
self.displayName=self.trUtf8('View')
self.icon=QtGui.QIcon()
+
+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,
+ }
+
#***********************************************************************
#
#***********************************************************************
@@ -82,22 +96,30 @@
IdSplitter = 'splitter'
IdTabTop = 'tabTop'
IdTabBottom = 'tabBottom'
-
def __init__(self, parent, idGlobalFeedback=config.IdMainWindow):
QtGui.QWidget.__init__(self, parent)
- self._isCreated = False
+ # setup ui
+ self.isCreated = False
+ self.menuGoToTopView = QtGui.QMenu(self)
+ self.menuGoToBottomView = QtGui.QMenu(self)
+ self.setupUi(self)
- self.views = {}
-
- self.setupUi(self)
+ # setup ...
config.ObjectRegistry.register(self)
- self.fcActions = Actions(self)
+ self.fcActions = ViewActions(self)
self.fcSettings = Settings().restore()
- self.fcViewObject = ViewObject(self)
+ self.fcViewObject = ViewViewObject(self)
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)
@@ -109,120 +131,180 @@
splitter.restoreState(self.fcSettings.value('SplitterPos'))
self.connect(splitter, QtCore.SIGNAL('splitterMoved(int, int)'), self.onSplitterMoved)
- # setup actions
- showTopTabBar = self.fcSettings.value('ShowTopTabBar')
- self.fcActions['ActionShowTopTabBar'].setChecked(showTopTabBar)
- tabWidgetTop.tabBar().setVisible(showTopTabBar)
-
-
- def controlById(self, idControl):
- return getattr(self, idControl)
-
-
+ ###################################
+ ## 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:
- name = view.fcViewObject.name
- if not name:
+ viewName = view.fcViewObject.name
+ if not viewName:
raise ValueError('view must have a name')
- if name in self.views:
- raise ValueError('view with that name is already present: %s' % name)
+ if viewName in self.viewData:
+ raise ValueError('view with that name is already present: %s' % viewName)
view.setParent(tabWidget)
- i = tabWidget.addTab(view, view.fcViewObject.icon, view.fcViewObject.displayName)
- self.views[name] = (tabWidget, view)
-
+ tabWidget.addTab(view, view.fcViewObject.icon, view.fcViewObject.displayName)
+ self.viewData[viewName] = viewData = ViewData(tabWidget, view)
+
+ # 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.fcViewObject.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)
+ view = tabWidget.currentWidget()
+ if view is not None:
+ return view.objectName()
+ 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.addMenu(self.menuGoToTopView)
+ menu.addMenu(self.menuGoToBottomView)
return menu
-
-
-
+
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 viewFromName(self, name):
- result = self.views.get(name, None)
- if result is not None:
- return result[1]
+ """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)
+ 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.viewClose()
+
def hideEvent(self, event):
self.fcGlobalFeedback.setVisible(False)
-
-
+
def showEvent(self, event):
self.fcGlobalFeedback.setVisible(True)
-
-
- #########################################################
- ##
- #########################################################
- def closeEvent(self, event):
- for tab, view in self.views.values():
- view.viewClose()
-
-
- def showEvent(self, event):
- if self._isCreated:
+ if self.isCreated:
return
- self._isCreated = True
+ self.isCreated = True
- # restore current views
+ # restore last selected views (could be costy, so do it here)
tabWidgetTop = self.controlById(self.IdTabTop)
- lastName = self.fcSettings.value('LastViewTop')
- self.setCurrentView(lastName)
+ 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)
- lastName = self.fcSettings.value('LastViewBottom')
- self.setCurrentView(lastName)
+ 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):
tabWidget = self.controlById(self.IdTabTop)
view = tabWidget.currentWidget()
+ viewData = self.viewData[view.objectName()]
+ viewData.actions['ActionGoTo'].setChecked(True)
self.fcSettings.setValues(LastViewTop=view.fcViewObject.name)
-
def onTabBottomCurrentChanged(self, index):
tab = self.controlById(self.IdTabBottom)
view = tab.currentWidget()
+ viewData = self.viewData[view.objectName()]
+ viewData.actions['ActionGoTo'].setChecked(True)
self.fcSettings.setValues(LastViewBottom=view.fcViewObject.name)
#**********************************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|