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_gui(self, container):
sw = QtGui.QScrollArea()
twidget = QtHelp.VBox()
sp = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
QtGui.QSizePolicy.Fixed)
twidget.setSizePolicy(sp)
vbox1 = twidget.layout()
vbox1.setContentsMargins(4, 4, 4, 4)
vbox1.setSpacing(2)
sw.setWidgetResizable(True)
sw.setWidget(twidget)
msgFont = self.fv.getFont("sansFont", 14)
tw = QtGui.QLabel()
tw.setFont(msgFont)
tw.setWordWrap(True)
self.tw = tw
path = str(self.entry.text()).strip()
self.browse(path)
def save_as_cb(self):
path = str(self.entry2.text()).strip()
if not path.startswith('/'):
path = os.path.join(self.curpath, path)
image = self.fitsimage.get_image()
self.fv.error_wrap(image.save_as_file, path)
def __str__(self):
return 'fbrowser'
class DragTable(QtGui.QTableWidget):
# This class exists only to let us drag and drop files from the
# file pane into the Ginga widget.
def __init__(self, parent=None, plugin=None):
super(DragTable, self).__init__(parent)
self.setDragEnabled(True)
self.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.plugin = plugin
def dragEnterEvent(self, event):
if event.mimeData().hasFormat("text/uri-list"):
event.setDropAction(QtCore.Qt.MoveAction)
event.accept()
else:
event.ignore()
return
# only consider this a drag if user has moved a certain amount
# away from the press position
if ((event.pos() - self.drag_start_position).manhattanLength() <
QApplication.startDragDistance()):
return
# prepare formatted possibilities on drop
mimeData = QtCore.QMimeData()
chname, name, path = self._dragdata
data = "%s||%s||%s" % (chname, name, path)
mimeData.setData("text/thumb", data)
mimeData.setData("text/plain", path)
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
drag.setPixmap(self.pixmap())
drag.setHotSpot(event.pos() - self.rect().topLeft())
self.event_type = 'drag'
#dropAction = drag.start(QtCore.Qt.CopyAction | QtCore.Qt.MoveAction)
def __init__(self, rows=1, columns=1):
super(GridBox, self).__init__()
w = QtGui.QWidget()
layout = QtGui.QGridLayout()
w.setLayout(layout)
self.widget = w
def __init__(self, parent=None, plugin=None):
super(DragTable, self).__init__(parent)
self.setDragEnabled(True)
self.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.plugin = plugin
vbox = QtGui.QVBoxLayout()
vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2))
vbox.setSpacing(1)
vbox.addWidget(w, stretch=1)
self.readout = QtGui.QLabel("")
vbox.addWidget(self.readout, stretch=0,
alignment=QtCore.Qt.AlignCenter)
hbox = QtGui.QHBoxLayout()
hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))
wopen = QtGui.QPushButton("Open File")
wopen.clicked.connect(self.open_file)
wquit = QtGui.QPushButton("Quit")
wquit.clicked.connect(self.close)
hbox.addStretch(1)
for w in (wopen, 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)
fi.configure(512, 512)
def __init__(self):
super(StatusBar, self).__init__()
sbar = QtGui.QStatusBar()
self.widget = sbar
def set_tab_position(self, tabpos):
w = self.widget
if tabpos == 'top':
w.setTabPosition(QtGui.QTabWidget.North)
elif tabpos == 'bottom':
w.setTabPosition(QtGui.QTabWidget.South)
elif tabpos == 'left':
w.setTabPosition(QtGui.QTabWidget.West)
elif tabpos == 'right':
w.setTabPosition(QtGui.QTabWidget.East)
def add_dialogs(self):
filesel = QtGui.QFileDialog(self.w.root, directory=os.curdir)
#filesel.setFileMode(QtGui.QFileDialog.ExistingFile)
filesel.setViewMode(QtGui.QFileDialog.Detail)
self.filesel = filesel
Usage:
example1_mpl.py [fits file]
"""
import sys
from matplotlib.figure import Figure
from ginga.qtw.QtHelp import QtGui, QtCore
from ginga.mplw.ImageViewCanvasMpl import ImageViewCanvas
from ginga.mplw.FigureCanvasQt import FigureCanvas
from ginga.misc import log
from ginga.util.loader import load_data
class FitsViewer(QtGui.QMainWindow):
def __init__(self, logger):
super(FitsViewer, self).__init__()
self.logger = logger
fig = Figure()
w = FigureCanvas(fig)
fi = ImageViewCanvas(logger=self.logger)
fi.enable_autocuts('on')
fi.set_autocut_params('zscale')
fi.enable_auto_orient(True)
fi.enable_autozoom('on')
#fi.set_callback('drag-drop', self.drop_file)
fi.set_callback('none-move', self.motion)
fi.set_bg(0.2, 0.2, 0.2)