/usr/lib/python2.7/dist-packages/ginga/rv/plugins/MyGlobalPlugin.py is in python-ginga 2.6.1-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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | """
Skeleton example of a Ginga global plugin called 'MyGlobalPlugin'
To enable it, run ginga with the command
$ ginga --modules=MyLocalPlugin
it should become active in the right panel.
"""
from ginga import GingaPlugin
from ginga.gw import Widgets
# import any other modules you want here--it's a python world!
class MyGlobalPlugin(GingaPlugin.GlobalPlugin):
def __init__(self, fv):
"""
This method is called when the plugin is loaded for the first
time. ``fv`` is a reference to the Ginga (reference viewer) shell.
You need to call the superclass initializer and then do any local
initialization.
"""
super(MyGlobalPlugin, self).__init__(fv)
# Your initialization here
# Create some variables to keep track of what is happening
# with which channel
self.active = None
# Subscribe to some interesting callbacks that will inform us
# of channel events. You may not need these depending on what
# your plugin does
fv.set_callback('add-channel', self.add_channel)
fv.set_callback('delete-channel', self.delete_channel)
fv.set_callback('channel-change', self.focus_cb)
def build_gui(self, container):
"""
This method is called when the plugin is invoked. It builds the
GUI used by the plugin into the widget layout passed as
``container``.
This method could be called several times if the plugin is opened
and closed. The method may be omitted if there is no GUI for the
plugin.
This specific example uses the GUI widget set agnostic wrappers
to build the GUI, but you can also just as easily use explicit
toolkit calls here if you only want to support one widget set.
"""
top = Widgets.VBox()
top.set_border_width(4)
# this is a little trick for making plugins that work either in
# a vertical or horizontal orientation. It returns a box container,
# a scroll widget and an orientation ('vertical', 'horizontal')
vbox, sw, orientation = Widgets.get_oriented_box(container)
vbox.set_border_width(4)
vbox.set_spacing(2)
# Take a text widget to show some instructions
self.msgFont = self.fv.get_font("sansFont", 12)
tw = Widgets.TextArea(wrap=True, editable=False)
tw.set_font(self.msgFont)
self.tw = tw
# Frame for instructions and add the text widget with another
# blank widget to stretch as needed to fill emp
fr = Widgets.Frame("Status")
fr.set_widget(tw)
vbox.add_widget(fr, stretch=0)
# Add a spacer to stretch the rest of the way to the end of the
# plugin space
spacer = Widgets.Label('')
vbox.add_widget(spacer, stretch=1)
# scroll bars will allow lots of content to be accessed
top.add_widget(sw, stretch=1)
# A button box that is always visible at the bottom
btns = Widgets.HBox()
btns.set_spacing(3)
# Add a close button for the convenience of the user
btn = Widgets.Button("Close")
btn.add_callback('activated', lambda w: self.close())
btns.add_widget(btn, stretch=0)
btns.add_widget(Widgets.Label(''), stretch=1)
top.add_widget(btns, stretch=0)
# Add our GUI to the container
container.add_widget(top, stretch=1)
# NOTE: if you are building a GUI using a specific widget toolkit
# (e.g. Qt) GUI calls, you need to extract the widget or layout
# from the non-toolkit specific container wrapper and call on that
# to pack your widget, e.g.:
#cw = container.get_widget()
#cw.addWidget(widget, stretch=1)
def get_channel_info(self, fitsimage):
chname = self.fv.get_channel_name(fitsimage)
channel = self.fv.get_channel(chname)
return channel
def set_info(self, text):
self.tw.set_text(text)
# CALLBACKS
def add_channel(self, viewer, channel):
"""
Callback from the reference viewer shell when a channel is added.
"""
self.set_info("Channel '%s' has been added" % (
channel.name))
def delete_channel(self, viewer, channel):
"""
Callback from the reference viewer shell when a channel is deleted.
"""
self.set_info("Channel '%s' has been deleted" % (
channel.name))
return True
def focus_cb(self, viewer, channel):
"""
Callback from the reference viewer shell when the focus changes
between channels.
"""
chname = channel.name
if self.active != chname:
# focus has shifted to a different channel than our idea
# of the active one
self.active = chname
self.set_info("Focus is now in channel '%s'" % (
self.active))
return True
def redo(self, channel, image):
"""
Called from the reference viewer shell when a new image has
been added to a channel.
"""
chname = channel.name
# Only update our GUI if the activity is in the focused
# channel
if self.active == chname:
imname = image.get('name', 'NONAME')
self.set_info("A new image '%s' has been added to channel %s" % (
imname, chname))
return True
def start(self):
"""
This method is called just after ``build_gui()`` when the plugin
is invoked. This method could be called more than once if the
plugin is opened and closed. This method may be omitted
in many cases.
"""
pass
def stop(self):
"""
This method is called when the plugin is stopped.
It should perform any special clean up necessary to terminate
the operation. This method could be called more than once if
the plugin is opened and closed, and may be omitted if there is no
special cleanup required when stopping.
"""
pass
def close(self):
self.fv.stop_global_plugin(str(self))
return True
def __str__(self):
"""
This method should be provided and should return the lower case
name of the plugin.
"""
return 'myglobalplugin'
|