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
38
39
40 uf_class = uf_info.add_class('state')
41 uf_class.title = "Class for saving or loading the program state."
42 uf_class.menu_text = "&state"
43 uf_class.gui_icon = "relax.relax"
44
45
46
47 uf = uf_info.add_uf('state.load')
48 uf.title = "Load a saved program state."
49 uf.title_short = "Saved state loading."
50 uf.add_keyarg(
51 name = "state",
52 default = "state.bz2",
53 py_type = "str_or_inst",
54 arg_type = "file sel",
55 desc_short = "file name",
56 desc = "The file name, which can be a string or a file descriptor object, of a saved program state.",
57 wiz_filesel_wildcard = "relax state files (*.bz2)|*.bz2|relax state files (*.gz)|*.gz|relax state files (*.*)|*.*",
58 wiz_filesel_style = FD_OPEN,
59 wiz_filesel_preview = False
60 )
61 uf.add_keyarg(
62 name = "dir",
63 py_type = "str",
64 arg_type = "dir",
65 desc_short = "directory name",
66 desc = "The name of the directory in which the file is found.",
67 can_be_none = True
68 )
69 uf.add_keyarg(
70 name = "force",
71 default = False,
72 py_type = "bool",
73 desc_short = "force flag",
74 desc = "A boolean flag which if True will cause the current program state to be overwritten."
75 )
76
77 uf.desc.append(Desc_container())
78 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.")
79 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.")
80
81 uf.desc.append(Desc_container("Prompt examples"))
82 uf.desc[-1].add_paragraph("The following commands will load the state saved in the file 'save'.")
83 uf.desc[-1].add_prompt("relax> state.load('save')")
84 uf.desc[-1].add_prompt("relax> state.load(state='save')")
85 uf.desc[-1].add_paragraph("Use one of the following commands to load the state saved in the bzip2 compressed file 'save.bz2':")
86 uf.desc[-1].add_prompt("relax> state.load('save')")
87 uf.desc[-1].add_prompt("relax> state.load(state='save')")
88 uf.desc[-1].add_prompt("relax> state.load('save.bz2')")
89 uf.desc[-1].add_prompt("relax> state.load(state='save.bz2', force=True)")
90 uf.backend = load_state
91 uf.menu_text = "&load"
92 uf.gui_icon = "oxygen.actions.document-open"
93 uf.wizard_size = (800, 600)
94 uf.gui_sync = True
95
96
97
98 uf = uf_info.add_uf('state.save')
99 uf.title = "Save the program state."
100 uf.title_short = "Saving state."
101 uf.add_keyarg(
102 name = "state",
103 default = "state.bz2",
104 py_type = "str_or_inst",
105 arg_type = "file sel",
106 desc_short = "file name",
107 desc = "The file name, which can be a string or a file descriptor object, to save the current program state in.",
108 wiz_filesel_wildcard = "relax state files (*.bz2)|*.bz2|relax state files (*.gz)|*.gz|relax state files (*.*)|*.*",
109 wiz_filesel_style = FD_SAVE
110 )
111 uf.add_keyarg(
112 name = "dir",
113 py_type = "str",
114 arg_type = "dir",
115 desc_short = "directory name",
116 desc = "The name of the directory in which to place the file.",
117 can_be_none = True
118 )
119 uf.add_keyarg(
120 name = "compress_type",
121 default = 1,
122 py_type = "int",
123 desc_short = "compression type",
124 desc = "The type of compression to use when creating the file.",
125 wiz_element_type = "combo",
126 wiz_combo_choices = ["No compression", "bzip2 compression", "gzip compression"],
127 wiz_combo_data = [0, 1, 2]
128 )
129 uf.add_keyarg(
130 name = "force",
131 default = False,
132 py_type = "bool",
133 desc_short = "force flag",
134 desc = "A boolean flag which if set to True will cause the file to be overwritten."
135 )
136
137 uf.desc.append(Desc_container())
138 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.")
139 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")
140 uf.desc[-1].add_item_list_element("0", "No compression (no file extension).")
141 uf.desc[-1].add_item_list_element("1", "bzip2 compression ('.bz2' file extension).")
142 uf.desc[-1].add_item_list_element("2", "gzip compression ('.gz' file extension).")
143
144 uf.desc.append(Desc_container("Prompt examples"))
145 uf.desc[-1].add_paragraph("The following commands will save the current program state, uncompressed, into the file 'save':")
146 uf.desc[-1].add_prompt("relax> state.save('save', compress_type=0)")
147 uf.desc[-1].add_prompt("relax> state.save(state='save', compress_type=0)")
148 uf.desc[-1].add_paragraph("The following commands will save the current program state into the bzip2 compressed file 'save.bz2':")
149 uf.desc[-1].add_prompt("relax> state.save('save')")
150 uf.desc[-1].add_prompt("relax> state.save(state='save')")
151 uf.desc[-1].add_prompt("relax> state.save('save.bz2')")
152 uf.desc[-1].add_prompt("relax> state.save(state='save.bz2')")
153 uf.desc[-1].add_paragraph("If the file 'save' already exists, the following commands will save the current program state by overwriting the file.")
154 uf.desc[-1].add_prompt("relax> state.save('save', force=True)")
155 uf.desc[-1].add_prompt("relax> state.save(state='save', force=True)")
156 uf.backend = save_state
157 uf.menu_text = "&save"
158 uf.gui_icon = "oxygen.actions.document-save"
159 uf.wizard_height_desc = 400
160 uf.wizard_size = (900, 700)
161