-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathchooseFormats.py
330 lines (253 loc) · 13.4 KB
/
chooseFormats.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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
from PyQt4 import QtGui
import sys
import os
import json
import chooseFormatsGUI
imageTypes = {"CT Raw":"-i2","FM Sector":"-i3","FM XFD":"-i3a","MFM":"-i4","Amiga DOS":"-i5","CBM DOS":"-i6","CBM DOS ErrMap":"-i7","Apple DOS 3.2":"-i8","Apple DOS 3.3":"-i8a","DSK":"-i9","Apple DOS 400/800K":"-i10","EMU":"-i11","EMU2":"-i12","Amiga Disk Spare":"-i13","DEC RX01":"-i14","DEC RX02":"-i15","CBM Micro Prose":"-i16","CBM RapidLok":"-i17","CBM Datasoft":"-i18","CBM Vorpal":"-i19","CBM V-MAX":"-i20","CBM Teque":"-i21","CBM TDP":"-i22","CBM GCR":"-i22a","CBM Big5":"-i23","CBM DOS":"-i24","CBM OziSoft":"-i25"}
imageFmts = {'-i3a': 'FM XFD', '-i24': 'CBM DOS', '-i25': 'CBM OziSoft', '-i20': 'CBM V-MAX', '-i21': 'CBM Teque', '-i22': 'CBM TDP', '-i23': 'CBM Big5', '-i22a': 'CBM GCR', '-i9': 'DSK', '-i8': 'Apple DOS 3.2', '-i3': 'FM Sector', '-i2': 'CT Raw', '-i5': 'Amiga DOS', '-i4': 'MFM', '-i7': 'CBMDOS ErrMap', '-i15': 'DEC RX02', '-i14': 'DEC RX01', '-i17': 'CBM RapidLok', '-i16': 'CBM MicroProse', '-i11': 'EMU', '-i10': 'Apple DOS 400/800K', '-i13': 'Amiga Disk Spare', '-i12': 'EMU2', '-i19': 'CBM Vorpal', '-i18': 'CBM Datasoft', '-i8a': 'AppleDOS3.3'}
endTracks = ("x","-e73","-e72","-e79","-e39","-e34","-e76","-e81")
sideModes = {"Both sides":"-g2","Side 0":"-g0","Side 1":"-g1"}
sideModesRv = {'-g2': 'Both sides', '-g1': 'Side 1', '-g0': 'Side 0'}
sectorSizes = {"128":"-z0","256":"-z1","512":"-z3","1024":"-z2"}
sectorSizesRv = {'-z0': '128', '-z1': '256', '-z2': '1024', '-z3': '512'}
sectorCounts = {"Exactly":"+","At most":"-"}
sectorCountsRv = {'+': 'Exactly', '-': 'At most'}
trackDistances = {"80":"-k1","40":"-k2"}
trackDistancesRv = {"-k1":"80","-k2":"40"}
targetRPMsBasic = {"300":"-v300","288":"-v288","360":"-v360","150":"-v150"}
targetRPMsBasicRv = {'-v150': '150', '-v288': '288', '-v300': '300', '-v360': '360'}
driveDensities = {"High":"-dd0","Low":"-dd1"}
driveDensitiesRv = {"-dd0":"High","-dd1":"Low"}
outputTrackOrders = {"Side 0 descending":"-oo1","Side 1 descending":"-oo2","Side 1 then side 0":"-oo4","Side oriented":"-oo8"}
outputTrackOrdersRv = {'-oo1': 'Side 0 descending', '-oo8': 'Side oriented', '-oo2': 'Side 1 descending', '-oo4': 'Side 1 then side 0'}
global spath
spath = os.getenv("HOME") + '/.diskFormatID/settings.json'
class addTypes(QtGui.QMainWindow, chooseFormatsGUI.Ui_addTypes):
def __init__(self, parent=None):
global spath
super(addTypes, self).__init__(parent)
self.setupUi(self)
self.imageTypeCB.clear()
# populate the combo box with the keys in the image variables defined above
self.imageTypeCB.addItems(imageTypes.keys())
#set the default value actual defaults
#set most of the combo boxes to not editable/greyed out by default (that will be changed if the check box is unchecked
self.imageTypeCB.setCurrentIndex(self.imageTypeCB.findText('MFM'))
self.trackDistanceCB.addItems(trackDistances.keys())
self.trackDistanceCB.setCurrentIndex(self.trackDistanceCB.findText('40'))
self.trackDistanceCB.setEnabled(False)
self.sectorCountCB.addItems(sectorCounts.keys())
self.sectorCountCB.setEnabled(False)
self.sideModeCB.addItems(sideModes.keys())
self.sideModeCB.setCurrentIndex(self.sideModeCB.findText('Both sides'))
self.sideModeCB.setEnabled(False)
self.sectorSizeCB.addItems(sectorSizes.keys())
self.sectorSizeCB.setCurrentIndex(self.sectorSizeCB.findText('512'))
self.sectorSizeCB.setEnabled(False)
self.startTrack.setEnabled(False)
self.endTrack.setEnabled(False)
self.sectorCount.setEnabled(False)
self.targetRPMCB.addItems(targetRPMsBasic.keys())
self.targetRPMCB.setEnabled(False)
# if the reset all button is clicked launch that function
self.resetTypes.clicked.connect(self.reset_types)
#open the spath file for reading
if os.stat(spath).st_size != 0:
self.updateTextBrowserFromJSON()
else:
#pass if file is empty
pass
def reset_types(self):
global spath
#open the json file and get the contents
with open(spath ,'r') as settings_file:
settings = json.load(settings_file)
# try deleting the outputFormats element/key
try:
del settings['outputFormats']
except KeyError:
pass
#write back the remaining json
jsoutput = json.dumps(settings)
outfile = open(spath, 'w')
outfile.write(jsoutput)
outfile.close()
# clear what is in the text browser in the gui
self.settingsDisplay.clear()
# process that clearance event
QtGui.QApplication.processEvents()
def save_and_add(self):
# this function adds what is in each setting to the json file
global spath
#check to see if the spath file is empty
if os.stat(spath).st_size != 0:
# if it is not empty open it for reading
with open(spath,'r') as settings_file:
settings = json.load(settings_file)
#create a variable to store the current input in the image type comobo box
imgType = imageTypes[str(self.imageTypeCB.currentText())]
#print imgType
#create a dictionary to store the set of settings for one disk (if needed)
diskSetting = {}
diskSetting.update({"Image type":imgType})
#Check to see if the side mode combo box is set to default
if not self.sideModeDefault.isChecked():
# if the side mode combo box is not set to default add the contents of it to the diskSetting dictionary
diskSetting.update({"Side mode":sideModes[str(self.sideModeCB.currentText())]})
if self.flippyMode.isChecked():
diskSetting.update({"Flippy mode":"-y"})
if not self.sectorSizeDefault.isChecked():
# if the sector size combo box is not set to default add the contents of it to the diskSetting dictionary
diskSetting.update({"Sector size":sectorSizes[str(self.sectorSizeCB.currentText())]})
if not self.sectorCountDefault.isChecked():
# if the sector count combo box is not set to default add the contents of it to the diskSetting dictionary
diskSetting.update({"Sector count":sectorCounts[str(self.sectorCountCB.currentText())] + str(self.sectorCount.text())})
if not self.trackDistanceDefault.isChecked():
# if the track distance combo box is not set to default add the contents of it to the diskSetting dictionary
diskSetting.update({"Track Distance":trackDistances[str(self.trackDistanceCB.currentText())]})
if not self.tracksDefault.isChecked():
starttr = "-os" + str(self.startTrack.text())
endtr = "-oe" + str(self.endTrack.text())
diskSetting.update({"Start track":str(starttr)})
diskSetting.update({"End track":str(endtr)})
if not self.targetRPMDefault.isChecked():
# if the target RPM combo box is not set to default add the contents of it to the diskSetting dictionary
diskSetting.update({"Target RPM":targetRPMsBasic[str(self.targetRPMCB.currentText())]})
# append the contents of disk settings to the format json element
if "outputFormats" in settings:
settings["outputFormats"].append(diskSetting)
else:
settings["outputFormats"] = [diskSetting]
#Clear the json file and write back the updated json
jsoutput = json.dumps(settings)
outfile = open(spath, 'w')
outfile.write(jsoutput)
outfile.close()
self.settingsDisplay.clear()
#clear the settings text browser in the GUI
#open the spath file and print the contents to the text browser in the gui, one per format instance
self.updateTextBrowserFromJSON()
else:
#if the spath file is empty you should put something into it
#this is a hangover from earlier versions where I needed to id/process the imagetype ina a unique way
imgType = imageTypes[str(self.imageTypeCB.currentText())]
#print imgType
#create a dictionary to store the set of settings for one disk (if needed)
diskSetting = {}
diskSetting.update({"Image type":imgType})
#Check to see if the side mode combo box is set to default
if not self.sideModeDefault.isChecked():
# if the side mode combo box is not set to default add the contents of it to the diskSetting dictionary
diskSetting.update({"Side mode":sideModes[str(self.sideModeCB.currentText())]})
if not self.sectorSizeDefault.isChecked():
# if the sector size combo box is not set to default add the contents of it to the diskSetting dictionary
diskSetting.update({"Sector size":sectorSizes[str(self.sectorSizeCB.currentText())]})
if self.flippyMode.isChecked():
diskSetting.update({"Flippy mode":"-y"})
if not self.sectorCountDefault.isChecked():
# if the sector count combo box is not set to default add the contents of it to the diskSetting dictionary
diskSetting.update({"Sector count":sectorCounts[str(self.sectorCountCB.currentText())] + str(self.sectorCount.text())})
if not self.trackDistanceDefault.isChecked():
# if the track distance combo box is not set to default add the contents of it to the diskSetting dictionary
diskSetting.update({"Track Distance":trackDistances[str(self.trackDistanceCB.currentText())]})
if not self.tracksDefault.isChecked():
starttr = "-os" + str(self.startTrack.text())
endtr = "-oe" + str(self.endTrack.text())
diskSetting.update({"Start track":starttr})
diskSetting.update({"End track":endtr})
if not self.targetRPMDefault.isChecked():
# if the target RPM combo box is not set to default add the contents of it to the diskSetting dictionary
diskSetting.update({"Target RPM":targetRPMsBasic[str(self.targetRPMCB.currentText())]})
#now write this all back
settings = {"outputFormats":[diskSetting]}
jsoutput = json.dumps(settings)
outfile = open(spath, 'w')
outfile.write(jsoutput)
outfile.close()
self.settingsDisplay.clear()
self.updateTextBrowserFromJSON()
def updateTextBrowserFromJSON(self):
global spath
#used to update what is in the textbrowser box in the GUI from the JSON file
with open(spath) as settings_file:
num = 0
settings = json.load(settings_file)
# get all the formats already stored in the file
if "outputFormats" in settings:
for format in settings["outputFormats"]:
num = num + 1
#create a variable to add content to be put into the text browser in the gui
setting = ""
for x in format:
#For each format add the information to the setting variable, starting with Image type
if x == "Image type":
setting = x + ": " + imageFmts[str(format[x])] + setting
elif x == "Sector size":
setting = setting + ", " + x + ": " + sectorSizesRv[str(format[x])]
elif x == "Side mode":
setting = setting + ", " + x + ": " + sideModesRv[str(format[x])]
elif x == "Sector count":
setting = setting + ", " + x + ": " + sectorCountsRv[str(format[x])[0]] + str(self.sectorCount.text())
elif x == "Track distance":
setting = setting + ", " + x + ": " + trackDistancesRv[str(format[x])]
elif x == "Target RPM":
setting = setting + ", " + x + ": " + targetRPMsBasicRv[str(format[x])]
elif x == "Flippy mode":
setting = setting + ", " + x + ": " + str(format[x])
elif x == "Start track":
setting = setting + ", " + x + ": " + str(format[x])[2:]
elif x == "End track":
setting = setting + ", " + x + ": " + str(format[x])[2:]
#update the text browser with the information in each format
self.settingsDisplay.append("Image " + str(num) + ": " + setting)
# process the update
QtGui.QApplication.processEvents()
settings_file.close()
# set up functions to change the editablility of the various widgets when the checkboxes change to unchecked
def tracks_default_change(self):
if self.tracksDefault.isChecked():
self.startTrack.setEnabled(False)
self.endTrack.setEnabled(False)
else:
self.startTrack.setEnabled(True)
self.endTrack.setEnabled(True)
def side_mode_default_change(self):
if self.sideModeDefault.isChecked():
self.sideModeCB.setEnabled(False)
else:
self.sideModeCB.setEnabled(True)
def sector_count_default_change(self):
if self.sectorCountDefault.isChecked():
self.sectorCountCB.setEnabled(False)
self.sectorCount.setEnabled(False)
else:
self.sectorCountCB.setEnabled(True)
self.sectorCount.setEnabled(True)
def sector_size_default_change(self):
if self.sectorSizeDefault.isChecked():
self.sectorSizeCB.setEnabled(False)
else:
self.sectorSizeCB.setEnabled(True)
def track_distance_default_change(self):
if self.trackDistanceDefault.isChecked():
self.trackDistanceCB.setEnabled(False)
else:
self.trackDistanceCB.setEnabled(True)
def target_RPM_default_change(self):
if self.targetRPMDefault.isChecked():
self.targetRPMCB.setEnabled(False)
else:
self.targetRPMCB.setEnabled(True)
# Don't think I strictly need this one
def flippy_change(self):
if self.flippyMode.isChecked():
True
else:
False
def main():
app = QtGui.QApplication(sys.argv)
form = addTypes()
form.show()
app.exec_()
if __name__ == '__main__':
main()