Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def build_info(captions, orientation='vertical'):
# numrows = len(captions)
numcols = reduce(lambda acc, tup: max(acc, len(tup)), captions, 0)
if (numcols % 2) != 0:
raise ValueError("Column spec is not an even number")
numcols = int(numcols // 2)
widget = QtGui.QWidget()
table = QtGui.QGridLayout()
widget.setLayout(table)
table.setVerticalSpacing(2)
table.setHorizontalSpacing(4)
table.setContentsMargins(2, 2, 2, 2)
wb = Bunch.Bunch()
row = 0
for tup in captions:
col = 0
while col < numcols:
idx = col * 2
if idx < len(tup):
title, wtype = tup[idx:idx + 2]
if not title.endswith(':'):
name = name_mangle(title)
hbox.addWidget(btn1)
btn2 = QtGui.QRadioButton("Edit")
btn2.setChecked(mode == 'edit')
btn2.toggled.connect(lambda val: self.set_mode_cb('edit', val))
btn2.setToolTip("Choose this to edit things on the canvas")
hbox.addWidget(btn2)
btn3 = QtGui.QRadioButton("Pick")
btn3.setChecked(mode == 'pick')
btn3.toggled.connect(lambda val: self.set_mode_cb('pick', val))
btn3.setToolTip("Choose this to pick things on the canvas")
hbox.addWidget(btn3)
hbox.addWidget(QtGui.QLabel(''), stretch=1)
hw = QtGui.QWidget()
hw.setLayout(hbox)
vbox.addWidget(hw, stretch=0)
vw = QtGui.QWidget()
self.setCentralWidget(vw)
vw.setLayout(vbox)
self.w.mnb.subWindowActivated.connect(self.page_switch_mdi_cb)
self.w.mnb.set_mode('tabs')
else:
self.w.mnb.currentChanged.connect(self.page_switch_cb)
# readout
if self.settings.get('share_readout', True):
self.readout = self.build_readout()
self.add_callback('field-info', self.readout_cb, self.readout, None)
rw = self.readout.get_widget()
# one level deeper to the native widget in gw.Readout
rw = rw.get_widget()
self.w.vbox.addWidget(rw, stretch=0)
# bottom buttons
plw = QtGui.QWidget()
hbox = QtGui.QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
hbox.setSpacing(2)
plw.setLayout(hbox)
cbox1 = QtHelp.ComboBox()
self.w.channel = cbox1
cbox1.setToolTip("Select a channel")
cbox1.activated.connect(self.channel_select_cb)
hbox.addWidget(cbox1, stretch=0)
opmenu = QtGui.QMenu()
self.w.operation = opmenu
btn = QtGui.QPushButton("Operation")
btn.clicked.connect(self.invoke_op_cb)
btn.setToolTip("Invoke operation")
if parent is not None:
parent = parent.get_widget()
self.widget = QtGui.QDialog(parent)
self.widget.setModal(modal)
vbox = QtGui.QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
self.widget.setLayout(vbox)
TopLevelMixin.__init__(self, title=title)
self.content = VBox()
vbox.addWidget(self.content.get_widget(), stretch=1)
if len(buttons) > 0:
hbox_w = QtGui.QWidget()
hbox = QtGui.QHBoxLayout()
hbox_w.setLayout(hbox)
for name, val in buttons:
btn = QtGui.QPushButton(name)
def cb(val):
return lambda: self._cb_redirect(val)
btn.clicked.connect(cb(val))
hbox.addWidget(btn, stretch=0)
vbox.addWidget(hbox_w, stretch=0)
# self.widget.closeEvent = lambda event: self.delete()
self.enable_callback('activated')
def _create_info_window(self):
sw = QtGui.QScrollArea()
widget = QtGui.QWidget()
vbox = QtGui.QVBoxLayout()
vbox.setContentsMargins(2, 2, 2, 2)
widget.setLayout(vbox)
captions = (('Name', 'label'), ('Object', 'label'),
('X', 'label'), ('Y', 'label'), ('Value', 'label'),
('RA', 'label'), ('DEC', 'label'),
('Equinox', 'label'), ('Dimensions', 'label'),
#('Slices', 'label', 'MultiDim', 'button'),
('Min', 'label'), ('Max', 'label'),
('Zoom', 'label'),
('Cut Low', 'xlabel', '@Cut Low', 'entry'),
('Cut High', 'xlabel', '@Cut High', 'entry'),
('Auto Levels', 'button', 'Cut Levels', 'button'),
('Cut New', 'label'), ('Zoom New', 'label'),
('Preferences', 'button'),
# Add matplotlib buttons
hbox = QtGui.QHBoxLayout()
hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))
wgetimg = QtGui.QPushButton("Get Data")
wgetimg.clicked.connect(self.get_image)
wgetrgb = QtGui.QPushButton("Get RGB")
wgetrgb.clicked.connect(self.get_rgb_image)
#wquit = QtGui.QPushButton("Quit")
#wquit.clicked.connect(self.close)
hbox.addStretch(1)
for w in (wgetimg, wgetrgb):
hbox.addWidget(w, stretch=0)
hw = QtGui.QWidget()
hw.setLayout(hbox)
layout.addWidget(hw, stretch=0)
vbox2.setLayout(layout)
vbox = QtGui.QVBoxLayout()
vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2))
vbox.setSpacing(1)
w = QtGui.QWidget()
layout = QtGui.QHBoxLayout()
layout.addWidget(vbox1, stretch=1.0)
layout.addWidget(vbox2, stretch=1.0)
w.setLayout(layout)
vbox.addWidget(w, stretch=1)
tg.configure(200, 200)
tg.enable_autozoom('on')
tg.set_autocut_params('zscale')
tg.enable_autocuts('override')
tg.enable_auto_orient(True)
tg.defer_redraw = False
tg.set_bg(0.7, 0.7, 0.7)
self.thumb_generator = tg
sw = MyScrollArea()
sw.setWidgetResizable(True)
#sw.setEnabled(True)
sw.thumbs_cb = self.thumbpane_resized_cb
# Create thumbnails pane
widget = QtGui.QWidget()
vbox = QtGui.QGridLayout()
vbox.setContentsMargins(4, 4, 4, 4)
vbox.setSpacing(14)
widget.setLayout(vbox)
self.w.thumbs = vbox
self.w.thumbs_w = widget
#widget.show()
sw.setWidget(widget)
self.w.thumbs_scroll = sw
#self.w.thumbs_scroll.connect("size_allocate", self.thumbpane_resized_cb)
# TODO: should this even have it's own scrolled window?
cw = container.get_widget()
cw.addWidget(sw, stretch=1)
sw.show()
wclear.clicked.connect(self.clear_canvas)
wopen = QtGui.QPushButton("Open File")
wopen.clicked.connect(self.open_file)
wquit = QtGui.QPushButton("Quit")
wquit.clicked.connect(self.quit)
hbox.addStretch(1)
for w in (wopen, wdrawtype, wdrawcolor, wfill,
QtGui.QLabel('Alpha:'), walpha, wclear, wquit):
hbox.addWidget(w, stretch=0)
hw = QtGui.QWidget()
hw.setLayout(hbox)
vbox.addWidget(hw, stretch=0)
vw = QtGui.QWidget()
self.setCentralWidget(vw)
vw.setLayout(vbox)
def __init__(self, title=''):
super(Expander, self).__init__()
# Qt doesn't seem to like it (segfault) if we actually construct
# these icons in the class variable declarations
if Expander.r_arrow is None:
Expander.r_arrow = QtHelp.get_icon(
os.path.join(icondir, 'triangle-right-48.png'), size=(12, 12))
if Expander.d_arrow is None:
Expander.d_arrow = QtHelp.get_icon(
os.path.join(icondir, 'triangle-down-48.png'), size=(12, 12))
self.widget = QtGui.QWidget()
vbox = QtGui.QVBoxLayout()
vbox.setContentsMargins(0, 0, 0, 0)
vbox.setSpacing(0)
self.layout = vbox
self.toggle = QtGui.QPushButton(Expander.r_arrow, title)
self.toggle.setStyleSheet(Expander.widget_style)
# self.toggle.setCheckable(True)
self.toggle.clicked.connect(self._toggle_widget)
vbox.addWidget(self.toggle, stretch=0)
self.widget.setLayout(vbox)
fi.ui_set_active(True)
self.fitsimage = fi
fi.show_color_bar(True)
# enable various key and mouse controlled actions
bd = fi.get_bindings()
bd.enable_all(True)
self.cp_tag = 'compass'
# pack widget into layout
gingaw = fi.get_widget()
gingaw.resize(wd, ht)
vbox1 = QtGui.QWidget()
layout = QtGui.QVBoxLayout()
layout.addWidget(gingaw, stretch=1)
self.cm = cmap.get_cmap('gray')
self.im = imap.get_imap('ramp')
# color map selection widget
wcmap = QtGui.QComboBox()
for name in self.cmaps:
wcmap.addItem(name)
index = self.cmaps.index('gray')
wcmap.setCurrentIndex(index)
wcmap.activated.connect(self.set_cmap_cb)
self.wcmap = wcmap
# intensity map selection widget