OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mdi_example.py

Shows how to add a custom python widget to the mdi-area of OpenStructure.

1 #------------------------------------------------------------------------------
2 # This file is part of the OpenStructure project <www.openstructure.org>
3 #
4 # Copyright (C) 2008-2011 by the OpenStructure authors
5 #
6 # This library is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU Lesser General Public License as published by the Free
8 # Software Foundation; either version 3.0 of the License, or (at your option)
9 # any later version.
10 # This library is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this library; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #------------------------------------------------------------------------------
19 from PyQt4 import QtCore, QtGui
20 
21 from ost import gui
22 import sys, random
23 
24 class Points(QtGui.QWidget):
25  def __init__(self, parent=None):
26  QtGui.QWidget.__init__(self, parent)
27  self.setWindowTitle('Some Points')
28 
29  def paintEvent(self, event):
30  paint = QtGui.QPainter()
31  paint.begin(self)
32  size = self.size()
33  paint.setPen(QtCore.Qt.red)
34  for i in range(5000):
35  x = random.randint(1, size.width()-1)
36  y = random.randint(1, size.height()-1)
37  paint.drawPoint(x, y)
38  paint.setPen(QtCore.Qt.green)
39  for i in range(5000):
40  x = random.randint(1, size.width()-1)
41  y = random.randint(1, size.height()-1)
42  paint.drawPoint(x, y)
43  paint.setPen(QtCore.Qt.blue)
44  for i in range(5000):
45  x = random.randint(1, size.width()-1)
46  y = random.randint(1, size.height()-1)
47  paint.drawPoint(x, y)
48  paint.end()
49 
50 
51 app=gui.GostyApp.Instance()
52 
53 #Get main area widget
54 main_area=app.perspective.main_area
55 
56 pts=Points(main_area.qobject)
57 
58 #Add Widget
59 main_area.AddWidget("Some Points", pts)
60 
61