-
Notifications
You must be signed in to change notification settings - Fork 2
/
MultiTabSection.py
117 lines (88 loc) · 3.57 KB
/
MultiTabSection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Name : Omero RT
Description : Omero plugin
Date : August 15, 2010
copyright : (C) 2010 by Giuseppe Sucameli (Faunalia)
email : [email protected]
***************************************************************************/
Omero plugin
Works done from Faunalia (http://www.faunalia.it) with funding from Regione
Toscana - S.I.T.A. (http://www.regione.toscana.it/territorio/cartografia/index.html)
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from ui.multiTabSection_ui import Ui_MultiTabSection
from AutomagicallyUpdater import *
class MultiTabSection(QWidget, MappingOne2Many, Ui_MultiTabSection):
def __init__(self, parent=None, basePageWidget=QWidget, baseTabName="Tab ", table=None, pk=None, parentPk=None):
QWidget.__init__(self, parent)
MappingOne2Many.__init__(self, table, pk, parentPk)
self.setupUi(self)
self.baseTabName = baseTabName
self.basePageWidget = basePageWidget
self.clear()
self.connect(self.tabWidget, SIGNAL( "currentChanged(int)" ), self.aggiornaPulsanti)
self.connect(self.btnDelete, SIGNAL( "clicked()" ), self.btnDeleteTabClicked)
self.connect(self.btnNew, SIGNAL( "clicked()" ), self.btnAddTabClicked)
self.aggiornaPulsanti()
def clear(self):
for i in range(self.tabWidget.count()):
w = self.tabWidget.widget(0)
self.tabWidget.removeTab(0)
del w
self.tabWidget.clear()
first = self.addTab()
def aggiornaPulsanti(self):
self.btnDelete.setEnabled(self.tabWidget.currentIndex() > 0)
def btnDeleteTabClicked(self):
self.deleteTab()
def deleteTab(self):
index = self.tabWidget.currentIndex()
if index <= 0:
return
widget = self.tabWidget.widget(index)
ret = widget.delete() # elimina dal db
self.delChildRef(widget) # elimina il riferimento
self.tabWidget.removeTab(index)
del widget
for i in range(1, self.tabWidget.count()):
text = "%s%d" % (self.baseTabName, i+1)
self.tabWidget.setTabText(i, str(text) )
return ret
def btnAddTabClicked(self):
index = self.addTab()
self.tabWidget.setCurrentIndex(index)
def addTab(self):
index = self.tabWidget.addTab(self.basePageWidget(), "")
text = "%s%d" % (self.baseTabName, index+1)
self.tabWidget.setTabText(index, str(text) )
self.addChildRef(self.tabWidget.widget(index))
return index
def setBaseTabName(self, name):
self.baseTabName = name
def setBasePageWidget(self, widget):
self.basePageWidget = widget
def setBaseTab(self, widget, name):
self.setBasePageWidget(widget)
self.setBaseTabName(name)
def addNewChild(self):
self.addTab()
return True
#def setupLoader(self, ID=None):
# MappingOne2Many.setupUpdater(self, ID)
# self.tabWidget.setCurrentIndex(0)
def toHtml(self, *args, **kwargs):
html = ""
for index in range(self.tabWidget.count()):
html += self.tabWidget.widget(index).toHtml(index, *args, **kwargs)
return html