[a3efdeb] | 1 | """ |
---|
| 2 | Invariant panel |
---|
| 3 | """ |
---|
[9ce7641c] | 4 | import wx |
---|
| 5 | import sys |
---|
[f6518f8] | 6 | |
---|
[4a2b054] | 7 | from sans.guiframe.utils import format_number |
---|
[518d35d] | 8 | from invariant_widgets import OutputTextCtrl |
---|
[9ce7641c] | 9 | # Dimensions related to chart |
---|
| 10 | RECTANGLE_WIDTH = 400.0 |
---|
| 11 | RECTANGLE_HEIGHT = 20 |
---|
| 12 | #Invariant panel size |
---|
| 13 | _BOX_WIDTH = 76 |
---|
[d0cc0bbc] | 14 | |
---|
| 15 | #scale to use for a bar of value zero |
---|
| 16 | RECTANGLE_SCALE = 0.0001 |
---|
| 17 | DEFAULT_QSTAR = 1.0 |
---|
[9ce7641c] | 18 | |
---|
[4a2b054] | 19 | if sys.platform.count("win32") > 0: |
---|
[9ce7641c] | 20 | _STATICBOX_WIDTH = 450 |
---|
| 21 | PANEL_WIDTH = 500 |
---|
[d0cc0bbc] | 22 | PANEL_HEIGHT = 430 |
---|
[9ce7641c] | 23 | FONT_VARIANT = 0 |
---|
| 24 | else: |
---|
| 25 | _STATICBOX_WIDTH = 480 |
---|
| 26 | PANEL_WIDTH = 530 |
---|
[d0cc0bbc] | 27 | PANEL_HEIGHT = 430 |
---|
[9ce7641c] | 28 | FONT_VARIANT = 1 |
---|
| 29 | |
---|
[9cec2dd] | 30 | ERROR_COLOR = wx.Colour(255, 0, 0, 128) |
---|
| 31 | EXTRAPOLATION_COLOR = wx.Colour(169, 169, 168, 128) |
---|
| 32 | INVARIANT_COLOR = wx.Colour(67, 208, 128, 128) |
---|
| 33 | |
---|
[d0cc0bbc] | 34 | |
---|
| 35 | class InvariantContainer(wx.Object): |
---|
[45802d4] | 36 | """ |
---|
[d7a39e5] | 37 | This class stores some values resulting resulting from invariant |
---|
| 38 | calculations. Given the value of total invariant, this class can also |
---|
| 39 | determine the percentage of invariants resulting from extrapolation. |
---|
[45802d4] | 40 | """ |
---|
[d0cc0bbc] | 41 | def __init__(self): |
---|
| 42 | #invariant at low range |
---|
[eed601e] | 43 | self.qstar_low = None |
---|
[d0cc0bbc] | 44 | #invariant at low range error |
---|
[eed601e] | 45 | self.qstar_low_err = None |
---|
[d0cc0bbc] | 46 | #invariant |
---|
[eed601e] | 47 | self.qstar = None |
---|
[d0cc0bbc] | 48 | #invariant error |
---|
[eed601e] | 49 | self.qstar_err = None |
---|
[d0cc0bbc] | 50 | #invariant at high range |
---|
[eed601e] | 51 | self.qstar_high = None |
---|
[d0cc0bbc] | 52 | #invariant at high range error |
---|
[eed601e] | 53 | self.qstar_high_err = None |
---|
[d0cc0bbc] | 54 | #invariant total |
---|
| 55 | self.qstar_total = None |
---|
| 56 | #invariant error |
---|
| 57 | self.qstar_total_err = None |
---|
| 58 | #scale |
---|
[eed601e] | 59 | self.qstar_low_percent = None |
---|
| 60 | self.qstar_high_percent = None |
---|
| 61 | self.qstar_percent = None |
---|
[d0cc0bbc] | 62 | # warning message |
---|
| 63 | self.existing_warning = False |
---|
| 64 | self.warning_msg = "No Details on calculations available...\n" |
---|
| 65 | |
---|
| 66 | def compute_percentage(self): |
---|
| 67 | """ |
---|
[d7a39e5] | 68 | Compute percentage of each invariant |
---|
[d0cc0bbc] | 69 | """ |
---|
[eed601e] | 70 | if self.qstar_total is None: |
---|
| 71 | self.qstar_percent = None |
---|
| 72 | self.qstar_low = None |
---|
| 73 | self.qstar_high = None |
---|
| 74 | self.check_values() |
---|
| 75 | return |
---|
| 76 | |
---|
| 77 | #compute invariant percentage |
---|
| 78 | if self.qstar is None: |
---|
| 79 | self.qstar_percent = None |
---|
| 80 | else: |
---|
| 81 | try: |
---|
| 82 | self.qstar_percent = float(self.qstar)/float(self.qstar_total) |
---|
| 83 | except: |
---|
| 84 | self.qstar_percent = 'error' |
---|
| 85 | #compute low q invariant percentage |
---|
| 86 | if self.qstar_low is None: |
---|
| 87 | self.qstar_low_percent = None |
---|
| 88 | else: |
---|
| 89 | try: |
---|
[4a2b054] | 90 | self.qstar_low_percent = float(self.qstar_low)\ |
---|
| 91 | /float(self.qstar_total) |
---|
[eed601e] | 92 | except: |
---|
| 93 | self.qstar_low_percent = 'error' |
---|
| 94 | #compute high q invariant percentage |
---|
| 95 | if self.qstar_high is None: |
---|
| 96 | self.qstar_high_percent = None |
---|
| 97 | else: |
---|
| 98 | try: |
---|
[4a2b054] | 99 | self.qstar_high_percent = float(self.qstar_high)\ |
---|
| 100 | /float(self.qstar_total) |
---|
[eed601e] | 101 | except: |
---|
| 102 | self.qstar_high_percent = 'error' |
---|
[d0cc0bbc] | 103 | self.check_values() |
---|
| 104 | |
---|
| 105 | def check_values(self): |
---|
| 106 | """ |
---|
[d7a39e5] | 107 | check the validity if invariant |
---|
[d0cc0bbc] | 108 | """ |
---|
[eed601e] | 109 | if self.qstar_total is None and self.qstar is None: |
---|
| 110 | self.warning_msg = "Invariant not calculated.\n" |
---|
| 111 | return |
---|
| 112 | if self.qstar_total == 0: |
---|
[4a2b054] | 113 | self.existing_warning = True |
---|
| 114 | self.warning_msg = "Invariant is zero. \n" |
---|
| 115 | self.warning_msg += "The calculations are likely " |
---|
| 116 | self.warning_msg += "to be unreliable!\n" |
---|
| 117 | return |
---|
[d0cc0bbc] | 118 | #warning to the user when the extrapolated invariant is greater than %5 |
---|
[3fab6ef] | 119 | msg = '' |
---|
[eed601e] | 120 | if self.qstar_percent == 'error': |
---|
| 121 | self.existing_warning = True |
---|
| 122 | msg = 'Error occurred when computing invariant from data.\n ' |
---|
[f6518f8] | 123 | if self.qstar_percent > 1: |
---|
| 124 | self.existing_warning = True |
---|
| 125 | msg += "Invariant Q contribution is greater " |
---|
| 126 | msg += "than 100% .\n" |
---|
[eed601e] | 127 | if self.qstar_low_percent == 'error': |
---|
| 128 | self.existing_warning = True |
---|
[4a2b054] | 129 | msg = "Error occurred when computing extrapolated invariant" |
---|
| 130 | msg += " at low-Q region.\n" |
---|
[f6518f8] | 131 | elif self.qstar_low_percent is not None : |
---|
| 132 | if self.qstar_low_percent >= 0.05: |
---|
| 133 | self.existing_warning = True |
---|
| 134 | msg += "Extrapolated contribution at Low Q is higher " |
---|
| 135 | msg += "than 5% of the invariant.\n" |
---|
| 136 | elif self.qstar_low_percent < 0: |
---|
| 137 | self.existing_warning = True |
---|
| 138 | msg += "Extrapolated contribution at Low Q < 0.\n" |
---|
| 139 | elif self.qstar_low_percent > 1: |
---|
| 140 | self.existing_warning = True |
---|
| 141 | msg += "Extrapolated contribution at Low Q is greater " |
---|
| 142 | msg += "than 100% .\n" |
---|
[eed601e] | 143 | if self.qstar_high_percent == 'error': |
---|
| 144 | self.existing_warning = True |
---|
[4a2b054] | 145 | msg += 'Error occurred when computing extrapolated' |
---|
| 146 | msg += ' invariant at high-Q region.\n' |
---|
[f6518f8] | 147 | elif self.qstar_high_percent is not None: |
---|
| 148 | if self.qstar_high_percent >= 0.05: |
---|
| 149 | self.existing_warning = True |
---|
| 150 | msg += "Extrapolated contribution at High Q is higher " |
---|
| 151 | msg += "than 5% of the invariant.\n" |
---|
| 152 | elif self.qstar_high_percent < 0: |
---|
| 153 | self.existing_warning = True |
---|
| 154 | msg += "Extrapolated contribution at High Q < 0.\n" |
---|
| 155 | elif self.qstar_high_percent > 1: |
---|
| 156 | self.existing_warning = True |
---|
| 157 | msg += "Extrapolated contribution at High Q is greater " |
---|
| 158 | msg += "than 100% .\n" |
---|
[eed601e] | 159 | if (self.qstar_low_percent not in [None, "error"]) and \ |
---|
| 160 | (self.qstar_high_percent not in [None, "error"])\ |
---|
| 161 | and self.qstar_low_percent + self.qstar_high_percent >= 0.05: |
---|
[d0cc0bbc] | 162 | self.existing_warning = True |
---|
[3fab6ef] | 163 | msg += "The sum of all extrapolated contributions is higher " |
---|
| 164 | msg += "than 5% of the invariant.\n" |
---|
[d0cc0bbc] | 165 | |
---|
| 166 | if self.existing_warning: |
---|
[3fab6ef] | 167 | self.warning_msg = '' |
---|
| 168 | self.warning_msg += msg |
---|
[4a2b054] | 169 | self.warning_msg += "The calculations are likely to be" |
---|
| 170 | self.warning_msg += " unreliable!\n" |
---|
[d0cc0bbc] | 171 | else: |
---|
| 172 | self.warning_msg = "No Details on calculations available...\n" |
---|
| 173 | |
---|
[d3fac18] | 174 | class InvariantDetailsPanel(wx.Dialog): |
---|
[9ce7641c] | 175 | """ |
---|
[d7a39e5] | 176 | This panel describes proportion of invariants |
---|
[9ce7641c] | 177 | """ |
---|
[45802d4] | 178 | def __init__(self, parent=None, id=-1, qstar_container=None, |
---|
| 179 | title="Invariant Details", |
---|
| 180 | size=(PANEL_WIDTH, PANEL_HEIGHT)): |
---|
[4a2b054] | 181 | wx.Dialog.__init__(self, parent=parent, id=id, title=title, size=size) |
---|
[f75ea4a] | 182 | |
---|
| 183 | #Font size |
---|
| 184 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
| 185 | self.parent = parent |
---|
| 186 | #self.qstar_container |
---|
| 187 | self.qstar_container = qstar_container |
---|
| 188 | #warning message |
---|
| 189 | self.warning_msg = self.qstar_container.warning_msg |
---|
[d0cc0bbc] | 190 | |
---|
[f75ea4a] | 191 | #Define scale of each bar |
---|
| 192 | self.low_inv_percent = self.qstar_container.qstar_low_percent |
---|
| 193 | self.low_scale = self.get_scale(percentage=self.low_inv_percent, |
---|
| 194 | scale_name="Extrapolated at Low Q") |
---|
| 195 | self.inv_percent = self.qstar_container.qstar_percent |
---|
| 196 | self.inv_scale = self.get_scale(percentage=self.inv_percent, |
---|
| 197 | scale_name="Inv in Q range") |
---|
| 198 | self.high_inv_percent = self.qstar_container.qstar_high_percent |
---|
| 199 | self.high_scale = self.get_scale(percentage=self.high_inv_percent, |
---|
| 200 | scale_name="Extrapolated at High Q") |
---|
[eed601e] | 201 | |
---|
[f75ea4a] | 202 | #Default color the extrapolation bar is grey |
---|
[9cec2dd] | 203 | self.extrapolation_color_low = EXTRAPOLATION_COLOR |
---|
| 204 | self.extrapolation_color_high = EXTRAPOLATION_COLOR |
---|
| 205 | self.invariant_color = INVARIANT_COLOR |
---|
[f75ea4a] | 206 | #change color of high and low bar when necessary |
---|
| 207 | self.set_color_bar() |
---|
| 208 | #draw the panel itself |
---|
| 209 | self._do_layout() |
---|
| 210 | self.set_values() |
---|
| 211 | |
---|
[9ce7641c] | 212 | def _define_structure(self): |
---|
| 213 | """ |
---|
[d7a39e5] | 214 | Define main sizers needed for this panel |
---|
[9ce7641c] | 215 | """ |
---|
[4a2b054] | 216 | #Box sizers must be defined first before defining buttons/textctrls |
---|
| 217 | # (MAC). |
---|
[9ce7641c] | 218 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
| 219 | #Sizer related to chart |
---|
| 220 | chart_box = wx.StaticBox(self, -1, "Invariant Chart") |
---|
| 221 | self.chart_sizer = wx.StaticBoxSizer(chart_box, wx.VERTICAL) |
---|
[4a2b054] | 222 | self.chart_sizer.SetMinSize((PANEL_WIDTH - 50, 110)) |
---|
[9ce7641c] | 223 | #Sizer related to invariant values |
---|
| 224 | self.invariant_sizer = wx.GridBagSizer(4, 4) |
---|
[d0cc0bbc] | 225 | invariant_box = wx.StaticBox(self, -1, "Numerical Values") |
---|
| 226 | self.invariant_box_sizer = wx.StaticBoxSizer(invariant_box, |
---|
| 227 | wx.HORIZONTAL) |
---|
| 228 | |
---|
[4a2b054] | 229 | self.invariant_box_sizer.SetMinSize((PANEL_WIDTH - 50, -1)) |
---|
[9ce7641c] | 230 | #Sizer related to warning message |
---|
| 231 | warning_box = wx.StaticBox(self, -1, "Warning") |
---|
| 232 | self.warning_sizer = wx.StaticBoxSizer(warning_box, wx.VERTICAL) |
---|
[4a2b054] | 233 | self.warning_sizer.SetMinSize((PANEL_WIDTH-50, -1)) |
---|
[9ce7641c] | 234 | #Sizer related to button |
---|
| 235 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 236 | |
---|
| 237 | def _layout_shart(self): |
---|
| 238 | """ |
---|
[d7a39e5] | 239 | Draw widgets related to chart |
---|
[9ce7641c] | 240 | """ |
---|
| 241 | self.panel_chart = wx.Panel(self) |
---|
| 242 | self.panel_chart.Bind(wx.EVT_PAINT, self.on_paint) |
---|
| 243 | self.chart_sizer.Add(self.panel_chart, 1, wx.EXPAND|wx.ALL, 0) |
---|
| 244 | |
---|
| 245 | def _layout_invariant(self): |
---|
| 246 | """ |
---|
[d7a39e5] | 247 | Draw widgets related to invariant |
---|
[9ce7641c] | 248 | """ |
---|
| 249 | uncertainty = "+/-" |
---|
[d0cc0bbc] | 250 | unit_invariant = '[1/(cm * A)]' |
---|
[9ce7641c] | 251 | |
---|
[eed601e] | 252 | invariant_txt = wx.StaticText(self, -1, 'Q* from Data ') |
---|
| 253 | invariant_txt.SetToolTipString("Invariant in the data set's Q range.") |
---|
[4a2b054] | 254 | self.invariant_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) |
---|
| 255 | hint_msg = "Invariant in the data set's Q range." |
---|
| 256 | self.invariant_tcl.SetToolTipString(hint_msg) |
---|
| 257 | self.invariant_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) |
---|
| 258 | hint_msg = "Uncertainty on the invariant from data's range." |
---|
| 259 | self.invariant_err_tcl.SetToolTipString(hint_msg) |
---|
[9ce7641c] | 260 | invariant_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
[4a2b054] | 261 | hint_msg = "Unit of the invariant from data's Q range" |
---|
| 262 | invariant_units_txt.SetToolTipString(hint_msg) |
---|
[9ce7641c] | 263 | |
---|
[eed601e] | 264 | invariant_low_txt = wx.StaticText(self, -1, 'Q* from Low-Q') |
---|
[4a2b054] | 265 | hint_msg = "Extrapolated invariant from low-Q range." |
---|
| 266 | invariant_low_txt.SetToolTipString(hint_msg) |
---|
| 267 | self.invariant_low_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, -1)) |
---|
| 268 | hint_msg = "Extrapolated invariant from low-Q range." |
---|
| 269 | self.invariant_low_tcl.SetToolTipString(hint_msg) |
---|
| 270 | self.invariant_low_err_tcl = OutputTextCtrl(self, -1, |
---|
| 271 | size=(_BOX_WIDTH, -1)) |
---|
| 272 | hint_msg = "Uncertainty on the invariant from low-Q range." |
---|
| 273 | self.invariant_low_err_tcl.SetToolTipString(hint_msg) |
---|
| 274 | invariant_low_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
| 275 | hint_msg = "Unit of the extrapolated invariant from low-Q range" |
---|
| 276 | invariant_low_units_txt.SetToolTipString(hint_msg) |
---|
[9ce7641c] | 277 | |
---|
[eed601e] | 278 | invariant_high_txt = wx.StaticText(self, -1, 'Q* from High-Q') |
---|
[4a2b054] | 279 | hint_msg = "Extrapolated invariant from high-Q range" |
---|
| 280 | invariant_high_txt.SetToolTipString(hint_msg) |
---|
| 281 | self.invariant_high_tcl = OutputTextCtrl(self, -1, |
---|
| 282 | size=(_BOX_WIDTH, -1)) |
---|
| 283 | hint_msg = "Extrapolated invariant from high-Q range" |
---|
| 284 | self.invariant_high_tcl.SetToolTipString(hint_msg) |
---|
| 285 | self.invariant_high_err_tcl = OutputTextCtrl(self, -1, |
---|
| 286 | size=(_BOX_WIDTH, -1)) |
---|
| 287 | hint_msg = "Uncertainty on the invariant from high-Q range." |
---|
[98eefdb] | 288 | self.invariant_high_err_tcl.SetToolTipString(hint_msg) |
---|
[4a2b054] | 289 | invariant_high_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
| 290 | hint_msg = "Unit of the extrapolated invariant from high-Q range" |
---|
| 291 | invariant_high_units_txt.SetToolTipString(hint_msg) |
---|
[9ce7641c] | 292 | |
---|
| 293 | #Invariant low |
---|
[d0cc0bbc] | 294 | iy = 0 |
---|
[9ce7641c] | 295 | ix = 0 |
---|
[4a2b054] | 296 | self.invariant_sizer.Add(invariant_low_txt, (iy, ix), (1, 1), |
---|
[9ce7641c] | 297 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 298 | ix += 1 |
---|
[4a2b054] | 299 | self.invariant_sizer.Add(self.invariant_low_tcl, (iy, ix), (1, 1), |
---|
[9ce7641c] | 300 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 301 | ix += 1 |
---|
| 302 | self.invariant_sizer.Add( wx.StaticText(self, -1, uncertainty), |
---|
[4a2b054] | 303 | (iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[9ce7641c] | 304 | ix += 1 |
---|
[4a2b054] | 305 | self.invariant_sizer.Add(self.invariant_low_err_tcl, (iy, ix), (1, 1), |
---|
[9ce7641c] | 306 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 307 | ix += 1 |
---|
| 308 | self.invariant_sizer.Add(invariant_low_units_txt |
---|
[4a2b054] | 309 | ,(iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[9ce7641c] | 310 | #Invariant |
---|
| 311 | iy += 1 |
---|
| 312 | ix = 0 |
---|
[4a2b054] | 313 | self.invariant_sizer.Add(invariant_txt, (iy, ix), (1, 1), |
---|
[9ce7641c] | 314 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 315 | ix += 1 |
---|
[4a2b054] | 316 | self.invariant_sizer.Add(self.invariant_tcl, (iy, ix), (1, 1), |
---|
[9ce7641c] | 317 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 318 | ix += 1 |
---|
| 319 | self.invariant_sizer.Add(wx.StaticText(self, -1, uncertainty), |
---|
[4a2b054] | 320 | (iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[9ce7641c] | 321 | ix += 1 |
---|
[4a2b054] | 322 | self.invariant_sizer.Add(self.invariant_err_tcl, (iy, ix), (1, 1), |
---|
[9ce7641c] | 323 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 324 | ix +=1 |
---|
| 325 | self.invariant_sizer.Add(invariant_units_txt |
---|
[4a2b054] | 326 | ,(iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[9ce7641c] | 327 | #Invariant high |
---|
| 328 | iy += 1 |
---|
| 329 | ix = 0 |
---|
[4a2b054] | 330 | self.invariant_sizer.Add(invariant_high_txt, (iy, ix), (1, 1), |
---|
[9ce7641c] | 331 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 332 | ix += 1 |
---|
[4a2b054] | 333 | self.invariant_sizer.Add(self.invariant_high_tcl, (iy, ix), (1, 1), |
---|
[9ce7641c] | 334 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 335 | ix += 1 |
---|
| 336 | self.invariant_sizer.Add(wx.StaticText(self, -1, uncertainty), |
---|
[4a2b054] | 337 | (iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[9ce7641c] | 338 | ix += 1 |
---|
[4a2b054] | 339 | self.invariant_sizer.Add(self.invariant_high_err_tcl, (iy, ix), (1, 1), |
---|
[9ce7641c] | 340 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 341 | ix += 1 |
---|
| 342 | self.invariant_sizer.Add(invariant_high_units_txt |
---|
[4a2b054] | 343 | ,(iy, ix), (1, 1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 344 | self.invariant_box_sizer.Add(self.invariant_sizer, 0, |
---|
| 345 | wx.TOP|wx.BOTTOM, 10) |
---|
[9ce7641c] | 346 | |
---|
| 347 | def _layout_warning(self): |
---|
| 348 | """ |
---|
[d7a39e5] | 349 | Draw widgets related to warning |
---|
[9ce7641c] | 350 | """ |
---|
| 351 | #Warning [string] |
---|
[3fab6ef] | 352 | self.warning_msg_txt = wx.StaticText(self, -1, self.warning_msg) |
---|
[d0cc0bbc] | 353 | if self.qstar_container.existing_warning: |
---|
| 354 | self.warning_msg_txt.SetForegroundColour('red') |
---|
[277fad8] | 355 | self.warning_sizer.AddMany([(self.warning_msg_txt, 0, |
---|
| 356 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10)]) |
---|
[9ce7641c] | 357 | |
---|
| 358 | def _layout_button(self): |
---|
| 359 | """ |
---|
[d7a39e5] | 360 | Draw widgets related to button |
---|
[9ce7641c] | 361 | """ |
---|
| 362 | #Close button |
---|
| 363 | id = wx.NewId() |
---|
| 364 | button_ok = wx.Button(self, id, "Ok") |
---|
| 365 | button_ok.SetToolTipString("Give Details on Computation") |
---|
| 366 | self.Bind(wx.EVT_BUTTON, self.on_close, id=id) |
---|
[4a2b054] | 367 | self.button_sizer.AddMany([((20, 20), 0 , wx.LEFT, 350), |
---|
[9ce7641c] | 368 | (button_ok, 0 , wx.RIGHT, 10)]) |
---|
| 369 | def _do_layout(self): |
---|
| 370 | """ |
---|
[d7a39e5] | 371 | Draw window content |
---|
[9ce7641c] | 372 | """ |
---|
| 373 | self._define_structure() |
---|
| 374 | self._layout_shart() |
---|
| 375 | self._layout_invariant() |
---|
| 376 | self._layout_warning() |
---|
| 377 | self._layout_button() |
---|
[d0cc0bbc] | 378 | self.main_sizer.AddMany([(self.chart_sizer, 0, wx.ALL, 10), |
---|
| 379 | ( self.invariant_box_sizer, 0, wx.ALL, 10), |
---|
[9ce7641c] | 380 | (self.warning_sizer, 0, wx.ALL, 10), |
---|
| 381 | (self.button_sizer, 0, wx.ALL, 10)]) |
---|
| 382 | self.SetSizer(self.main_sizer) |
---|
[d3fac18] | 383 | |
---|
[9ce7641c] | 384 | |
---|
| 385 | def set_values(self): |
---|
| 386 | """ |
---|
[d7a39e5] | 387 | Set value of txtcrtl |
---|
[9ce7641c] | 388 | """ |
---|
[4a2b054] | 389 | value = format_number(self.qstar_container.qstar) |
---|
| 390 | self.invariant_tcl.SetValue(value) |
---|
| 391 | value = format_number(self.qstar_container.qstar_err) |
---|
| 392 | self.invariant_err_tcl.SetValue(value) |
---|
| 393 | value = format_number(self.qstar_container.qstar_low) |
---|
| 394 | self.invariant_low_tcl.SetValue(value) |
---|
| 395 | value = format_number(self.qstar_container.qstar_low_err) |
---|
| 396 | self.invariant_low_err_tcl.SetValue(value) |
---|
| 397 | value = format_number(self.qstar_container.qstar_high) |
---|
| 398 | self.invariant_high_tcl.SetValue(value) |
---|
| 399 | value = format_number(self.qstar_container.qstar_high_err) |
---|
| 400 | self.invariant_high_err_tcl.SetValue(value) |
---|
[d0cc0bbc] | 401 | |
---|
| 402 | def get_scale(self, percentage, scale_name='scale'): |
---|
[9ce7641c] | 403 | """ |
---|
[d7a39e5] | 404 | Check scale receive in this panel. |
---|
[9ce7641c] | 405 | """ |
---|
[eed601e] | 406 | scale = RECTANGLE_SCALE |
---|
[9ce7641c] | 407 | try: |
---|
[eed601e] | 408 | if percentage in [None, 0.0, "error"]: |
---|
| 409 | scale = RECTANGLE_SCALE |
---|
| 410 | return scale |
---|
[f6518f8] | 411 | elif percentage < 0: |
---|
| 412 | scale = RECTANGLE_SCALE |
---|
| 413 | return scale |
---|
| 414 | scale = float(percentage) |
---|
[9ce7641c] | 415 | except: |
---|
[eed601e] | 416 | scale = RECTANGLE_SCALE |
---|
[a3efdeb] | 417 | self.warning_msg += "Recieve an invalid scale for %s\n" |
---|
| 418 | self.warning_msg += "check this value : %s\n" % str(percentage) |
---|
[eed601e] | 419 | return scale |
---|
[9ce7641c] | 420 | |
---|
| 421 | def set_color_bar(self): |
---|
| 422 | """ |
---|
[d7a39e5] | 423 | Change the color for low and high bar when necessary |
---|
[9ce7641c] | 424 | """ |
---|
[9cec2dd] | 425 | self.extrapolation_color_low = EXTRAPOLATION_COLOR |
---|
| 426 | self.extrapolation_color_high = EXTRAPOLATION_COLOR |
---|
| 427 | self.invariant_color = INVARIANT_COLOR |
---|
[9ce7641c] | 428 | #warning to the user when the extrapolated invariant is greater than %5 |
---|
[f6518f8] | 429 | if self.low_scale >= 0.05 or self.low_scale > 1 or self.low_scale < 0: |
---|
| 430 | self.extrapolation_color_low = ERROR_COLOR |
---|
| 431 | if self.high_scale >= 0.05 or self.high_scale > 1 or self.high_scale < 0: |
---|
| 432 | self.extrapolation_color_high = ERROR_COLOR |
---|
[9cec2dd] | 433 | if self.inv_scale > 1 or self.inv_scale < 0: |
---|
[f6518f8] | 434 | self.invariant_color = ERROR_COLOR |
---|
[9cec2dd] | 435 | |
---|
[9ce7641c] | 436 | def on_close(self, event): |
---|
| 437 | """ |
---|
[d7a39e5] | 438 | Close the current window |
---|
[9ce7641c] | 439 | """ |
---|
| 440 | self.Close() |
---|
[d3fac18] | 441 | |
---|
[9ce7641c] | 442 | def on_paint(self, event): |
---|
| 443 | """ |
---|
[d7a39e5] | 444 | Draw the chart |
---|
[9ce7641c] | 445 | """ |
---|
| 446 | dc = wx.PaintDC(self.panel_chart) |
---|
| 447 | try: |
---|
| 448 | gc = wx.GraphicsContext.Create(dc) |
---|
| 449 | except NotImplementedError: |
---|
[4a2b054] | 450 | msg = "This build of wxPython does not support " |
---|
| 451 | msg += "the wx.GraphicsContext family of classes." |
---|
| 452 | dc.DrawText(msg, 25, 25) |
---|
[9ce7641c] | 453 | return |
---|
| 454 | #Start the drawing |
---|
| 455 | font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) |
---|
| 456 | font.SetWeight(wx.BOLD) |
---|
| 457 | gc.SetFont(font) |
---|
| 458 | # Draw a rectangle |
---|
| 459 | path = gc.CreatePath() |
---|
| 460 | path.AddRectangle(-RECTANGLE_WIDTH/2,-RECTANGLE_HEIGHT/2, |
---|
| 461 | RECTANGLE_WIDTH/2,RECTANGLE_HEIGHT/2) |
---|
[d0cc0bbc] | 462 | x_origine = 20 |
---|
[9ce7641c] | 463 | y_origine = 15 |
---|
| 464 | #Draw low rectangle |
---|
| 465 | gc.PushState() |
---|
[f6518f8] | 466 | label = "Q* from Low-Q " |
---|
[9ce7641c] | 467 | PathFunc = gc.DrawPath |
---|
| 468 | w, h = gc.GetTextExtent(label) |
---|
| 469 | gc.DrawText(label, x_origine, y_origine) |
---|
| 470 | #Translate the rectangle |
---|
| 471 | x_center = x_origine + RECTANGLE_WIDTH * self.low_scale/2 + w +10 |
---|
| 472 | y_center = y_origine + h |
---|
| 473 | gc.Translate(x_center, y_center) |
---|
| 474 | gc.SetPen(wx.Pen("black", 1)) |
---|
| 475 | gc.SetBrush(wx.Brush(self.extrapolation_color_low)) |
---|
[eed601e] | 476 | if self.low_inv_percent is None: |
---|
| 477 | low_percent = 'Not Computed' |
---|
| 478 | elif self.low_inv_percent == 'error': |
---|
| 479 | low_percent = 'Error' |
---|
| 480 | else: |
---|
| 481 | low_percent = format_number(self.low_inv_percent*100)+ '%' |
---|
[d0cc0bbc] | 482 | x_center = 20 |
---|
| 483 | y_center = -h |
---|
| 484 | gc.DrawText(low_percent, x_center, y_center) |
---|
[9ce7641c] | 485 | # Increase width by self.low_scale |
---|
| 486 | gc.Scale(self.low_scale, 1.0) |
---|
| 487 | PathFunc(path) |
---|
| 488 | gc.PopState() |
---|
| 489 | #Draw rectangle for invariant |
---|
| 490 | gc.PushState() # save it again |
---|
| 491 | y_origine += 20 |
---|
[f6518f8] | 492 | gc.DrawText("Q* from Data ", x_origine, y_origine) |
---|
[9ce7641c] | 493 | # offset to the lower part of the window |
---|
| 494 | x_center = x_origine + RECTANGLE_WIDTH * self.inv_scale/2 + w + 10 |
---|
| 495 | y_center = y_origine + h |
---|
| 496 | gc.Translate(x_center, y_center) |
---|
| 497 | # 128 == half transparent |
---|
[f6518f8] | 498 | gc.SetBrush(wx.Brush(self.invariant_color)) |
---|
[9ce7641c] | 499 | # Increase width by self.inv_scale |
---|
[eed601e] | 500 | if self.inv_percent is None: |
---|
| 501 | inv_percent = 'Not Computed' |
---|
| 502 | elif self.inv_percent == 'error': |
---|
| 503 | inv_percent = 'Error' |
---|
| 504 | else: |
---|
| 505 | inv_percent = format_number(self.inv_percent*100)+ '%' |
---|
[d0cc0bbc] | 506 | x_center = 20 |
---|
| 507 | y_center = -h |
---|
| 508 | gc.DrawText(inv_percent, x_center, y_center) |
---|
[9ce7641c] | 509 | gc.Scale(self.inv_scale, 1.0) |
---|
| 510 | gc.DrawPath(path) |
---|
| 511 | gc.PopState() |
---|
| 512 | # restore saved state |
---|
| 513 | #Draw rectangle for high invariant |
---|
| 514 | gc.PushState() |
---|
| 515 | y_origine += 20 |
---|
[f6518f8] | 516 | gc.DrawText("Q* from High-Q ", x_origine, y_origine) |
---|
[9ce7641c] | 517 | #define the position of the new rectangle |
---|
| 518 | x_center = x_origine + RECTANGLE_WIDTH * self.high_scale/2 + w + 10 |
---|
| 519 | y_center = y_origine + h |
---|
| 520 | gc.Translate(x_center, y_center) |
---|
| 521 | gc.SetBrush(wx.Brush(self.extrapolation_color_high)) |
---|
| 522 | # increase scale by self.high_scale |
---|
[eed601e] | 523 | if self.high_inv_percent is None: |
---|
| 524 | high_percent = 'Not Computed' |
---|
| 525 | elif self.high_inv_percent == 'error': |
---|
| 526 | high_percent = 'Error' |
---|
| 527 | else: |
---|
| 528 | high_percent = format_number(self.high_inv_percent*100)+ '%' |
---|
[d0cc0bbc] | 529 | x_center = 20 |
---|
| 530 | y_center = -h |
---|
| 531 | gc.DrawText(high_percent, x_center, y_center) |
---|
| 532 | |
---|
[9ce7641c] | 533 | gc.Scale(self.high_scale, 1.0) |
---|
| 534 | gc.DrawPath(path) |
---|
| 535 | gc.PopState() |
---|