extensions one-off activation - attach_window / detach_window the way to go?



Hiya.  I'm writing a small Python Epiphany extension.  I want to do
some one-off initialization when the extension is activated (and some
clean-up when deactivated, either through the Tools -> Extensions
dialog or when all windows are closed).  Doing this code
once-every-window-open or every-tab-open seems too often to me, so I'm
doing something like

------------------------------------
window_count = 0

def attach_window(window):
 global window_count
 if window_count == 0:
   do_init()
 window_count += 1

def detach_window(window):
 global window_count
 window_count -= 1
 if window_count == 0:
   do_cleanup()
------------------------------------

I was just wondering if this would be the right way to go about it, or
is this not thread-safe (are extensions (and their event handlers) run
single-threadedly??) or is there an extension_activated signal that I
can listen for?

I have taken a quick look at
epiphany-extensions/extensions/sample-python/*.py and they activate
themselves on attach_window, but that makes sense, since they do
per-window UI changes.  But I only want to fiddle with
epiphany.ephy_shell_get_default().get_bookmarks().



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]