-
Notifications
You must be signed in to change notification settings - Fork 3
/
propel_utility_dev_grt.py
executable file
·193 lines (173 loc) · 5.56 KB
/
propel_utility_dev_grt.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import sys
import os
sys.path.append(str(os.path.dirname(os.path.realpath(__file__))) + '/PropelUtility')
# import the wb module
from wb import *
# import the grt module
import grt
# import the mforms module for GUI stuff
import mforms
# import the re module
import re
# import the pickle module
import pickle
# import etree module
import ElementTree as ET
# define PropelUtilisty class
import new
from PropelForm import *
import PropelDatabase
import PropelTabGrid
import PropelTabDatabase
import PropelTabTables
import PropelTabColumns
import PropelTabForeignKeys
import PropelTabIndices
import PropelTabBehaviors
import PropelTabExternalSchemas
import PropelTabExport
import PropelTabFile
ModuleInfo = DefineModule(name= "Propel Utilities (Dev)", author= "mazenovi", version="1.0")
class PropelUtilityGUI(mforms.Form):
tabs_list = [
'database',
'tables',
'columns',
'foreign_keys',
'indices',
'behaviors',
'external_schemas',
'export'
#'import',
#'settings',
]
tabs = {
'database':{
'name':'Database',
'class':PropelTabDatabase,
'method':'PropelTabDatabase'
},
'tables':{
'name':'Tables',
'class':PropelTabTables,
'method':'PropelTabTables'
},
'columns':{
'name':'Columns',
'class':PropelTabColumns,
'method':'PropelTabColumns'
},
'foreign_keys':{
'name':'Foreign Keys',
'class':PropelTabForeignKeys,
'method':'PropelTabForeignKeys'
},
'indices':{
'name':'Indices',
'class':PropelTabIndices,
'method':'PropelTabIndices'
},
'behaviors':{
'name':'Behaviors',
'class':PropelTabBehaviors,
'method':'PropelTabBehaviors'
},
'external_schemas':{
'name':'External Schemas',
'class':PropelTabExternalSchemas,
'method':'PropelTabExternalSchemas'
},
'export':{
'name':'Export',
'class':PropelTabExport,
'method':'PropelTabExport'
}#,
#'import':{
# 'name':'Import',
# 'class':PropelTabFile,
# 'method':'PropelTabFile'
#},
#'settings':{
# 'name':'Preferences',
# 'class':PropelTabFile,
# 'method':'PropelTabFile'
#}
}
defaults = {
'width':1040,
'height':700,
'tab_index':0
}
widget = {}
def __init__(self, catalog):
self.db = PropelDatabase.PropelDatabase(grt.root.wb.doc.physicalModels[0].catalog)
# have to store app prefernces in catalog.customData :/
for k, v in self.defaults.iteritems():
if not self.db.wbObject.customData.has_key(k):
self.db.cache[k] = v
else:
self.db.cache[k] = self.db.wbObject.customData[k]
# main windows : self
mforms.Form.__init__(self, None, mforms.FormResizable)
self.set_title("Propel Utility")
self.set_size(self.defaults['width'], self.defaults['height'])
# main box
box = PropelForm.spaced_box(False)
# header
box.add(self.header_box(), False, False)
# main tabs
self.tvMain = mforms.newTabView(False)
for name in self.tabs_list:
tTab = getattr(self.tabs[name]['class'], self.tabs[name]['method'])(False, name, self.db)
if name == 'export':
exportTab = tTab
self.tvMain.add_page(tTab, self.tabs[name]['name'])
self.tvMain.relayout()
self.tvMain.set_active_tab(int(self.db.get_tab_index))
self.tvMain.add_tab_changed_callback(lambda: exportTab.refresh_text_editor_schema_box())
box.add(self.tvMain, True, True)
self.set_content(box)
self.ui_ok_cancel_button(box)
def header_box(self):
headBox = mforms.newBox(True)
img = mforms.newImageBox()
img.set_image(str(os.path.dirname(os.path.realpath(__file__))) + '/PropelUtility/propel-logo.png')
img.set_size(self.defaults['width']/2-PropelForm.defaults['space']*2, 100)
headBox.add(img, False, False)
return headBox
def ui_ok_cancel_button(self, box):
tBox = PropelForm.spaced_box(True)
#label = mforms.newLabel("remember to validate your changes by press OK, and save you .mwb file in MySQLWorkbench to save you Propel Utilty changes ;)")
#tBox.add(label, False, True)
self.cancelButton = mforms.newButton()
self.cancelButton.set_text("cancel")
tBox.add_end(self.cancelButton, False, True)
self.okButton = mforms.newButton()
self.okButton.set_text("ok")
tBox.add_end(self.okButton, False, True)
self.okButton.add_clicked_callback(self.save)
box.add_end(tBox, False, True)
def save(self):
self.db.set_tab_index = self.tvMain.get_active_tab()
self.db.save()
def run(self):
self.run_modal(self.okButton, self.cancelButton)
@ModuleInfo.plugin("wb.catalog.util.PropelUtilityDev", caption= "Propel Utilty (Dev)", input= [wbinputs.currentCatalog()], pluginMenu= "Catalog", type="standalone")
@ModuleInfo.export(grt.INT, grt.classes.db_Catalog)
def PropelUtilityDev(catalog):
form = PropelUtilityGUI(catalog)
form.run()
return 0
@ModuleInfo.plugin("wb.catalog.util.PropelEraseDev", caption= "Propel Erase All Data (Dev)", input= [wbinputs.currentCatalog()], pluginMenu= "Catalog", type="standalone")
@ModuleInfo.export(grt.INT, grt.classes.db_Catalog)
def PropelEraseDev(catalog):
if mforms.Utilities.show_warning("Warning", "All propel data of you will be lost", "OK", "NO IT'S A JOKE", ""):
db = PropelDatabase.PropelDatabase(grt.root.wb.doc.physicalModels[0].catalog)
# have to store app prefernces in catalog.customData :/
for k, v in PropelUtilityGUI.defaults.iteritems():
if not db.wbObject.customData.has_key(k):
db.cache[k] = v
else:
db.cache[k] = db.wbObject.customData[k]
db.erase()
return 0