def attach(self, OM_obj_uid): """Attaches this object to a ObjectManager object. Example: self.attach(('log', 1)) OM.remove(('log', 1)) -> self will be removed by UIManager """ # print ('ATTACHING...') # obj = OM.get(OM_objuid) try: OM = ObjectManager() # Is OM_objuid valid? obj = OM.get(OM_obj_uid) if obj: OM.subscribe(self._check_OM_removals, 'pre_remove') self._attached_to = obj.uid # print ('{} IS NOW ATTACHED TO {} \n'.format(self.uid, self._attached_to)) except Exception as e: print('ERROR WHILE ATTACHING:', e)
def PostInit(self): OM = ObjectManager() OM.subscribe(self._on_OM_object_added, 'add') OM.subscribe(self._on_OM_object_removed, 'post_remove')
class Dialog(wx.Dialog): def __init__(self, *args, **kwargs): if 'on_ok_callback' in kwargs: self.on_ok_callback = kwargs.pop('on_ok_callback') else: self.on_ok_callback = None if 'on_cancel_callback' in kwargs: self.on_cancel_callback = kwargs.pop('on_cancel_callback') else: self.on_cancel_callback = None super(Dialog, self).__init__(*args, **kwargs) self._OM = ObjectManager() self._OM.subscribe(self.on_wells_changed, 'add') self._OM.subscribe(self.on_wells_changed, 'post_remove') #self._OM.addcallback('add_object', self.on_wells_changed) #self._OM.addcallback('post_remove_object', self.on_wells_changed) self.well_selector = wx.Choice(self) self.well_selector.Bind(wx.EVT_CHOICE, self.on_well_select) self.export_panel = Panel(self) button_sizer = self.CreateButtonSizer(wx.OK | wx.CANCEL) self.Bind(wx.EVT_BUTTON, self.on_button) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(self.well_selector, proportion=0, flag=wx.ALIGN_CENTER) vbox.Add(self.export_panel, proportion=1, flag=wx.ALL | wx.EXPAND) vbox.Add(button_sizer, flag=wx.ALIGN_RIGHT) self.SetSizer(vbox) self.SetSize((400, 600)) self.SetTitle(u"Exportar:") self.welluid = None self.wellmap = [] self.iwellmap = {} self.on_wells_changed(None) def get_welluid(self): return self.welluid def set_welluid(self, welluid): self.welluid = welluid self.well_selector.SetSelection( self.iwellmap.get(welluid, wx.NOT_FOUND)) self.export_panel.set_welluid(welluid) def set_depth_selection(self, selection): self.export_panel.set_depth_selection(selection) def get_depth_selection(self): return self.export_panel.get_depth_selection() def set_log_selection(self, selection): self.export_panel.set_log_selection(selection) def get_log_selection(self): return self.export_panel.get_log_selection() def set_partition_selection(self, selection): self.export_panel.set_partition_selection(selection) def get_partition_selection(self): return self.export_panel.get_partition_selection() def set_property_selection(self, selection): self.export_panel.set_property_selection(selection) def get_property_selection(self): return self.export_panel.get_property_selection() def on_well_select(self, event): i = event.GetSelection() self.set_welluid(self.wellmap[i]) def on_wells_changed(self, objuid): wellnames = [] self.wellmap = [] self.iwellmap.clear() self.well_selector.Clear() self.set_welluid(None) for i, well in enumerate(self._OM.list('well')): self.wellmap.append(well.uid) self.iwellmap[well.uid] = i wellnames.append(well.name) self.well_selector.AppendItems(wellnames) if len(self.wellmap) == 1: self.set_welluid(self.wellmap[0]) def on_button(self, event): evt_id = event.GetId() if evt_id == wx.ID_OK and self.on_ok_callback is not None: self.on_ok_callback(event) elif evt_id == wx.ID_CANCEL and self.on_cancel_callback is not None: self.on_cancel_callback(event) event.Skip(True) def __del__(self): self._OM.removecallback("add", self.on_wells_changed) self._OM.removecallback("post-remove", self.on_wells_changed) super(Dialog, self).__del__()