/usr/lib/python3/dist-packages/ginga/rv/plugins/Toolbar.py is in python3-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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | #
# Toolbar.py -- Tool bar plugin for the Ginga fits viewer
#
# This is open-source software licensed under a BSD license.
# Please see the file LICENSE.txt for details.
#
import os.path
from ginga.gw import Widgets
from ginga.misc import Bunch
from ginga import GingaPlugin
class Toolbar(GingaPlugin.GlobalPlugin):
def __init__(self, fv):
# superclass defines some variables for us, like logger
super(Toolbar, self).__init__(fv)
# active view
self.active = None
# holds our gui widgets
self.w = Bunch.Bunch()
self.gui_up = False
# get local plugin preferences
prefs = self.fv.get_preferences()
self.settings = prefs.createCategory('plugin_Toolbar')
self.settings.load(onError='silent')
self.modetype = self.settings.get('mode_type', 'oneshot')
fv.set_callback('add-channel', self.add_channel_cb)
fv.set_callback('delete-channel', self.delete_channel_cb)
fv.set_callback('channel-change', self.focus_cb)
def build_gui(self, container):
top = Widgets.VBox()
top.set_border_width(0)
vbox, sw, orientation = Widgets.get_oriented_box(container)
self.orientation = orientation
vbox.set_spacing(0)
vbox.set_border_width(0)
tb = Widgets.Toolbar(orientation=orientation)
for tup in (
#("Load", 'button', 'fits_open_48', "Open an image file",
#None),
("FlipX", 'toggle', 'flipx_48', "Flip image in X axis",
self.flipx_cb),
("FlipY", 'toggle', 'flipy_48', "Flip image in Y axis",
self.flipy_cb),
("SwapXY", 'toggle', 'swapxy_48', "Swap X and Y axes",
self.swapxy_cb),
("---",),
("Rot90", 'button', 'rot90ccw_48', "Rotate image 90 deg",
self.rot90_cb),
("RotN90", 'button', 'rot90cw_48', "Rotate image -90 deg",
self.rotn90_cb),
("OrientRH", 'button', 'orient_nw_48', "Orient image N=Up E=Right",
self.orient_rh_cb),
("OrientLH", 'button', 'orient_ne_48', "Orient image N=Up E=Left",
self.orient_lh_cb),
("---",),
("Prev", 'button', 'prev_48', "Go to previous channel",
lambda w: self.fv.prev_channel()),
("Next", 'button', 'next_48', "Go to next channel",
lambda w: self.fv.next_channel()),
("Up", 'button', 'up_48', "Go to previous image in channel",
lambda w: self.fv.prev_img()),
("Down", 'button', 'down_48', "Go to next image in channel",
lambda w: self.fv.next_img()),
("---",),
("Zoom In", 'button', 'zoom_in_48', "Zoom in",
lambda w: self.fv.zoom_in()),
("Zoom Out", 'button', 'zoom_out_48', "Zoom out",
lambda w: self.fv.zoom_out()),
("Zoom Fit", 'button', 'zoom_fit_48', "Zoom to fit window size",
lambda w: self.fv.zoom_fit()),
("Zoom 1:1", 'button', 'zoom_100_48', "Zoom to 100% (1:1)",
lambda w: self.fv.zoom_1_to_1()),
("---",),
("Pan", 'toggle', 'pan_48', "Pan with left, zoom with right",
lambda w, tf: self.mode_cb(tf, 'pan')),
("FreePan", 'toggle', 'hand_48', "Free Panning",
lambda w, tf: self.mode_cb(tf, 'freepan')),
("Rotate", 'toggle', 'rotate_48', "Interactive rotation",
lambda w, tf: self.mode_cb(tf, 'rotate')),
("Cuts", 'toggle', 'cuts_48',
"Left/right sets hi cut, up/down sets lo cut",
lambda w, tf: self.mode_cb(tf, 'cuts')),
("Contrast", 'toggle', 'contrast_48',
"Contrast/bias with left/right/up/down",
lambda w, tf: self.mode_cb(tf, 'contrast')),
("ModeLock", 'toggle', 'lock_48',
"Modes are oneshot or locked", self.set_locked_cb),
("---",),
("Center", 'button', 'center_image_48', "Center image",
self.center_image_cb),
("Restore", 'button', 'reset_rotation_48',
"Reset all transformations and rotations",
self.reset_all_transforms_cb),
("AutoLevels", 'button', 'auto_cuts_48', "Auto cut levels",
self.auto_levels_cb),
("ResetContrast", 'button', 'reset_contrast_48', "Reset contrast",
self.reset_contrast_cb),
("---",),
("Preferences", 'button', 'settings_48', "Set channel preferences",
lambda w: self.start_plugin_cb('Preferences')),
("FBrowser", 'button', 'open_48', "Open file",
lambda w: self.start_plugin_cb('FBrowser')),
## ("Histogram", 'button', 'open_48', "Histogram and cut levels",
## lambda w: self.start_plugin_cb('Histogram')),
#("Quit", 'button', 'exit_48', "Quit the program"),
):
name = tup[0]
if name == '---':
tb.add_separator()
continue
iconpath = os.path.join(self.fv.iconpath, "%s.png" % (tup[2]))
btn = tb.add_action(None, toggle=(tup[1]=='toggle'),
iconpath=iconpath)
if tup[3]:
btn.set_tooltip(tup[3])
if tup[4]:
btn.add_callback('activated', tup[4])
# add to our widget dict
self.w[Widgets.name_mangle(name, pfx='btn_')] = btn
# add widget to toolbar
#tb.add_widget(btn)
hbox = Widgets.HBox()
hbox.add_widget(tb, stretch=0)
# stretcher
hbox.add_widget(Widgets.Label(''), stretch=1)
#sw.set_widget(tb)
#top.add_widget(sw, stretch=1)
container.add_widget(hbox, stretch=0)
self.gui_up = True
# CALLBACKS
def add_channel_cb(self, viewer, channel):
fitsimage = channel.fitsimage
fitsimage.add_callback('transform', self.viewer_transform_cb)
bm = fitsimage.get_bindmap()
bm.add_callback('mode-set', self.mode_set_cb, fitsimage)
def delete_channel_cb(self, viewer, channel):
self.logger.debug("delete channel %s" % (channel.name))
# we don't keep around any baggage on channels so nothing
# to delete
def focus_cb(self, viewer, channel):
fitsimage = channel.fitsimage
self.active = fitsimage
self._update_toolbar_state(fitsimage)
return True
def center_image_cb(self, w):
view, bd = self._get_view()
bd.kp_center(view, 'x', 0.0, 0.0)
return True
def reset_contrast_cb(self, w):
view, bd = self._get_view()
bd.kp_contrast_restore(view, 'x', 0.0, 0.0)
return True
def auto_levels_cb(self, w):
view, bd = self._get_view()
bd.kp_cut_auto(view, 'x', 0.0, 0.0)
return True
def rot90_cb(self, w):
view, bd = self._get_view()
bd.kp_rotate_inc90(view, 'x', 0.0, 0.0)
return True
def rotn90_cb(self, w):
view, bd = self._get_view()
bd.kp_rotate_dec90(view, 'x', 0.0, 0.0)
return True
def orient_lh_cb(self, w):
view, bd = self._get_view()
bd.kp_orient_lh(view, 'x', 0.0, 0.0)
return True
def orient_rh_cb(self, w):
view, bd = self._get_view()
bd.kp_orient_rh(view, 'x', 0.0, 0.0)
return True
def reset_all_transforms_cb(self, w):
view, bd = self._get_view()
bd.kp_rotate_reset(view, 'x', 0.0, 0.0)
return True
def start_plugin_cb(self, name):
self.fv.start_operation(name)
return True
def flipx_cb(self, w, tf):
view, bd = self._get_view()
flip_x, flip_y, swap_xy = view.get_transforms()
flip_x = tf
view.transform(flip_x, flip_y, swap_xy)
return True
def flipy_cb(self, w, tf):
view, bd = self._get_view()
flip_x, flip_y, swap_xy = view.get_transforms()
flip_y = tf
view.transform(flip_x, flip_y, swap_xy)
return True
def swapxy_cb(self, w, tf):
view, bd = self._get_view()
flip_x, flip_y, swap_xy = view.get_transforms()
swap_xy = tf
view.transform(flip_x, flip_y, swap_xy)
return True
def mode_cb(self, tf, modename):
if self.active is None:
self.active, bd = self._get_view()
fitsimage = self.active
if fitsimage is None:
return
bm = fitsimage.get_bindmap()
if not tf:
bm.reset_mode(fitsimage)
return True
bm.set_mode(modename)
# just in case mode change failed
self._update_toolbar_state(fitsimage)
return True
def mode_set_cb(self, bm, mode, mtype, fitsimage):
# called whenever the user interaction mode is changed
# in the viewer
if self.active is None:
self.active, bd = self._get_view()
if fitsimage != self.active:
return True
self._update_toolbar_state(fitsimage)
return True
def viewer_transform_cb(self, fitsimage):
# called whenever the transform (flip x/y, swap axes) is done
# in the viewer
if self.active is None:
self.active, bd = self._get_view()
if fitsimage != self.active:
return True
self._update_toolbar_state(fitsimage)
return True
def new_image_cb(self, fitsimage, image):
self._update_toolbar_state(fitsimage)
return True
def set_locked_cb(self, w, tf):
if tf:
modetype = 'locked'
else:
modetype = 'oneshot'
if self.active is None:
self.active, bd = self._get_view()
fitsimage = self.active
if fitsimage is None:
return
# get current bindmap, make sure that the mode is consistent
# with current lock button
bm = fitsimage.get_bindmap()
modename, cur_modetype = bm.current_mode()
bm.set_default_mode_type(modetype)
bm.set_mode(modename, mode_type=modetype)
if not tf:
# turning off lock also resets the mode
bm.reset_mode(fitsimage)
self._update_toolbar_state(fitsimage)
return True
# LOGIC
def _get_view(self):
channel = self.fv.get_channel_info()
view = channel.fitsimage
return (view, view.get_bindings())
def _update_toolbar_state(self, fitsimage):
if (fitsimage is None) or (not self.gui_up):
return
self.logger.debug("updating toolbar state")
try:
# update transform toggles
flipx, flipy, swapxy = fitsimage.get_transforms()
# toolbar follows view
self.w.btn_flipx.set_state(flipx)
self.w.btn_flipy.set_state(flipy)
self.w.btn_swapxy.set_state(swapxy)
# update mode toggles
bm = fitsimage.get_bindmap()
modename, mode_type = bm.current_mode()
self.logger.debug("modename=%s" % (modename))
# toolbar follows view
self.w.btn_pan.set_state(modename == 'pan')
self.w.btn_freepan.set_state(modename == 'freepan')
self.w.btn_rotate.set_state(modename == 'rotate')
self.w.btn_cuts.set_state(modename == 'cuts')
self.w.btn_contrast.set_state(modename == 'contrast')
default_mode_type = bm.get_default_mode_type()
if self.w.has_key('btn_modelock'):
is_locked = (default_mode_type in ('locked', 'softlock'))
self.w.btn_modelock.set_state(is_locked)
except Exception as e:
self.logger.error("error updating toolbar: %s" % str(e))
raise e
def __str__(self):
return 'toolbar'
#END
|