Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _insert_lazy_thumb(self, thumbkey, chname, info, thumbpath):
"""This function gets called to create an initial entry for a
thumb.
"""
thumbname = info.name
self.logger.debug("inserting an empty thumb %s" % (thumbname))
# Make an initial entry for the thumbs in the tracking dict.
# Nothing is actually plotted, because the thumb may be in a region
# that is not visible.
n = len(self.thumb_list)
row = n // self.thumb_num_cols
col = n % self.thumb_num_cols
extras = info.setdefault('thumb_extras', Bunch.Bunch())
bnch = Bunch.Bunch(info=info, extras=extras,
thumbname=thumbname, chname=chname,
thumbpath=thumbpath, row=row, col=col)
self.thumb_dict[thumbkey] = bnch
if thumbkey not in self.thumb_list:
sort_order = self.settings.get('sort_order', None)
if sort_order is not None:
bisect.insort(self.thumb_list, thumbkey)
else:
self.thumb_list.append(thumbkey)
self._latest_thumb = thumbkey
self.timer_update.cond_set(self.update_interval)
#self.timer_update.set(self.update_interval)
def add_history(self, imname, path, idx=None,
image_loader=None, image_future=None):
if not (imname in self.image_index):
if image_loader is None:
image_loader = self.fv.load_image
# create an image_future if one does not exist
if (image_future is None) and (path is not None):
image_future = Future.Future()
image_future.freeze(image_loader, path)
info = Bunch.Bunch(name=imname, path=path,
idx=idx,
image_loader=image_loader,
image_future=image_future,
time_added=time.time(),
time_modified=None,
last_viewer_info=None,
profile=None)
self._add_info(info)
else:
# already in history
info = self.image_index[imname]
return info
else:
try:
# node already exists
bnch = shadow[key]
item = bnch.item
d = bnch.node
except KeyError:
# new node
item = TreeWidgetItem(parent_item, [str(key)])
if level == 1:
parent_item.addTopLevelItem(item)
else:
parent_item.addChild(item)
d = {}
shadow[key] = Bunch.Bunch(node=d, item=item, terminal=False)
# recurse for non-leaf interior node
for key in node:
self._add_subtree(level + 1, d, item, key, node[key])
figure.set_size_inches(wd_in, ht_in)
self.fig = figure
if hasattr(self.fig, 'set_tight_layout'):
self.fig.set_tight_layout(True)
self.logger = logger
self.fontsize = 10
self.ax = None
self.logx = False
self.logy = False
self.xdata = []
self.ydata = []
# for interactive features
self.can = Bunch.Bunch(zoom=False, pan=False)
# For callbacks
for name in ['draw-canvas', 'limits-set']:
self.enable_callback(name)
nb.setAcceptDrops(True)
nb.currentChanged.connect(lambda idx: self.switch_page_cb(idx, nb))
tb = nb.tabBar()
## tb.setAcceptDrops(True)
tb.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
tb.customContextMenuRequested.connect(lambda point: self.on_context_menu(nb, group, point))
else:
nb = StackedWidget()
nb.currentChanged.connect(lambda idx: self.switch_page_cb(idx, nb))
nb.setStyleSheet(tabwidget_style)
if not name:
name = str(time.time())
bnch = Bunch.Bunch(nb=nb, name=name, nbtype=wstype,
widget=nb, group=group)
self.notebooks[name] = bnch
return bnch
menu="History [G]", start=False, category='Utils', ptype='global'),
Bunch(module='Mosaic', workspace='dialogs', category='Utils', ptype='local'),
Bunch(module='Collage', workspace='dialogs', category='Utils', ptype='local'),
Bunch(module='FBrowser', tab='Open File', workspace='right',
menu="Open File [G]", start=False, category='Utils', ptype='global'),
Bunch(module='Preferences', workspace='dialogs', category='Utils',
ptype='local'),
Bunch(module='Ruler', workspace='dialogs', category='Utils', ptype='local'),
# TODO: Add SaveImage to File menu.
Bunch(module='SaveImage', tab='SaveImage', workspace='right',
menu="Save File [G]", start=False, category='Utils', ptype='global'),
Bunch(module='WCSAxes', workspace='dialogs', category='Utils',
ptype='local'),
Bunch(module='WBrowser', tab='Help', workspace='channels', start=False,
menu="Help [G]", category='Help', ptype='global'),
Bunch(module='Header', tab='Header', workspace='left', start=False,
menu="Header [G]", hidden=False, category='Utils', ptype='global'),
Bunch(module='Zoom', tab='Zoom', workspace='left', start=False,
menu="Zoom [G]", category='Utils', ptype='global'),
]
class ReferenceViewer(object):
"""
This class exists solely to be able to customize the reference
viewer startup.
"""
def __init__(self, layout=default_layout, plugins=plugins):
self.layout = layout
self.channels = ['Image']
self.default_plugins = plugins
self.plugins = []
def set_header(self, info, image):
treeview = info.treeview
header = image.get_header()
# Update the header info
listmodel = gtk.ListStore(object)
keyorder = list(header.keys())
sorted = info.sortw.get_active()
if sorted:
keyorder.sort()
for key in keyorder:
card = header.get_card(key)
bnch = Bunch.Bunch(kwd=key, value=str(card.value),
comment=card.comment)
listmodel.append([bnch])
treeview.set_fixed_height_mode(False)
treeview.set_model(listmodel)
# This speeds up rendering of TreeViews
treeview.set_fixed_height_mode(True)
def __init__(self, duration=0.0, mplcanvas=None):
"""Create a timer set to expire after `duration` sec.
"""
super(Timer, self).__init__()
self.duration = duration
# For storing aritrary data with timers
self.data = Bunch.Bunch()
self._timer = mplcanvas.new_timer()
self._timer.single_shot = True
self._timer.add_callback(self._redirect_cb)
for name in ('expired', 'canceled'):
self.enable_callback(name)
('DEC', 'dec'),
('Mag', 'mag'),
('Preference', 'preference'),
('Priority', 'priority'),
('Description', 'description'),
('Index', 'index'),
]
self.catalog = None
self.cursor = 0
self.color_selected = 'skyblue'
self.selection_mode = 'single'
self.selected = []
self.moving_cursor = False
self.btn = Bunch.Bunch()
self.cmap = cmap.get_cmap(self.magcmap)
self.imap = imap.get_imap('ramp')
self.cbar_ht = 32
self.operation_table = []
self._select_flag = False
self._build_gui(container)