~shadowrobot/sr-ros-interface/release1.2

« back to all changes in this revision

Viewing changes to shadow_robot/sr_control_gui/src/sr_control_gui/plugins/generic_plugin.py

  • Committer: Ugo Cupcic
  • Date: 2010-11-03 16:25:21 UTC
  • mfrom: (0.1.117 trunk)
  • Revision ID: ugo@shadowrobot.com-20101103162521-bht8o7tas3js0xiy
mergedĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
from yapsy.IPlugin import IPlugin
 
4
 
 
5
from PyQt4 import QtCore, QtGui, Qt
 
6
from config import *
 
7
 
 
8
class MyMdiSubWindow(QtGui.QMdiSubWindow):
 
9
    def __init__(self, parent):
 
10
        """
 
11
        This MdiSubWindow removes itself from the MdiArea when it closes. It can then be reopened.
 
12
        """
 
13
        self.container = 0
 
14
        self.parent = parent
 
15
        QtGui.QMdiSubWindow.__init__(self)
 
16
        
 
17
    def set_container(self, container):
 
18
        self.container = container
 
19
        
 
20
    def closeEvent(self, event):
 
21
        self.parent.on_close()
 
22
        self.container.removeSubWindow(self)
 
23
        #self.container.closeActiveSubWindow()
 
24
 
 
25
class GenericPlugin(IPlugin):  
 
26
    name = "GenericPlugin"
 
27
    
 
28
    def __init__(self):
 
29
        self.id = 0
 
30
        self.parent = 0        
 
31
        self.window = MyMdiSubWindow(self)
 
32
        #self.window.setAttribute(QtCore.Qt.WA_DeleteOnClose)
 
33
        self.window.widget()
 
34
        self.window.setWindowTitle(self.name)
 
35
        self.is_window_opened = False
 
36
        
 
37
    def set_parent(self, parent):
 
38
        self.parent = parent
 
39
        self.window.set_container(self.parent.container)
 
40
                
 
41
    def activate(self):
 
42
        if not self.is_window_opened:
 
43
            self.parent.container.addSubWindow(self.window)
 
44
            self.window.show()
 
45
            self.is_window_opened = True
 
46
        else:
 
47
            self.parent.container.setActiveSubWindow(self.window)
 
48
            
 
49
    
 
50
    def set_icon(self, path):
 
51
        self.window.setWindowIcon(QtGui.QIcon(path))
 
52
    
 
53
    def on_close(self):
 
54
        self.is_window_opened = False
 
55
        self.window.close()
 
56
 
 
57
    def depends(self):
 
58
        return Config.generic_plugin_config.dependencies
 
 
b'\\ No newline at end of file'