Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _add_info(self, channel, filelist):
for path in filelist:
name = iohelper.name_image_from_path(path)
info = Bunch.Bunch(name=name, path=path)
self.fv.gui_call(channel.add_image_info, info)
p_canvas = panimage.get_private_canvas()
# add X/Y compass
x, y = 0.5, 0.5
radius = 0.1
compass_xy = p_canvas.add(self.dc.Compass(
x, y, radius,
color=self.settings.get('xy_compass_color', 'yellow'),
fontsize=14, ctype='pixel', coord='percentage'))
iw = Viewers.GingaViewerWidget(panimage)
iw.resize(self._wd, self._ht)
self.nb.add_widget(iw)
#index = self.nb.index_of(iw)
paninfo = Bunch.Bunch(panimage=panimage, widget=iw,
compass_wcs=None, compass_xy=compass_xy,
panrect=None)
channel.extdata._pan_info = paninfo
fitsimage.copy_attributes(panimage, self.copy_attrs)
fitsimage.add_callback('redraw', self.redraw_cb, channel)
fitsimage.add_callback('image-set',
lambda viewer, image: self._redo(channel, image))
self.logger.debug("channel '%s' added." % (channel.name))
#
# font_asst.py -- Font assistant routines
#
# This is open-source software licensed under a BSD license.
# Please see the file LICENSE.txt for details.
#
import os
from ginga.misc import Bunch
# lookup table of cached fonts, for backends that build them
font_cache = Bunch.Bunch(caseless=True)
# lookup table of font
font_dir = Bunch.Bunch(caseless=True)
# Set up font alias mapping
aliases = Bunch.Bunch(caseless=True)
# font scaling factors
default_scaling_factor = 1.0
scaling_factor = Bunch.Bunch(caseless=True)
def add_alias(alias_name, font_name):
"""Add an alias for a font family name.
e.g. add_alias('fixed', 'Monotype')
"""
def __init__(self, app):
super(Desktop, self).__init__()
self.app = app
self.logger = app.logger
# for tabs
self.tab = Bunch.caselessDict()
self.tabcount = 0
self.workspace = Bunch.caselessDict()
self.default_ws_name = None
self.toplevels = []
self.node = {}
self.node_idx = 0
self._cur_dialogs = []
for name in ('page-switch', 'page-close', 'all-closed'):
self.enable_callback(name)
def make_widget(kind, params, args, pack):
kind = kind.lower()
# Process workspace parameters
param_dict = Bunch.Bunch(name=None, title=None, height=-1,
width=-1, group=1, show_tabs=True,
show_border=False, scrollable=True,
detachable=False, wstype='tabs',
tabpos='top', use_toolbar=False)
param_dict.update(params)
params.update(param_dict)
if kind == 'widget':
widget = args[0]
elif kind == 'ws':
group = int(params.group)
ws = self.make_ws(params.name, group=group,
show_tabs=params.show_tabs,
show_border=params.show_border,
detachable=params.detachable,
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.create_category('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)
fv.add_callback('add-image-info', self._ch_image_added_cb)
fv.add_callback('remove-image-info', self._ch_image_removed_cb)
# Use X and Y positions directly. Convert to RA and DEC (deg).
if ra is None or dec is None:
ra, dec = image.pixtoradec(x, y)
# RA and DEC already in degrees. Convert to pixel X and Y.
else:
x, y = image.radectopix(ra, dec)
# Display original X/Y (can be 0- or 1-indexed) using
# our internal 0-indexed values.
xdisp = x + self.pixelstart
ydisp = y + self.pixelstart
seqstr = '{0:04d}'.format(seqno) # Prepend 0s for proper sort
bnch = Bunch.Bunch(zip(self.extra_columns, args[4:])) # Extra
bnch.update(Bunch.Bunch(MARKID=seqstr, RA=ra, DEC=dec,
X=xdisp, Y=ydisp))
# Do not draw out of bounds
if (not np.isfinite(x) or x < 0 or x > max_x or
not np.isfinite(y) or y < 0 or y > max_y):
self.logger.debug('Ignoring RA={0}, DEC={1} '
'(x={2}, y={3})'.format(ra, dec, x, y))
bad_sub_dict[seqstr] = bnch
nbad += 1
# Display point
else:
obj = self._get_markobj(
x, y, marktype, marksize, markcolor, self.markwidth)
objlist.append(obj)
('Priority', 'priority'),
('Description', 'description'),
]
# Append extra columns returned by search to table header
# TODO: what if not all sources have same record structure?
# is this possible with VO?
cols = list(source.keys())
cols.remove('RA')
cols.remove('DEC')
cols.remove('id')
columns.extend(zip(cols, cols))
# which column is the likely one to color source circles
colorCode = 'Mag'
info = Bunch.Bunch(columns=columns, color=colorCode)
return starlist, info
pass
# This is to get around table widget not sorting numbers properly
i_fmt = '{{0:0{0}d}}'.format(len(str(len(a_tab))))
# Table header with units
columns = [('Row', '_DISPLAY_ROW')]
for c in a_tab.columns.values():
col_str = '{0:^s}\n{1:^s}'.format(c.name, str(c.unit))
columns.append((col_str, c.name))
self.widget.setup_table(columns, 1, '_DISPLAY_ROW')
# Table contents
for i, row in enumerate(a_tab, 1):
bnch = Bunch.Bunch(zip(row.colnames, row.as_void()))
i_str = i_fmt.format(i)
bnch['_DISPLAY_ROW'] = i_str
tree_dict[i_str] = bnch
self.widget.set_tree(tree_dict)
# Resize column widths
n_rows = len(tree_dict)
if n_rows < self.settings.get('max_rows_for_col_resize', 5000):
self.widget.set_optimal_column_widths()
self.logger.debug('Resized columns for {0} row(s)'.format(n_rows))
tablename = table.get('name', 'NoName')
self.logger.debug('Displayed {0}'.format(tablename))
readout.fitsimage = fi
fi.add_callback('image-set', self.readout_config, readout)
self.add_callback('field-info', self.readout_cb, readout, name)
rw = readout.get_widget()
# one level deeper to the native widget in gw.Readout
rw = rw.get_widget()
vbox.pack_start(rw, padding=0, fill=True, expand=False)
else:
readout = None
vbox.show_all()
# Add a page to the specified notebook
if not workspace:
workspace = 'channels'
bnch = Bunch.Bunch(fitsimage=fi, view=iw, container=vbox,
readout=readout, workspace=workspace)
self.ds.add_tab(workspace, vbox, 1, name, data=bnch)
self.update_pending()
return bnch