/usr/lib/python2.7/dist-packages/ginga/GingaPlugin.py is in python-ginga 2.7.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | #
# GingaPlugin.py -- Base classes for plugins in Ginga reference viewer
#
# This is open-source software licensed under a BSD license.
# Please see the file LICENSE.txt for details.
#
from ginga.misc import Bunch
__all__ = ['PluginError', 'GlobalPlugin', 'LocalPlugin']
class PluginError(Exception):
"""Plugin related error."""
pass
class BasePlugin(object):
"""Base class for all plugins."""
def __init__(self, fv):
super(BasePlugin, self).__init__()
self.fv = fv
self.logger = fv.logger
# Holds GUI widgets
self.w = Bunch.Bunch()
def start(self):
"""
This method is called to start the plugin.
It is called after build_gui().
"""
pass
def stop(self):
"""This method is called to stop the plugin."""
pass
def _help_docstring(self):
import inspect
# Insert section title at the beginning
plg_name = self.__class__.__name__
plg_mod = inspect.getmodule(self)
plg_doc = ('{}\n{}\n'.format(plg_name, '=' * len(plg_name)) +
plg_mod.__doc__)
self.fv.help_text(plg_name, plg_doc, text_kind='rst', trim_pfx=4)
def help(self):
"""Display help for the plugin."""
if not self.fv.gpmon.has_plugin('WBrowser'):
self._help_docstring()
return
self.fv.start_global_plugin('WBrowser')
# need to let GUI finish processing, it seems
self.fv.update_pending()
obj = self.fv.gpmon.get_plugin('WBrowser')
obj.show_help(plugin=self, no_url_callback=self._help_docstring)
class GlobalPlugin(BasePlugin):
"""Class to handle a global plugin."""
def __init__(self, fv):
super(GlobalPlugin, self).__init__(fv)
def initialize(self, container):
"""
This method will be called with a container widget if the global
plugin was requested to be loaded into a workspace. The plugin should
construct its GUI and pack it into the container.
"""
pass
def redo(self, channel, image):
"""This method is called when an image is set in a channel."""
pass
def blank(self, channel):
"""This method is called when a channel is no longer displaying any object."""
pass
class LocalPlugin(BasePlugin):
"""Class to handle a local plugin."""
def __init__(self, fv, fitsimage):
super(LocalPlugin, self).__init__(fv)
self.fitsimage = fitsimage
# find our channel info
if self.fitsimage is not None:
self.chname = self.fv.get_channel_name(self.fitsimage)
self.channel = self.fv.get_channel(self.chname)
# TO BE DEPRECATED
self.chinfo = self.channel
self.fv.add_callback('delete-channel', self._delete_channel_cb)
def modes_off(self):
"""Turn off any mode user may be in."""
bm = self.fitsimage.get_bindmap()
bm.reset_mode(self.fitsimage)
# def build_gui(self, container):
# """
# If a plugin defines this method, it will be called with a
# container object in which to build its GUI. It should finish
# by packing into this container. This will be called every
# time the local plugin is activated.
# """
# pass
def pause(self):
"""
This method is called when the plugin is defocused.
The plugin should disable any user input that it responds to.
"""
pass
def resume(self):
"""
This method is called when the plugin is focused.
The plugin should enable any user input that it responds to.
"""
pass
def redo(self):
"""
This method is called when a new image arrives in the channel
associated with the plugin. It can optionally redo whatever operation
it is doing.
"""
pass
def blank(self):
"""
This method is called when no object is displayed in the channel
associated with the plugin. It can optionally clear whatever operation
it is doing.
"""
pass
def _delete_channel_cb(self, fv, channel):
# stop ourself if our channel is deleted
if channel is self.channel:
self.stop()
# END
|