Package Camelot :: Package camelot :: Package view :: Module workspace
[frames] | no frames]

Source Code for Module Camelot.camelot.view.workspace

 1  """This module provides a singleton workspace that can be used by views
 
 2  and widget to create new windows or raise existing ones""" 
 3  
 
 4  from PyQt4 import QtGui, QtCore 
 5  
 
 6  import logging 
 7  
 
 8  from camelot.view.model_thread import gui_function 
 9  
 
10  logger = logging.getLogger('camelot.view.workspace') 
11 12 -class DesktopWorkspace(QtGui.QMdiArea):
13 14 @gui_function
15 - def __init__(self, *args):
16 QtGui.QMdiArea.__init__(self, *args) 17 self.setOption(QtGui.QMdiArea.DontMaximizeSubWindowOnActivation) 18 self.setBackground(QtGui.QBrush(QtGui.QColor('white'))) 19 self.setActivationOrder(QtGui.QMdiArea.ActivationHistoryOrder)
20 21 @gui_function
22 - def addSubWindow(self, widget, *args):
23 from camelot.view.controls.view import AbstractView 24 subwindow = QtGui.QMdiArea.addSubWindow(self, widget, *args) 25 if hasattr(widget, 'closeAfterValidation'): 26 subwindow.connect(widget, widget.closeAfterValidation, subwindow, QtCore.SLOT("close()")) 27 28 def create_set_window_title(subwindow): 29 30 def set_window_title(new_title): 31 subwindow.setWindowTitle(new_title)
32 33 return set_window_title
34 35 self.connect(widget, AbstractView.title_changed_signal, create_set_window_title(subwindow)) 36 return subwindow 37
38 -class NoDesktopWorkspace(QtCore.QObject):
39 - def __init__(self):
40 QtCore.QObject.__init__(self) 41 self._windowlist = []
42 43 @gui_function
44 - def addSubWindow(self, widget, *args):
45 self.widget = widget 46 self.widget.setParent(None) 47 self.widget.show() 48 self._windowlist.append(self.widget) 49 self.connect(widget, QtCore.SIGNAL('WidgetClosed()'), self.removeWidgetFromWorkspace)
50 51 @gui_function
52 - def subWindowList(self):
53 return self._windowlist
54 55 @gui_function
57 self._windowlist.remove(self.widget)
58 59 _workspace_ = []
60 61 @gui_function 62 -def construct_workspace(*args, **kwargs):
63 _workspace_.append(DesktopWorkspace()) 64 return _workspace_[0]
65
66 @gui_function 67 -def construct_no_desktop_workspace(*args, **kwargs):
68 _workspace_.append(NoDesktopWorkspace()) 69 return _workspace_[0]
70
71 @gui_function 72 -def get_workspace():
73 return _workspace_[0]
74
75 @gui_function 76 -def has_workspace():
77 return len(_workspace_) > 0
78