Package pyforms :: Package gui :: Package Controls :: Module ControlMdiArea |
[hide private]
[frames] | no frames]

# Source Code for Module pyforms.gui.Controls.ControlMdiArea

      1  #!/usr/bin/python
      2  # -*- coding: utf-8 -*-
      3
      4  """ pyforms.gui.Controls.ControlMdiArea"""
      5
      6  from PyQt4 import QtCore
      7  from PyQt4.QtGui import QMdiArea
      8  from pyforms.gui.Controls.ControlBase import ControlBase
      9
     10  __author__ = "Ricardo Ribeiro"
     11  __copyright__ = ""
     12  __credits__ = "Carlos Mão de Ferro"
     13  __license__ = "MIT"
     14  __version__ = "0.0"
     15  __maintainer__ = ["Ricardo Ribeiro", "Carlos Mão de Ferro"]
     16  __email__ = ["ricardojvr at gmail.com", "cajomferro at gmail.com"]
     17  __status__ = "Development"
     18
     19
     20 -class ControlMdiArea(ControlBase, QMdiArea):
     21      """
     22      The ControlMdiArea wraps a QMdiArea widget which provides
     23       an area in which MDI windows are displayed.
     24      """
     25
     26 -    def __init__(self, label=""):
     27          QMdiArea.__init__(self)
     28          ControlBase.__init__(self, label)
     29          self._value = []
     30          self._showCloseButton = True
     31          self._openWindows = []
     32
     33 -    def initForm(self): pass
     34
     35 -    def __flags(self):
     36          flags = QtCore.Qt.SubWindow
     37
     38          flags |= QtCore.Qt.WindowTitleHint
     39          flags |= QtCore.Qt.WindowMinimizeButtonHint
     40          flags |= QtCore.Qt.WindowMaximizeButtonHint
     41          if self._showCloseButton:
     42              flags |= QtCore.Qt.WindowSystemMenuHint
     43              flags |= QtCore.Qt.WindowCloseButtonHint
     44
     45          return flags
     46
     47 -    def __add__(self, other):
     48          if other.title not in self._openWindows:
     49              if not other._formLoaded:
     50                  other.initForm()
     51              other.subwindow = self.addSubWindow(other)
     52              other.subwindow.overrideWindowFlags(self.__flags())
     53              other.show()
     54              other.closeEvent = self._subWindowClosed
     55
     56              self.value.append(other)
     57              self._openWindows.append(other.title)
     58          return self
     59
     60 -    def _subWindowClosed(self, closeEvent):
     61          activeWidget = self.activeSubWindow().widget()
     62          if activeWidget in self._value:
     63              self._value.remove(activeWidget)
     64          self.removeSubWindow(self.activeSubWindow())
     65          self._openWindows.remove(activeWidget.title)
     66          closeEvent.accept()
     67
     68      ##########################################################################
     69      ############ Properties ##################################################
     70      ##########################################################################
     71
     72      @property
     73 -    def showCloseButton(self): return self._showCloseButton
     74
     75      @showCloseButton.setter
     76 -    def showCloseButton(self, value): self._showCloseButton = value
     77
     78      @property
     79 -    def label(self): return self._label
     80
     81      @label.setter
     82 -    def label(self, value): self._label = value
     83
     84      @property
     85 -    def form(self): return self
     86
     87      @property
     88 -    def value(self): return ControlBase.value.fget(self)
     89
     90      @value.setter
     91 -    def value(self, value):
     92          self.closeAllSubWindows()
     93          self._value = []
     94
     95          if isinstance(value, list):
     96              for w in value:
     97                  self += w
     98          else:
     99              self += value
    100
    101          ControlBase.value.fset(self, self._value)
    102