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