-
Notifications
You must be signed in to change notification settings - Fork 10
/
qdc_gui.py
executable file
·1140 lines (941 loc) · 33.5 KB
/
qdc_gui.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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
from common import (
as_variable,
CoSignal,
CoTask,
execfile,
mlget as _,
open_dir,
OrderedSet,
pythonize,
qdtdirs,
UserSettings,
Variable,
)
from examples import (
Q35MachineNode_2_6_0,
Q35Project_2_6_0,
)
import qdt
from qemu import (
account_build_path,
BadBuildPath,
load_build_path_list,
MachineNode,
QemuVersionDescription,
QProject,
qvd_get,
)
from qemu_device_creator import (
arg_type_directory,
)
from widgets import (
AddDescriptionDialog,
askdirectory,
askopen,
asksaveas,
askyesno,
CoStatusView,
DescNameWatcher,
GitVerSelDialog,
GUIPOp_SetBuildPath,
GUIProject,
GUIProjectHistoryTracker,
GUITk,
HistoryWindow,
HotKeyBinding,
ProjectWidget,
QDCGUISignalHelper,
Statusbar,
VarMenu,
)
from argparse import (
ArgumentParser,
)
from os import (
remove,
)
from os.path import (
abspath,
dirname,
isfile,
)
from six.moves.cPickle import (
load as load_cPickled,
)
from six.moves.tkinter import (
BooleanVar,
DISABLED,
END,
NORMAL,
RIGHT,
StringVar,
)
from six.moves.tkinter_messagebox import (
askyesnocancel,
showerror,
showinfo,
)
from sys import (
stderr,
version as py_version,
)
from traceback import (
format_exception,
)
class ProjectGeneration(CoTask):
def __init__(self, project, source_path, signal, reload_build_path_task,
gen_chunk_graphs, translate_cpu_semantics
):
self.p = project
self.s = source_path
self.sig = signal
self.finished = False
self.reload_build_path_task = reload_build_path_task
self.gen_chunk_graphs = gen_chunk_graphs
self.translate_cpu_semantics = translate_cpu_semantics
CoTask.__init__(
self,
self.main(),
description = _("Generation")
)
def main(self):
try:
yield self.reload_build_path_task
except:
self.prev_qvd = None # for `__finalize`
raise RuntimeError("Cannot continue without a cache")
cur_qvd = qvd_get(self.p.build_path, version = self.p.target_version)
self.prev_qvd = cur_qvd.use()
yield self.p.co_gen_all(self.s,
known_targets = cur_qvd.qvc.known_targets,
with_chunk_graph = self.gen_chunk_graphs,
translate_cpu_semantics = self.translate_cpu_semantics,
include_paths = tuple(path for path, __ in cur_qvd.include_paths)
)
def __failed__(self):
self.__finalize()
def __finished__(self):
showinfo(
title = _("Generation completed").get(),
message = _("No errors were reported.").get()
)
self.__finalize()
def __finalize(self):
if self.prev_qvd is not None:
self.prev_qvd.use()
self.finished = True
self.sig.emit()
class QDCGUIWindow(GUITk, QDCGUISignalHelper):
def __init__(self, project = None):
GUITk.__init__(self, wait_msec = 1)
for signame in [
"qvc_dirtied",
"qvd_failed",
"qvc_available"
]:
s = CoSignal()
s.attach(self.signal_dispatcher)
setattr(self, "sig_" + signame, s)
self.title_suffix = _("Qemu device creator GUI")
self.title_suffix.trace_variable("w", self.__on_title_suffix_write__)
self.title_not_saved_asterisk = StringVar()
self.title_not_saved_asterisk.trace_variable("w",
self.__on_title_suffix_write__)
self.saved_operation = None
self.var_title = StringVar()
self.title(self.var_title)
# Hot keys, accelerators
hotkeys = self.hk
hotkeys.add_bindings([
HotKeyBinding(
self.invert_history_window,
key_code = 43,
description = _("If editing history window is hidden then \
show it else hide it."),
symbol = "H"
),
HotKeyBinding(
self.on_load,
key_code = 32,
description = _("Load project from file."),
symbol = "O"
),
HotKeyBinding(
self.on_new_project,
key_code = 57,
description = _("Create new project."),
symbol = "N"
),
HotKeyBinding(
self.on_add_description,
key_code = 40,
description = _("Add description to the project"),
symbol = "D"
),
HotKeyBinding(
self.on_set_qemu_build_path,
key_code = 56,
description = _("Set Qemu build path for the project"),
symbol = "B"
),
HotKeyBinding(
self.on_sel_tgt_qemu_version,
key_code = 28,
description = _("Select target Qemu version for the project"),
symbol = "T"
),
HotKeyBinding(
self.on_generate,
key_code = 42,
description = _("Launch code generation"),
symbol = "G"
),
HotKeyBinding(
self.on_delete,
key_code = 24,
description = _("Shutdown the application."),
symbol = "Q"
),
HotKeyBinding(
self.undo,
key_code = 52,
description = _("Revert previous editing."),
symbol = "Z"
),
HotKeyBinding(
self.redo,
key_code = 29,
description = _("Make reverted editing again."),
symbol = "Y"
),
HotKeyBinding(
self.on_save,
key_code = 39,
description = _("Save project."),
symbol = "S"
),
HotKeyBinding(
self.on_reload,
key_code = 27,
description = _("Reload current project from file."),
symbol = "R"
)
])
# see `set_user_settings`
self._user_settings = None
# Menu bar
menubar = VarMenu(self)
self.filemenu = filemenu = VarMenu(menubar, tearoff = False)
filemenu.add_command(
label = _("Add description"),
command = self.on_add_description,
accelerator = hotkeys.get_keycode_string(self.on_add_description)
)
filemenu.add_command(
label = _("Set Qemu build path"),
command = self.on_set_qemu_build_path,
accelerator = hotkeys.get_keycode_string(
self.on_set_qemu_build_path
)
)
filemenu.add_command(
label = _("Select target Qemu version"),
command = self.on_sel_tgt_qemu_version,
accelerator = hotkeys.get_keycode_string(
self.on_sel_tgt_qemu_version
)
)
filemenu.add_command(
label = _("Generate"),
command = self.on_generate,
accelerator = hotkeys.get_keycode_string(
self.on_generate
)
)
filemenu.add_separator()
filemenu.add_command(
label = _("New project"),
command = self.on_new_project,
accelerator = hotkeys.get_keycode_string(self.on_new_project)
)
filemenu.add_command(
label = _("Save"),
command = self.on_save,
accelerator = hotkeys.get_keycode_string(self.on_save)
)
filemenu.add_command(
label = _("Save project as..."),
command = self.on_save_as
)
filemenu.add_command(
label = _("Load"),
command = self.on_load,
accelerator = hotkeys.get_keycode_string(self.on_load)
)
self.reload_idx = filemenu.count
filemenu.add_command(
label = _("Reload"),
command = self.on_reload,
accelerator = hotkeys.get_keycode_string(self.on_reload)
)
self.open_proj_dir_idx = filemenu.count
filemenu.add_command(
label = _("Open project directory"),
command = self.on_open_project_directory
)
self.recentmenu = recentmenu = VarMenu(filemenu, tearoff = False)
filemenu.add_cascade(
label = _("Recent projects"),
menu = recentmenu,
state = DISABLED # a user settings instance is required
)
filemenu.add_separator()
filemenu.add_command(
label = _("Quit"),
command = self.on_quit,
accelerator = hotkeys.get_keycode_string(self.on_delete)
)
menubar.add_cascade(label = _("File"), menu = filemenu)
self.editmenu = editmenu = VarMenu(menubar, tearoff = False)
editmenu.add_command(
label = _("Undo"),
command = self.undo,
accelerator = hotkeys.get_keycode_string(self.undo)
)
self.undo_idx = editmenu.count - 1
editmenu.add_command(
label = _("Redo"),
command = self.redo,
accelerator = hotkeys.get_keycode_string(self.redo)
)
self.redo_idx = editmenu.count - 1
editmenu.add_separator()
v = self.var_history_window = BooleanVar()
v.set(False)
self.__on_var_history_window = v.trace_variable("w",
self.__on_var_history_window__
)
editmenu.add_checkbutton(
label = _("Editing history window"),
variable = v,
accelerator = hotkeys.get_keycode_string(self.invert_history_window)
)
menubar.add_cascade(label = _("Edit"), menu = editmenu)
self.optionsmenu = optionsmenu = VarMenu(menubar, tearoff = False)
v = self.var_schedule_generation = BooleanVar()
v.set(False)
self.__on_var_schedule_generation = v.trace_variable("w",
self.__on_var_schedule_generation__
)
optionsmenu.add_checkbutton(
label = _("Schedule generation after cache loading"),
variable = v
)
v = self.var_gen_chunk_graphs = BooleanVar()
v.set(False)
self.__on_var_gen_chunk_graphs = v.trace_variable("w",
self.__on_var_gen_chunk_graphs__
)
optionsmenu.add_checkbutton(
label = _("Generate chunk graphs"),
variable = v
)
v = self.var_translate_cpu_semantics = BooleanVar()
v.set(False)
self.__on_var_translate_cpu_semantics = v.trace_variable("w",
self.__on_var_translate_cpu_semantics__
)
optionsmenu.add_checkbutton(
label = _("Translate CPU semantics"),
variable = v
)
v = self.var_require_device_tree = BooleanVar()
self.__on_var_require_device_tree = v.trace_variable("w",
self.__on_var_require_device_tree__
)
v.set(True)
optionsmenu.add_checkbutton(
label = _("Require device tree"),
variable = v
)
menubar.add_cascade(label = _("Options"), menu = optionsmenu)
toolsmenu = VarMenu(menubar, tearoff = False)
toolsmenu.add_command(
label = _("Rebuild Cache"),
command = self.rebuild_cache,
accelerator = hotkeys.get_keycode_string(self.rebuild_cache),
)
toolsmenu.add_command(
label = _("Open user cache directory"),
command = self.on_open_user_cache_dir,
accelerator = hotkeys.get_keycode_string(
self.on_open_user_cache_dir
),
)
menubar.add_cascade(label = _("Tools"), menu = toolsmenu)
self.config(menu = menubar)
# Widget layout
self.grid()
self.grid_columnconfigure(0, weight = 1)
self.grid_rowconfigure(0, weight = 1)
# Status bar
self.grid_rowconfigure(1, weight = 0)
self.sb = sb = Statusbar(self)
sb.grid(row = 1, column = 0, sticky = "NEWS")
# Target Qemu version in the status bar
self._target_qemu = Variable(None)
# This complicated scheme is required because the status must also
# be updated on language change.
@as_variable(self._target_qemu, _("No target"), _("Target Qemu: %s"))
def var_target_qemu(target, no_target, target_qemu):
if target is None:
return no_target
else:
return target_qemu % target
sb.left(var_target_qemu)
# QEMU build path displaying
self.var_qemu_build_path = StringVar()
sb.left(self.var_qemu_build_path)
# Task counters in status bar
sb.right(_("Background tasks: "))
sb.repack(CoStatusView(sb), RIGHT)
self.signal_dispatcher.watch_failed(self.__on_listener_failed)
self.protocol("WM_DELETE_WINDOW", self.on_delete)
self.set_project(GUIProject() if project is None else project)
self.__update_title__()
self.__check_saved_asterisk__()
self.qsig_watch("qvc_available", self.__on_qvc_available)
def set_user_settings(self, val):
if self._user_settings is val:
return
self._user_settings = val
self._update_recent_projects()
self._update_options()
def _update_recent_projects(self):
settings = self._user_settings
menu = self.recentmenu
# first, clear recent menu
last = menu.index(END)
if last is not None:
menu.delete(0, last)
added = 0
if settings is not None:
for f in reversed(list(settings.recent_projects)):
# a simple check
if not isfile(f):
settings.recent_projects.discard(f)
continue
def do_load(file_name = f):
self._do_load(file_name)
menu.add_command(label = f, command = do_load)
added += 1
self.filemenu.entryconfigure(
self.filemenu.index(_("Recent projects").get()),
state = NORMAL if added else DISABLED
)
def _update_options(self):
settings = self._user_settings
if settings is None:
return
self.var_schedule_generation.set(settings.schedule_generation)
self.var_gen_chunk_graphs.set(settings.gen_chunk_graphs)
self.var_translate_cpu_semantics.set(settings.translate_cpu_semantics)
self.var_require_device_tree.set(settings.require_device_tree)
def __on_listener_failed(self, e, tb):
stderr.write("Listener failed - %s" %
"".join(format_exception(type(e), e, tb))
)
def __on_history_window_destroy__(self, *args, **kw):
self.var_history_window.trace_vdelete("w",
self.__on_var_history_window
)
self.var_history_window.set(False)
self.__on_var_history_window = self.var_history_window.trace_variable(
"w", self.__on_var_history_window__
)
def __on_var_history_window__(self, *args):
if self.var_history_window.get():
self._history_window = HistoryWindow(self.pht, self)
self._history_window.bind("<Destroy>",
self.__on_history_window_destroy__, "+"
)
else:
try:
self._history_window.destroy()
except AttributeError:
pass
else:
del self._history_window
def invert_history_window(self):
self.var_history_window.set(not self.var_history_window.get())
def __on_var_schedule_generation__(self, *args):
settings = self._user_settings
if settings is not None:
settings.schedule_generation = self.var_schedule_generation.get()
def __on_var_gen_chunk_graphs__(self, *args):
settings = self._user_settings
if settings is not None:
settings.gen_chunk_graphs = self.var_gen_chunk_graphs.get()
def __on_var_translate_cpu_semantics__(self, *args):
settings = self._user_settings
if settings is not None:
settings.translate_cpu_semantics = (
self.var_translate_cpu_semantics.get()
)
def __on_var_require_device_tree__(self, *args):
settings = self._user_settings
require_device_tree = self.var_require_device_tree.get()
if settings is not None:
settings.require_device_tree = require_device_tree
QemuVersionDescription.REQUIRE_DEVICE_TREE = require_device_tree
# `if require_device_tree`, this triggers QVD reloading to build
# device tree.
# `if not require_device_tree`, this restarts current QVD loading to
# interrupt device tree building as soon as possible.
# In both cases QVC building, version parameters evaluation or
# any other useful long running job progress can be discarded because
# of the restarting.
# It's up to user now to choose a moment to toggle the flag.
# TODO: do it conditionally
self.sig_qvc_dirtied.emit()
def __on_title_suffix_write__(self, *args, **kw):
self.__update_title__()
def __update_title__(self):
try:
title_prefix = str(self.current_file_name)
except AttributeError:
title_prefix = "[New project]"
self.var_title.set(
title_prefix
+ self.title_not_saved_asterisk.get()
+ " - "
+ self.title_suffix.get()
)
def check_undo_redo(self):
can_do = self.pht.can_do()
self.hk.set_enabled(self.redo, can_do)
if can_do:
self.editmenu.entryconfig(self.redo_idx, state = NORMAL)
else:
self.editmenu.entryconfig(self.redo_idx, state = DISABLED)
can_undo = self.pht.can_undo()
self.hk.set_enabled(self.undo, can_undo)
if can_undo:
self.editmenu.entryconfig(self.undo_idx, state = NORMAL)
else:
self.editmenu.entryconfig(self.undo_idx, state = DISABLED)
def set_current_file_name(self, file_name = None):
if file_name is None:
try:
del self.current_file_name
except AttributeError:
pass # already deleted
else:
self.filemenu.entryconfig(self.reload_idx, state = DISABLED)
self.filemenu.entryconfig(self.open_proj_dir_idx, state = DISABLED)
else:
# TODO: watch the file in FS and auto ask user to reload
self.current_file_name = file_name
self.filemenu.entryconfig(self.reload_idx, state = NORMAL)
self.filemenu.entryconfig(self.open_proj_dir_idx, state = NORMAL)
self.__update_title__()
def set_project(self, project):
try:
pht = self.pht
except AttributeError:
# Project was never been set
pass
else:
pht.unwatch_changed(self.on_changed)
try:
self.pw.destroy()
except AttributeError:
# project widget was never been created
pass
# Close history window
if self.var_history_window.get():
self.var_history_window.set(False)
self.proj = project
self.pht = GUIProjectHistoryTracker(self.proj, self.proj.history)
DescNameWatcher(self.pht)
self.pw = ProjectWidget(self,
project = self.proj,
)
self.pw.grid(column = 0, row = 0, sticky = "NEWS")
self.update_qemu_build_path(project.build_path)
self.update_target_qemu()
self.pht.watch_changed(self.on_changed)
self.check_undo_redo()
def __saved_asterisk__(self, saved = True):
if saved:
if self.title_not_saved_asterisk.get() != "":
self.title_not_saved_asterisk.set("")
else:
if self.title_not_saved_asterisk.get() != "*":
self.title_not_saved_asterisk.set("*")
def __check_saved_asterisk__(self):
if self.saved_operation == self.pht.pos:
self.__saved_asterisk__(True)
else:
self.__saved_asterisk__(False)
def on_changed(self, op, *args, **kw):
self.check_undo_redo()
self.__check_saved_asterisk__()
if isinstance(op, GUIPOp_SetBuildPath):
proj = self.proj
if op.p is proj:
self.update_qemu_build_path(proj.build_path)
# Note that target Qemu version info will be update when QVC
# will be ready.
def on_quit(self):
self.save_project_to_file("project.py")
self.quit()
# This is necessary on Windows Py2 to prevent error:
# "Fatal Python error: PyEval_RestoreThread: NULL tstate".
self.destroy()
def undo(self):
self.pht.undo_sequence()
def redo(self):
self.pht.do_sequence()
def rebuild_cache(self):
try:
qvd = qvd_get(self.proj.build_path,
version = self.proj.target_version
)
except BadBuildPath as e:
showerror(
title = _("Cache rebuilding is impossible").get(),
message = (_("Selected Qemu build path is bad. Reason: %s") % (
e.message
)).get()
)
return
# if 'reload_build_path_task' is not failed
if hasattr(self.pw, 'reload_build_path_task'):
# reload_build_path_task always run at program start that is why
# it's in process when it's not in finished_tasks and not failed
if self.pw.reload_build_path_task not in self.pw.tm.finished_tasks:
ans = askyesno(self,
title = _("Cache rebuilding"),
message = _("Cache building is already \
in process. Do you want to start cache rebuilding?")
)
if not ans:
return
qvd.remove_cache()
self.pw.reload_build_path()
def on_delete(self):
if self.title_not_saved_asterisk.get() == "*":
resp = askyesnocancel(
title = self.title_suffix.get(),
message = _(
"Current project has unsaved changes."
" Would you like to save it?"
"\n\nNote that a backup is always saved with name"
" project.py in current working directory."
).get()
)
if resp is None:
return
if resp:
self.on_save()
if self.title_not_saved_asterisk.get() == "*":
# user canceled saving during on_save
return
try:
""" TODO: Note that it is possible to prevent window to close if a
generation task is in process. But is it really needed? """
self.task_manager.remove(self._project_generation_task)
except AttributeError:
pass
else:
del self._project_generation_task
self.signal_dispatcher.unwatch_failed(self.__on_listener_failed)
self.on_quit()
def on_add_description(self):
AddDescriptionDialog(self.pht, self)
def on_set_qemu_build_path(self):
_dir = askdirectory(self, title = _("Select Qemu build path"))
if not _dir:
return
self.pht.set_build_path(_dir)
def on_sel_tgt_qemu_version(self):
try:
qvd = qvd_get(self.proj.build_path)
except:
repo = None
else:
repo = qvd.repo
new_target = GitVerSelDialog(self, repo).wait()
if new_target is None:
return
self.pht.set_target(new_target)
def on_generate(self):
try:
t = self._project_generation_task
except AttributeError:
pass
else:
if not t.finished:
showerror(
title = _("Generation is cancelled").get(),
message = _("At least one generation task is already \
in process.").get()
)
return
if not self.proj.build_path:
showerror(
title = _("Generation is impossible").get(),
message = _("No Qemu build path is set for the project.").get()
)
return
try:
qvd = qvd_get(self.proj.build_path,
version = self.proj.target_version
)
except BadBuildPath as e:
showerror(
title = _("Generation is impossible").get(),
message = (_("Selected Qemu build path is bad. Reason: %s") % (
e.message
)).get()
)
return
if not hasattr(self.pw, "reload_build_path_task"):
showerror(
title = _("Generation is impossible").get(),
message = _("Qemu version cache loading failed.").get()
)
return
if not qvd.qvc_is_ready and not self.var_schedule_generation.get():
showerror(
title = _("Generation is cancelled").get(),
message = _("Qemu version cache is not ready yet. Try \
later.").get()
)
return
self._project_generation_task = ProjectGeneration(
self.proj,
qvd.src_path,
self.sig_qvc_dirtied,
self.pw.reload_build_path_task,
self.var_gen_chunk_graphs.get(),
self.var_translate_cpu_semantics.get()
)
self.task_manager.enqueue(self._project_generation_task)
def load_project_from_file(self, file_name):
loaded_variables = dict(qdt.__dict__)
try:
execfile(file_name, loaded_variables)
except Exception as e:
raise e
else:
qproj = None
for v in loaded_variables.values():
if isinstance(v, GUIProject):
break
elif qproj is None and isinstance(v, QProject):
qproj = v
else:
if qproj:
v = GUIProject.from_qproject(qproj)
else:
raise Exception("No project object was loaded")
v.replace_relpaths_to_abspaths(abspath(dirname(file_name)))
self.set_project(v)
self.set_current_file_name(file_name)
self.saved_operation = self.pht.pos
self.__check_saved_asterisk__()
if self._user_settings:
self._user_settings.account_project(file_name)
self._update_recent_projects()
def save_project_to_file(self, file_name):
self.pw.refresh_layouts()
project = self.proj
# Ensure that all machine nodes are in corresponding lists
for d in project.descriptions:
if isinstance(d, MachineNode):
d.link(handle_system_bus = False)
file_path = abspath(dirname(file_name))
project.replace_abspaths_to_relpaths(file_path)
pythonize(project, file_name)
project.replace_relpaths_to_abspaths(file_path)
self.set_current_file_name(file_name)
self.saved_operation = self.pht.pos
self.__check_saved_asterisk__()
def try_save_project_to_file(self, file_name):
try:
open(file_name, "wb").close()
except IOError as e:
if not e.errno == 13: # Do not remove read-only files
try:
remove(file_name)
except:
pass
showerror(
title = _("Cannot save project").get(),
message = str(e)
)
return
self.save_project_to_file(file_name)
if self._user_settings:
self._user_settings.account_project(file_name)
self._update_recent_projects()
def on_save_as(self):
fname = asksaveas(self,
[(_("QDC GUI Project defining script"), ".py")],
title = _("Save project")
)
if not fname:
return
self.try_save_project_to_file(fname)
def on_save(self):
try:
fname = self.current_file_name
except AttributeError:
self.on_save_as()
else:
self.try_save_project_to_file(fname)
def check_unsaved(self):
if self.title_not_saved_asterisk.get() == "*":
return askyesno(self,
title = self.title_suffix,
message =
_("Current project has unsaved changes. They will be lost. Continue?")
)
else:
return True
def on_new_project(self):
if not self.check_unsaved():
return
self.set_project(GUIProject())
self.set_current_file_name()
""" There is nothing to save in just created project. So declare that
all changes are saved. """
self.saved_operation = self.pht.pos
self.__check_saved_asterisk__()
def on_load(self):
if not self.check_unsaved():
return
fname = askopen(self, [(_("QDC GUI Project defining script"), ".py")],
title = _("Load project")
)
if fname:
self._do_load(fname)
def _do_load(self, fname):
try:
self.load_project_from_file(fname)
except Exception as e:
showerror(
title = _("Project loading failed").get(),
message = str(e)
)
def on_reload(self):