1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """The state user function definitions."""
24
25
26 import dep_check
27 if dep_check.wx_module:
28 from wx import FD_OPEN, FD_SAVE
29 else:
30 FD_OPEN = -1
31 FD_SAVE = -1
32
33
34 from pipe_control.state import load_state, save_state
35 from user_functions.data import Uf_info; uf_info = Uf_info()
36 from user_functions.objects import Desc_container
37 from user_functions.wildcards import WILDCARD_RELAX_SAVE
38
39
40
41 uf_class = uf_info.add_class('state')
42 uf_class.title = "Class for saving or loading the program state."
43 uf_class.menu_text = "&state"
44 uf_class.gui_icon = "relax.relax"
45
46
47
48 uf = uf_info.add_uf('state.load')
49 uf.title = "Load a saved program state."
50 uf.title_short = "Saved state loading."
51 uf.add_keyarg(
52 name = "state",
53 default = "state.bz2",
54 py_type = "str_or_inst",
55 arg_type = "file sel",
56 desc_short = "file name",
57 desc = "The file name, which can be a string or a file descriptor object, of a saved program state.",
58 wiz_filesel_wildcard = WILDCARD_RELAX_SAVE,
59 wiz_filesel_style = FD_OPEN,
60 wiz_filesel_preview = False
61 )
62 uf.add_keyarg(
63 name = "dir",
64 py_type = "str",
65 arg_type = "dir",
66 desc_short = "directory name",
67 desc = "The name of the directory in which the file is found.",
68 can_be_none = True
69 )
70 uf.add_keyarg(
71 name = "force",
72 default = False,
73 py_type = "bool",
74 desc_short = "force flag",
75 desc = "A boolean flag which if True will cause the current program state to be overwritten."
76 )
77
78 uf.desc.append(Desc_container())
79 uf.desc[-1].add_paragraph("This is able to handle uncompressed, bzip2 compressed files, or gzip compressed files automatically. The full file name including extension can be supplied, however, if the file cannot be found, this function will search for the file name with '.bz2' appended followed by the file name with '.gz' appended.")
80 uf.desc[-1].add_paragraph("For more advanced users, file descriptor objects are supported. If the force flag is set to True, then the relax data store will be reset prior to the loading of the saved state.")
81
82 uf.desc.append(Desc_container("Prompt examples"))
83 uf.desc[-1].add_paragraph("The following commands will load the state saved in the file 'save'.")
84 uf.desc[-1].add_prompt("relax> state.load('save')")
85 uf.desc[-1].add_prompt("relax> state.load(state='save')")
86 uf.desc[-1].add_paragraph("Use one of the following commands to load the state saved in the bzip2 compressed file 'save.bz2':")
87 uf.desc[-1].add_prompt("relax> state.load('save')")
88 uf.desc[-1].add_prompt("relax> state.load(state='save')")
89 uf.desc[-1].add_prompt("relax> state.load('save.bz2')")
90 uf.desc[-1].add_prompt("relax> state.load(state='save.bz2', force=True)")
91 uf.backend = load_state
92 uf.menu_text = "&load"
93 uf.gui_icon = "oxygen.actions.document-open"
94 uf.wizard_size = (800, 600)
95 uf.gui_sync = True
96
97
98
99 uf = uf_info.add_uf('state.save')
100 uf.title = "Save the program state."
101 uf.title_short = "Saving state."
102 uf.add_keyarg(
103 name = "state",
104 default = "state.bz2",
105 py_type = "str_or_inst",
106 arg_type = "file sel",
107 desc_short = "file name",
108 desc = "The file name, which can be a string or a file descriptor object, to save the current program state in.",
109 wiz_filesel_wildcard = WILDCARD_RELAX_SAVE,
110 wiz_filesel_style = FD_SAVE
111 )
112 uf.add_keyarg(
113 name = "dir",
114 py_type = "str",
115 arg_type = "dir",
116 desc_short = "directory name",
117 desc = "The name of the directory in which to place the file.",
118 can_be_none = True
119 )
120 uf.add_keyarg(
121 name = "compress_type",
122 default = 1,
123 py_type = "int",
124 desc_short = "compression type",
125 desc = "The type of compression to use when creating the file.",
126 wiz_element_type = "combo",
127 wiz_combo_choices = ["No compression", "bzip2 compression", "gzip compression"],
128 wiz_combo_data = [0, 1, 2]
129 )
130 uf.add_keyarg(
131 name = "force",
132 default = False,
133 py_type = "bool",
134 desc_short = "force flag",
135 desc = "A boolean flag which if set to True will cause the file to be overwritten."
136 )
137
138 uf.desc.append(Desc_container())
139 uf.desc[-1].add_paragraph("This will place the program state - the relax data store - into a file for later reloading or reference. The default format is an XML formatted file.")
140 uf.desc[-1].add_paragraph("The default behaviour of this function is to compress the file using bzip2 compression. If the extension '.bz2' is not included in the file name, it will be added. The compression can, however, be changed to either no compression or gzip compression. This is controlled by the compression type which can be set to")
141 uf.desc[-1].add_item_list_element("0", "No compression (no file extension).")
142 uf.desc[-1].add_item_list_element("1", "bzip2 compression ('.bz2' file extension).")
143 uf.desc[-1].add_item_list_element("2", "gzip compression ('.gz' file extension).")
144
145 uf.desc.append(Desc_container("Prompt examples"))
146 uf.desc[-1].add_paragraph("The following commands will save the current program state, uncompressed, into the file 'save':")
147 uf.desc[-1].add_prompt("relax> state.save('save', compress_type=0)")
148 uf.desc[-1].add_prompt("relax> state.save(state='save', compress_type=0)")
149 uf.desc[-1].add_paragraph("The following commands will save the current program state into the bzip2 compressed file 'save.bz2':")
150 uf.desc[-1].add_prompt("relax> state.save('save')")
151 uf.desc[-1].add_prompt("relax> state.save(state='save')")
152 uf.desc[-1].add_prompt("relax> state.save('save.bz2')")
153 uf.desc[-1].add_prompt("relax> state.save(state='save.bz2')")
154 uf.desc[-1].add_paragraph("If the file 'save' already exists, the following commands will save the current program state by overwriting the file.")
155 uf.desc[-1].add_prompt("relax> state.save('save', force=True)")
156 uf.desc[-1].add_prompt("relax> state.save(state='save', force=True)")
157 uf.backend = save_state
158 uf.menu_text = "&save"
159 uf.gui_icon = "oxygen.actions.document-save"
160 uf.wizard_height_desc = 400
161 uf.wizard_size = (900, 700)
162