This repository was archived by the owner on May 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
247 lines (195 loc) · 9.35 KB
/
Copy pathgui.py
File metadata and controls
247 lines (195 loc) · 9.35 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
##
#
# gui.py
# An attempt to parse concept maps, exported from cmap tools...take one
#
# Copyright 2016 Josh Pelkey
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing permissions and limitations under the
# License.
#
##
import os
import wx
import cmap_parse
cmap_files = []
results = ''
filenames = []
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title=title,
size=(750, 350))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
panel = wx.Panel(self)
sizer = wx.GridBagSizer(5, 5)
text1 = wx.StaticText(panel, label="cmap-parse: parsing cmaps and stuff")
sizer.Add(text1, pos=(0, 0), flag=wx.TOP|wx.LEFT|wx.BOTTOM,
border=10)
#icon = wx.StaticBitmap(panel, bitmap=wx.Bitmap('info.png'))
#sizer.Add(icon, pos=(0, 4), flag=wx.TOP|wx.RIGHT|wx.ALIGN_RIGHT,
# border=5)
line = wx.StaticLine(panel)
sizer.Add(line, pos=(1, 0), span=(1, 5),
flag=wx.EXPAND|wx.BOTTOM, border=10)
# Name the root node
text2 = wx.StaticText(panel, label="Root Concept")
sizer.Add(text2, pos=(2, 0), flag=wx.LEFT, border=10)
self.tc1 = wx.TextCtrl(panel)
sizer.Add(self.tc1, pos=(2, 1), span=(1, 3), flag=wx.TOP|wx.EXPAND)
self.tc1.ChangeValue("Sustainability")
# Import the results choice
text3 = wx.StaticText(panel, label="Select concept maps...")
sizer.Add(text3, pos=(3, 0), flag=wx.LEFT|wx.TOP, border=10)
self.tc2 = wx.TextCtrl(panel, style=wx.TE_READONLY)
sizer.Add(self.tc2, pos=(3, 1), span=(1, 3), flag=wx.TOP|wx.EXPAND,
border=5)
button1 = wx.Button(panel, label="Browse...")
sizer.Add(button1, pos=(3, 4), flag=wx.TOP|wx.RIGHT, border=5)
self.Bind(wx.EVT_BUTTON, self.OnOpen, button1)
# Export the results choice
text4 = wx.StaticText(panel, label="Save results as...")
sizer.Add(text4, pos=(4, 0), flag=wx.TOP|wx.LEFT, border=10)
self.tc3 = wx.TextCtrl(panel, style=wx.TE_READONLY)
sizer.Add(self.tc3, pos=(4, 1), span=(1, 3),
flag=wx.TOP|wx.EXPAND, border=5)
button2 = wx.Button(panel, label="Browse...")
sizer.Add(button2, pos=(4, 4), flag=wx.TOP|wx.RIGHT, border=5)
self.Bind(wx.EVT_BUTTON, self.OnOpen2, button2)
# Optional Attributes which do nothing
sb = wx.StaticBox(panel, label="Optional Attributes")
boxsizer = wx.StaticBoxSizer(sb, wx.VERTICAL)
global export_checkbox
export_checkbox = wx.CheckBox(panel, label=" Export Concepts")
boxsizer.Add(export_checkbox,
flag=wx.LEFT|wx.TOP, border=5)
#boxsizer.Add(wx.CheckBox(panel, label=" Cast Hogwarts Spell"),
#flag=wx.LEFT, border=5)
#boxsizer.Add(wx.CheckBox(panel, label=" Enter the Matrix"),
#flag=wx.LEFT|wx.BOTTOM, border=5)
sizer.Add(boxsizer, pos=(5, 0), span=(1, 5), flag=wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT , border=10)
# Halp!
button3 = wx.Button(panel, label='Help')
sizer.Add(button3, pos=(7, 0), flag=wx.LEFT, border=10)
self.Bind(wx.EVT_BUTTON, self.OnHelp, button3)
# Run the codes
button4 = wx.Button(panel, label="Run")
sizer.Add(button4, pos=(7, 3))
self.Bind(wx.EVT_BUTTON, self.OnRun, button4)
# Get me out of here
button5 = wx.Button(panel, label="Exit")
sizer.Add(button5, pos=(7, 4), span=(1, 1),
flag=wx.BOTTOM|wx.RIGHT, border=5)
self.Bind(wx.EVT_BUTTON, self.OnExit, button5)
sizer.AddGrowableCol(2)
panel.SetSizer(sizer)
# Open up all your files
def OnOpen(self, evt):
# Create the dialog. In this case the current directory is forced as the starting
# directory for the dialog, and no default file name is forced. This can easilly
# be changed in your program. This is an 'open' dialog, and allows multitple
# file selections as well.
#
# Finally, if the directory is changed in the process of getting files, this
# dialog is set up to change the current working directory to the path chosen.
dlg = wx.FileDialog(
self, message="Select concept maps",
defaultDir=os.getcwd(),
defaultFile="",
wildcard="txt and cxl files (*.txt; *.cxl)|*.txt;*.cxl",
style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR
)
# Show the dialog and retrieve the user response. If it is the OK response,
# process the data.
if dlg.ShowModal() == wx.ID_OK:
# set us up the file to pass in
global cmap_files, filenames
cmap_files = dlg.GetPaths()
filenames = dlg.GetFilenames()
if len(filenames) > 1:
self.tc2.ChangeValue(filenames[0] + ' + ' + str(len(cmap_files)-1) + ' more files')
else:
self.tc2.ChangeValue(filenames[0])
# Destroy the dialog. Don't do this until you are done with it!
# BAD things can happen otherwise!
dlg.Destroy()
# Save it out
def OnOpen2(self, evt):
# Create the dialog. In this case the current directory is forced as the starting
# directory for the dialog, and no default file name is forced. This can easilly
# be changed in your program. This is an 'save' dialog.
#
# Finally, if the directory is changed in the process of getting files, this
# dialog is set up to change the current working directory to the path chosen.
dlg = wx.FileDialog(
self, message="Save results as",
defaultDir=os.getcwd(),
defaultFile="CmapResults.txt",
style=wx.SAVE | wx.OVERWRITE_PROMPT
)
# Show the dialog and retrieve the user response. If it is the OK response,
# process the data.
if dlg.ShowModal() == wx.ID_OK:
# This returns a Python list of files that were selected.
global results
results = dlg.GetPath()
self.tc3.ChangeValue(results)
# Destroy the dialog. Don't do this until you are done with it!
# BAD things can happen otherwise!
dlg.Destroy()
# Run the program...finally
def OnRun (self,e):
if self.tc2.IsEmpty():
dlg = wx.MessageDialog( self, "Please select your cmap files.", "Missing info", wx.OK)
dlg.ShowModal()
dlg.Destroy()
elif self.tc3.IsEmpty():
dlg = wx.MessageDialog( self, "Please choose where to save results.", "Missing info", wx.OK)
dlg.ShowModal()
dlg.Destroy()
else:
root_concept = self.tc1.GetValue ()
cmap_parse.CmapParse (cmap_files, results, filenames, root_concept, export_checkbox.GetValue())
dlg = wx.MessageDialog( self, "Your results are ready!", "Complete!", wx.OK)
dlg.ShowModal()
dlg.Destroy()
# Help text
def OnHelp(self,e):
# A message dialog box with an OK button. wx.OK is a standard ID in wxWidgets.
dlg = wx.MessageDialog( self, "cmap-parse\n\
An attempt to parse concept maps, exported from cmap tools...take one\n\
------------------------------------------------------------------------------------------\n\n\
Step 1: Set your root node name. This is the 'top' of your concept map. We will start at this node for many calculations.\n\n\
Step 2: Choose your cmap files. These must either be cxl files (recommended, as they are easier to export in bulk from Cmap Tools), or txt files exported 'Propositions as text...' from Cmap Tools.\n\n\
Step 3: Choose your export path and filename. Results will be exported as plain-text.\n\n\
Step 4: Click Run and go view your results! It's best to copy/paste them in to a spreadsheet.\n\n\
------------------------------------------------------------------------------------------\n\
Copyright 2016 Josh Pelkey\n\n\
Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n\
use this file except in compliance with the License. You may obtain a copy of\n\
the License at\n\n\
http://www.apache.org/licenses/LICENSE-2.0\n\n\
Unless required by applicable law or agreed to in writing, software distributed\n\
under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR\n\
CONDITIONS OF ANY KIND, either express or implied. See the License for the specific\n\
language governing permissions and limitations under the License."
,
"cmap-parse help", wx.OK)
dlg.ShowModal() # Show it
dlg.Destroy() # finally destroy it when finished.
# Quit the program
def OnExit(self,e):
self.Close(True)
if __name__ == '__main__':
app = wx.App()
Example(None, title="cmap-parse")
app.MainLoop()