SF.net SVN: fclient:[928] trunk/fclient/fclient/impl/View.py
Status: Pre-Alpha
Brought to you by:
jurner
From: <jU...@us...> - 2008-08-16 10:56:43
|
Revision: 928 http://fclient.svn.sourceforge.net/fclient/?rev=928&view=rev Author: jUrner Date: 2008-08-16 10:56:48 +0000 (Sat, 16 Aug 2008) Log Message: ----------- no longer needed Removed Paths: ------------- trunk/fclient/fclient/impl/View.py Deleted: trunk/fclient/fclient/impl/View.py =================================================================== --- trunk/fclient/fclient/impl/View.py 2008-08-16 10:56:12 UTC (rev 927) +++ trunk/fclient/fclient/impl/View.py 2008-08-16 10:56:48 UTC (rev 928) @@ -1,358 +0,0 @@ -#*************************************************************************** -#TODO: -# -# x. shortcuts for "Go to" menus and items -# x. detatch tabs -# -#*************************************************************************** -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 .tpls.Ui_ViewWidgetTpl 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 ViewViewObject(config.ViewObject): - - def __init__(self, parent): - config.ViewObject. __init__(self, parent) - - self.name=parent.objectName() - 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, - } - -#*********************************************************************** -# -#*********************************************************************** -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 ... - config.ObjectRegistry.register(self) - self.fcActions = ViewActions(self) - self.fcSettings = Settings().restore() - 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) - 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.fcViewObject.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.setParent(tabWidget) - 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.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) - 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) - 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): - 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) - -#********************************************************************************** -# -#********************************************************************************** -#NOTE: to self. no need to register views to config.ObjectRegistry. they are just -# opaque objects private to ViewWidget -class View(object): - """base class for views ond by L{ViewWidget}""" - - def __init__(self): - raise NotImplemetedError() - - 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 viewIcon(self): - """should return the icon associated to the view - @return: (QIcon) - """ - raise NotImplemetedError() - - def viewName(self): - """should return the internally used id of the view - @return: (str) id - """ - raise NotImplemetedError() - -#********************************************************************************** -# -#********************************************************************************** -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. |