# uncompyle6 version 3.9.3 # Python bytecode version base 2.6 (62161) # Decompiled from: Python 3.9.25 (main, Oct 31 2025, 23:16:49) # [GCC 14.2.0] # Embedded file name: dialog.pyc # Compiled at: 2024-11-13 12:27:50 import mytime, wx, os, data_model, traceback, one_unit, sys, inspect, protocol mac_names = 'posix' def getString(strID): return one_unit.getString(strID) class Dialog(wx.Dialog): def __init__(self, parent, id, title, infotext='', optkey=None, optmask=0, opttext={}, bgcolour=(220, 220, 220), fgcolour=(70, 70, 70), OK_Only=False, textkey=None, default_text=None, IsPassword=False, Set=True, Wrap=400, size=(250, 100), bg=None, choices={}, value_mask=None, selectkey=None, default_choice=0, OK_Enable=True, OKtext='Ok', Canceltext='Cancel', OK_Show=True, max=None, default_options=0, always_use_default_choice=False): wx.Dialog.__init__(self, None, wx.ID_ANY, title, size=size, style=wx.STAY_ON_TOP | wx.CAPTION | wx.DEFAULT_DIALOG_STYLE) self.parent = parent self.value_mask = value_mask self.optkey = optkey self.updating = False self.response = 'Cancel' self.textkey = textkey self.selectkey = selectkey self.options = default_options self.choices = choices self.default_options = default_options self.max = max self.optmask = optmask self.frame_height = 2 * wx.SystemSettings.GetMetric(wx.SYS_CAPTION_Y) + wx.SystemSettings.GetMetric(wx.SYS_BORDER_Y) if os.name in mac_names: self.frame_height = 24 self.chkboxes = {} self.Set = Set self.infotext = None self.textpanel = wx.Panel(self, -1) textvbox = wx.BoxSizer(wx.VERTICAL) textfieldpanel = wx.Panel(self, -1) textfieldvbox = wx.BoxSizer(wx.VERTICAL) selectfieldpanel = wx.Panel(self, -1) selectfieldvbox = wx.BoxSizer(wx.VERTICAL) optionspanel = wx.Panel(self, -1) optionsvbox = wx.BoxSizer(wx.VERTICAL) buttonspanel = wx.Panel(self, -1) buttonshbox = wx.BoxSizer(wx.HORIZONTAL) mainvbox = wx.BoxSizer(wx.VERTICAL) if infotext != '': textstring = wx.StaticText(self.textpanel, -1, infotext, style=wx.ALIGN_LEFT) textstring.Wrap(Wrap) textstring.SetForegroundColour(fgcolour) textvbox.Add(textstring, 1, wx.EXPAND) self.textpanel.SetSizer(textvbox) if Wrap > 0: textvbox.SetMinSize((Wrap, 10)) else: textvbox.SetMinSize(size) mainvbox.Add(self.textpanel, 0, border=10, flag=wx.ALL) self.infotext = textstring self.infostring = infotext self.wrap = Wrap if textkey != None: textval = '' if default_text == None: try: textval = self.parent.model.get(textkey) retries = 20 while textval == None and retries > 0: print mytime.clock(), 'Retrieving text value for dialog with key', textkey self.parent.remote_link.set_get_key(textkey) retries -= 1 mytime.sleep(0.1) textval = self.parent.model.get(textkey) except: print mytime.displayTime() + ' Failed to get text for dialog' traceback.print_exc(file=sys.stdout) if textval == None: textval = '' if default_text != None: textval = default_text if IsPassword == True: style = wx.TE_PROCESS_ENTER | wx.TE_PASSWORD else: style = wx.TE_PROCESS_ENTER textfield = wx.TextCtrl(textfieldpanel, 3, unicode(textval), style=style) textfieldvbox.Add(textfield, 1, border=5, flag=wx.ALIGN_LEFT | wx.ALL) textfield.SetFocus() textfieldpanel.SetSizer(textfieldvbox) mainvbox.Add(textfieldpanel, 0, border=10, flag=wx.LEFT | wx.RIGHT) self.textfield = textfield if selectkey != None: selectval = None try: selectval = self.parent.model.get(selectkey) retries = 20 while selectval == None and retries > 0: print mytime.clock(), 'Retrieving select value for dialog with key', selectkey self.parent.remote_link.set_get_key(selectkey) retries -= 1 mytime.sleep(0.1) selectval = self.parent.model.get(selectkey) if value_mask != None: selectval = int(int(selectval) & value_mask) except: traceback.print_exc(file=sys.stdout) else: if selectval == None or always_use_default_choice == True: selectval = default_choice if selectval not in self.choices.keys(): selectval = default_choice style = wx.BORDER_NONE | wx.CB_READONLY mychoices = [] for i in sorted(choices.keys()): mychoices.append(choices[i]) selectfield = wx.ComboBox(selectfieldpanel, 30, choices=mychoices, style=style) selectfield.SetStringSelection(self.choices[selectval]) selectfieldvbox.Add(selectfield, 1, border=5, flag=wx.ALIGN_LEFT | wx.ALL) selectfieldpanel.SetSizer(selectfieldvbox) mainvbox.Add(selectfieldpanel, 0, border=10, flag=wx.LEFT | wx.RIGHT) self.selectfield = selectfield if optkey != None and optmask != 0: try: options = int(self.parent.model.get(optkey)) except: options = default_options else: chkboxes = {} for i in range(0, 31): optnr = optmask & 1 << i val = options & 1 << i if optnr > 0: try: this_opttext = opttext[optnr] except: this_opttext = 'Unlisted Option: ' + hex(optnr) else: chkboxes[i] = wx.CheckBox(optionspanel, -1, this_opttext) chkboxes[i].SetForegroundColour(fgcolour) optionsvbox.Add(chkboxes[i], 1, border=5, flag=wx.ALIGN_LEFT | wx.ALL) if val > 0: chkboxes[i].SetValue(1) optionspanel.SetSizer(optionsvbox) optionsvbox.SetMinSize((250, 10)) mainvbox.Add(optionspanel, 0, border=10, flag=wx.LEFT | wx.RIGHT) self.chkboxes = chkboxes self.OK_button = wx.Button(buttonspanel, 1, OKtext) self.OK_button.Enable(OK_Enable) self.OK_button.Show(OK_Show) buttonshbox.Add(self.OK_button, 1, border=0, flag=wx.ALL) if OK_Only == False: buttonshbox.Add(wx.Button(buttonspanel, 2, Canceltext), 1, border=0, flag=wx.ALL) buttonspanel.SetSizer(buttonshbox) if OK_Only == True: buttonshbox.SetMinSize((75, self.frame_height)) else: buttonshbox.SetMinSize((150, self.frame_height)) mainvbox.Add(buttonspanel, 0, border=5, flag=wx.ALL) self.SetSizerAndFit(mainvbox) self.Centre() self.textvbox = textvbox self.SetBackgroundColour(bgcolour) self.Bind(wx.EVT_TEXT_ENTER, self.OnOK, id=3) self.Bind(wx.EVT_COMBOBOX, self.OnCombo, id=30) self.Bind(wx.EVT_BUTTON, self.OnOK, id=1) self.Bind(wx.EVT_BUTTON, self.OnCancel, id=2) self.CenterOnScreen() self.mainvbox = mainvbox self.response = None self.initialSize = self.GetSize() self.initialPosition = self.GetPosition() return def OnCombo(self, evt): self.Raise() return def OnEraseBackground(self, evt): """ Add a picture to the background """ dc = evt.GetDC() if not dc: dc = wx.ClientDC(self) rect = self.GetUpdateRegion().GetBox() dc.SetClippingRect(rect) dc.Clear() bmp = wx.Bitmap(self.bg) dc.DrawBitmap(bmp, 0, 0) self.Raise() return def OnOK(self, evt): self.response = 'OK' try: if self.textkey != None and self.Set == True: val = self.textfield.GetValue() if self.max != None: try: if float(val) > self.max: val = self.max except: pass self.parent.set_value(self.textkey, val) if self.optkey != None and self.optmask != 0: try: options = int(self.parent.model.get(self.optkey)) except: options = self.default_options else: for i in range(0, 31): optnr = self.optmask & 1 << i val = 1 << i if optnr > 0: if self.chkboxes[i].GetValue() == True: options |= val else: options &= 4294967295L - val if self.Set == True: self.parent.set_value(self.optkey, options) self.options = options if self.selectkey != None and self.Set == True: s = self.selectfield.GetStringSelection() for (k, v) in self.choices.items(): if v == s: v = k print mytime.displayTime() + ' setting to', v, 'mask', self.value_mask if self.value_mask != None: val = int(self.parent.model.get(self.selectkey)) & (4294967295L ^ self.value_mask) val |= int(v) v = val self.parent.set_value(self.selectkey, v) except: traceback.print_exc(file=sys.stdout) if self.IsModal() == False: self.Destroy() else: self.Close() return def OnCancel(self, evt): if self.IsModal == False: self.Destroy() else: self.Close() return def Update(self, text): while self.updating == True: mytime.sleep(0.1) self.updating = True self.infostring = unicode(text) if os.name in mac_names: self.textvbox.Detach(self.infotext) self.infotext.Destroy() self.infotext = wx.StaticText(self.textpanel, -1, self.infostring, style=wx.ALIGN_LEFT | wx.ST_NO_AUTORESIZE) self.textvbox.Add(self.infotext, 1, wx.EXPAND) else: self.infotext.SetLabel(self.infostring) self.infotext.Wrap(self.wrap) self.Layout() self.SetSizerAndFit(self.mainvbox) self.updating = False return def EnableOK(self, OK_Enable): self.OK_button.Enable(OK_Enable) return def ShowOK(self, OK_Enable): self.OK_button.Show(OK_Enable) return aantalBits = 32 class mapOutputToInput(wx.Dialog): def __init__(self, parent, bits, title): self.parent = parent x = 50 + len(self.parent.unit_channels) * 50 y = 110 + 18 * aantalBits size = (x, y) wx.Dialog.__init__(self, None, wx.ID_ANY, title, size=size, style=wx.STAY_ON_TOP | wx.CAPTION | wx.DEFAULT_DIALOG_STYLE) self.p = wx.Panel(self) self.p.SetSize(size) self.res = bits self.response = 'Cancel' self.OK_button = wx.Button(self.p, 1, 'OK', pos=(size[0] - 200, size[1] - 60), size=(80, 20)) self.Cancel_button = wx.Button(self.p, 2, 'Cancel', pos=(size[0] - 100, size[1] - 60), size=(80, 20)) self.Bind(wx.EVT_BUTTON, self.OnOK, id=1) self.Bind(wx.EVT_BUTTON, self.OnCancel, id=2) self.flags = {} self.enable = {} x = 30 for channel in sorted(bits.keys()): if channel < 128: wx.StaticText(self.p, -1, 'In ' + str(channel + 1), pos=(x, 20)) else: wx.StaticText(self.p, -1, 'Out ' + str(channel - 127), pos=(x, 20)) val = bits[channel] self.flags[channel] = {} for i in range(aantalBits): y = 40 + i * 18 channelString = str(i + 1) self.flags[channel][i] = wx.CheckBox(self.p, -1, channelString, pos=(x, y), size=(50, 18)) self.flags[channel][i].SetValue(val & 1 << i) x += 50 return def OnOK(self, evt): for channel in self.parent.unit_channels: val = 0 for i in range(aantalBits): val += self.flags[channel][i].GetValue() << i self.res[channel] = val self.response = 'OK' if self.IsModal() == False: self.Destroy() else: self.Close() return def OnCancel(self, evt): if self.IsModal == False: self.Destroy() else: self.Close() return # okay decompiling pycode/dialog.pyc