Skip to content

Commit

Permalink
add and use event on FLATNOTEBOOK CLOSING to turn off Timer, avoiding…
Browse files Browse the repository at this point in the history
… crashes
  • Loading branch information
newville committed Oct 9, 2024
1 parent f276866 commit 7aa9d08
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions epicsapps/instruments/InstrumentApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
Would you like this application to use this instrument file?
"""

from larch.utils import debugtimer
class InstrumentFrame(wx.Frame):
def __init__(self, parent=None, configfile=None, prompt=False, **kws):

Expand All @@ -65,25 +66,35 @@ def __init__(self, parent=None, configfile=None, prompt=False, **kws):
self.configfile = InstrumentConfig(fname=configfile)
self.config = self.configfile.config

dt = debugtimer()
wx.Frame.__init__(self, parent=None, title='Epics Instruments',
size=(925, -1), **kws)

dt.add(' make frame')
self.pvlist = EpicsPVList(self)
dt.add(' get pvlist')
self.connected = {}
self.panels = {}
self.epics_server = None
self.server_timer = None
self.db, self.dbname = self.connect_db(prompt=prompt, **self.config)

if self.db is None:
return
dt.add('db connected')

self.colors = GUIColors()
self.create_Statusbar()
self.create_Menus()
dt.add('create menu')
self.create_Frame()
dt.add('create frame')
self.Bind(wx.EVT_CLOSE, self.onClose)
dt.add('before enable epics')
self.enable_epics_server()

dt.add('after enable epics')
# dt.show()
# print(time.ctime())

def connect_db(self, dbname=None, server='sqlite',
user=None, password=None, host=None, port=None,
recent_dbs=None, new=False, prompt=False, **kws):
Expand Down Expand Up @@ -157,7 +168,8 @@ def connect_db(self, dbname=None, server='sqlite',
def create_Frame(self):
self.nb = flat_nb.FlatNotebook(self, wx.ID_ANY,
agwStyle=FNB_STYLE)
self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.onNBChanged)
self.nb.Bind(flat_nb.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.onNBChanged)
self.nb.Bind(flat_nb.EVT_FLATNOTEBOOK_PAGE_CLOSING, self.onNBClosing)
colors = self.colors
self.nb.SetActiveTabColour(colors.nb_active)
self.nb.SetTabAreaColour(colors.nb_area)
Expand All @@ -179,10 +191,11 @@ def create_Frame(self):
except:
pass

self.Refresh()
# self.Refresh()

def create_nbpages(self):
self.initializing = True
# print("InstApp Create NB")
if self.nb.GetPageCount() > 0:
self.nb.DeleteAllPages()
for row in self.db.get_all_instruments():
Expand All @@ -209,7 +222,7 @@ def onInitTimer(self, evt=None):
callback = getattr(current_page, 'onPanelExposed', None)
if callable(callback):
wx.CallAfter(callback, {'updates': True})

def add_instrument_page(self, instname):
panel = InstrumentPanel(self, instname, db=self.db,
size=(925, -1),
Expand All @@ -219,10 +232,15 @@ def add_instrument_page(self, instname):
self.panels[instname] = panel
self.nb.AddPage(panel, instname, True)

def onNBClosing(self, event=None):
current_page = self.nb.GetCurrentPage()
callback = getattr(current_page, 'onPanelExposed', None)
if callable(callback):
callback(updates=False)

def onNBChanged(self, event=None):
pages = [self.nb.GetPage(i) for i in range(self.nb.GetPageCount())]
current_page = self.nb.GetCurrentPage()
# print("onNB CHANGED ", len(pages), self.initializing)

for page in pages:
callback = getattr(page, 'onPanelExposed', None)
Expand Down

0 comments on commit 7aa9d08

Please sign in to comment.