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