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

# Source Code for Module pyforms.gui.standaloneManager

      1  #!/usr/bin/python
      2  # -*- coding: utf-8 -*-
      3
      4  '''
      5  @author: Ricardo Ribeiro
      6  @credits: Ricardo Ribeiro
      7  @license: MIT
      8  @version: 0.0
      9  @maintainer: Ricardo Ribeiro
     10  @email: ricardojvr@gmail.com
     11  @status: Development
     12  @lastEditedBy: Carlos Mão de Ferro (carlos.maodeferro@neuro.fchampalimaud.org)
     13  '''
     14
     15  import sys
     16  from PyQt4 import QtGui, QtCore
     17
     18  from pyforms.gui.Controls.ControlDockWidget import ControlDockWidget
     19
     20
     21 -class StandAloneContainer(QtGui.QMainWindow):
     22
     23 -    def __init__(self, ClassObject):
     24          super(QtGui.QMainWindow, self).__init__()
     25          w = ClassObject()
     26
     27          w.initForm()
     28          self.setCentralWidget(w)
     29          self.setWindowTitle(w.title)
     30
     31          docks = {}
     32          for name, item in w.formControls.items():
     33              if isinstance(item, ControlDockWidget):
     34                  if item.side not in docks:
     35                      docks[item.side] = []
     36                  docks[item.side].append((name, item))
     37
     38          for key, widgets in docks.items():
     39              side = QtCore.Qt.RightDockWidgetArea
     40              if key == 'left':
     41                  side = QtCore.Qt.LeftDockWidgetArea
     42              elif key == 'right':
     43                  side = QtCore.Qt.RightDockWidgetArea
     44              elif key == 'top':
     45                  side = QtCore.Qt.TopDockWidgetArea
     46              elif key == 'bottom':
     47                  side = QtCore.Qt.BottomDockWidgetArea
     48              else:
     49                  side = QtCore.Qt.LeftDockWidgetArea
     50
     51              if isinstance(widgets, list):
     52                  for name, widget in widgets:
     53                      dock = QtGui.QDockWidget(self)
     54                      dock.setFeatures(QtGui.QDockWidget.DockWidgetFloatable |
     55                                       QtGui.QDockWidget.DockWidgetClosable | QtGui.QDockWidget.DockWidgetMovable)
     56                      dock.setObjectName(name)
     57
     58                      # print dock.objectName(),1
     59                      dock.setWidget(widget.form)
     60                      dock.setWindowTitle(widget.label)
     61                      widget.dock = dock
     62                      if not widget._show: dock.hide()
     63
     64                      self.addDockWidget(side, dock)
     65              else:
     66                  dock = QtGui.QDockWidget(self)
     67                  dock.setFeatures(QtGui.QDockWidget.DockWidgetFloatable |
     68                                   QtGui.QDockWidget.DockWidgetClosable | QtGui.QDockWidget.DockWidgetMovable)
     69                  # dock.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
     70                  # dock.layout().setMargin(0)
     71
     72                  # print dock.objectName(), 2
     73                  dock.setObjectName(name)
     74                  dock.setWidget(widget.form)
     75                  self.addDockWidget(side, dock)
     76                  dock.setWindowTitle(widget.label)
     77                  widget.dock = dock
     78                  if not widget._show: dock.hide()
     79
     80          if len(w.mainmenu) > 0:
     81              self.__initMainMenu(w.mainmenu)
     82
     83          try:
     84              self.loadStyleSheetFile('style.css')
     85          except:
     86              pass
     87
     88 -    def __initMainMenu(self, options, keys={}):
     89          menubar = self.menuBar()
     90          for m in options:
     91              for key, menus in m.items():
     92                  menu = menubar.addMenu(key)
     93                  for m1 in menus:
     94                      if isinstance(m1, str) and m1 == "-":
     95                          menu.addSeparator()
     96                      else:
     97                          for text, func in m1.items():
     98                              action = QtGui.QAction(text, self)
     99                              if func:
    100                                  action.triggered.connect(func)
    101                                  menu.addAction(action)
    102
    103 -    def loadStyleSheetFile(self, filename):
    104          infile = open(filename, 'r')
    105          text = infile.read()
    106          infile.close()
    107          self.setStyleSheet(text)
    108
    109
    110 -def startApp(ClassObject):
    111      app = QtGui.QApplication(sys.argv)
    112      w = StandAloneContainer(ClassObject)
    113      w.showMaximized()
    114      app.exec_()
    115