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