Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added label support to the pds viewer. This is an initial commit. More features will be added to the label viewer. #4

Merged
merged 2 commits into from
May 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
*.py[cod]

._*
# C extensions
*.so

# Packages
*.egg
*.egg-info
.nfs*
dist
build
eggs
Expand Down
11 changes: 10 additions & 1 deletion pdsview/PDSImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ def __init__(self, data_np=None, metadata=None, logger=None):
def load_file(self, filepath):
self.logger.debug("Loading file '%s' ..." % (filepath))
pds_image = gdal_pds.PDSImage(filepath)
self.set_data(pds_image.image)
self.pds_image = pds_image
self.set_data(pds_image.image)
with open(filepath) as f:
labelview = []
for lineno, line in enumerate(f):
line = line.rstrip()
if line.strip() == 'END':
break
labelview.append(line)
pds_image.labelview = labelview
66 changes: 66 additions & 0 deletions pdsview/label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from ginga.qtw.QtHelp import QtGui, QtCore
import text_finderUI


class LabelView(QtGui.QWidget):
def __init__(self, image_label):
QtGui.QWidget.__init__(self, None)
print("Label Show")
self.textwindow = QtGui.QVBoxLayout()
self.textwindow.setContentsMargins(QtCore.QMargins(2, 2, 2, 2))
self.buttonwindow = QtGui.QHBoxLayout()
self.labelwindowlayout = QtGui.QHBoxLayout()
self.buttonwindow.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))

self.textwidget = QtGui.QWidget()
self.textwidget.setWindowTitle("Label")
self.textwidget.resize(640, 620)
self.labelPT = QtGui.QTextEdit()
self.labelPT.setReadOnly(True)
self.font = QtGui.QFont("Monaco")
self.font.setPointSize(12)

self.image_label = image_label
self.labelPT.setFont(self.font)
self.textwindow.addWidget(self.labelPT, stretch=0)

findButton = QtGui.QPushButton("Find")
findButton.clicked.connect(self.find)
cancelbutton = QtGui.QPushButton("Cancel")
cancelbutton.clicked.connect(self.cancel)

for button in (findButton, cancelbutton):
self.buttonwindow.addWidget(button, stretch=0)

self.buttonwidget = QtGui.QWidget()
self.buttonwidget.setLayout(self.buttonwindow)
self.textwindow.addWidget(self.buttonwidget, stretch=0)
self.textwidget.setLayout(self.textwindow)

self.label_show()

def label_show(self):
if self.image_label == None:
self.labelPT.setText("Please Open an Image First !")
else:
self.labelPT.setText('\n'.join(self.image_label))
# labelPT.setText(json.dumps(image_label, indent=4))
self.textwidget.setLayout(self.textwindow)
self.textwidget.setMinimumWidth(50)
self.textwidget.show()
self.textwidget.raise_()
self.textwidget.activateWindow()
labelview_window = self.textwidget
return labelview_window

def find(self):
self.lastMatch = None
self.finderUI()

def finderUI(self):
mw = text_finderUI.LabelSearch()
self.labelwindowlayout.addWidget(mw, stretch=0)
print mw.search()

def cancel(self):
self.deleteLater()
39 changes: 24 additions & 15 deletions pdsview/pdsview.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
# This is open-source software licensed under a BSD license.
# Please see the file LICENSE.txt for details.
#
import sys, os
import sys
import logging
import PDSImage
import label

from ginga.qtw.QtHelp import QtGui, QtCore
from ginga.qtw.ImageViewCanvasQt import ImageViewCanvas
Expand All @@ -34,58 +35,68 @@ def __init__(self, logger):
self.fitsimage = fi

bd = fi.get_bindings()
bd.enable_pan(True)
bd.enable_zoom(True)
bd.enable_cuts(True)
bd.enable_flip(True)
bd.enable_all(True)

w = fi.get_widget()
w.resize(512, 512)
w.resize(768, 768)

vbox = QtGui.QVBoxLayout()
vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2))
vbox.setSpacing(1)
vbox.addWidget(w, stretch=1)

hbox = QtGui.QHBoxLayout()
self.hboxlayout = QtGui.QHBoxLayout()
hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))

wopen = QtGui.QPushButton("Open File")
wopen.clicked.connect(self.open_file)
wlabel = QtGui.QPushButton("Label")
wlabel.clicked.connect(self.label)
wquit = QtGui.QPushButton("Quit")
wquit.clicked.connect(self.quit)

hbox.addStretch(1)
for w in (wopen, wquit):
for w in (wopen, wlabel, wquit):
hbox.addWidget(w, stretch=0)

hw = QtGui.QWidget()
hw.setLayout(hbox)
vbox.addWidget(hw, stretch=0)
self.vbox = vbox
self.hbox = hbox
self.w = w

vw = QtGui.QWidget()
self.setCentralWidget(vw)
vw.setLayout(vbox)

def load_file(self, filepath):
# image = AstroImage.AstroImage(logger=self.logger)
# filepath = '1f345867992effb0j3p1212l0m1.img'
# print(filepath)
global image
image = PDSImage.PDSImage(logger=self.logger)
image.load_file(filepath)
self.fitsimage.set_image(image)
print('File_Loaded')
# print(image)
self.setWindowTitle(filepath)

def label(self):
try:
label_data = image.pds_image.labelview
except NameError:
label_data = None
mw = label.LabelView(label_data)
self.hboxlayout.addWidget(mw, stretch=0)

def find(self):
print("Search")

def open_file(self):
res = QtGui.QFileDialog.getOpenFileName(self, "Open IMG file",
".", "IMG files (*.IMG)")
if isinstance(res, tuple):
fileName = res[0]
else:
fileName = str(res)
# fileName = '1f345867992effb0j3p1212l0m1.img'
self.load_file(fileName)

def drop_file(self, fitsimage, paths):
Expand All @@ -109,7 +120,7 @@ def main():
logger.addHandler(stderrHdlr)

w = FitsViewer(logger)
w.resize(524, 540)
w.resize(780, 770)
w.show()
app.setActiveWindow(w)
w.raise_()
Expand All @@ -118,5 +129,3 @@ def main():

if __name__ == '__main__':
main()

# END
50 changes: 50 additions & 0 deletions pdsview/text_finderUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from ginga.qtw.QtHelp import QtGui, QtCore


class LabelSearch(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self, None)
print("Text Search")
self.textwindow = QtGui.QVBoxLayout()
self.textwindow.setContentsMargins(QtCore.QMargins(2, 2, 2, 2))
self.buttonwindow = QtGui.QHBoxLayout()
self.labelwindowlayout = QtGui.QHBoxLayout()
self.buttonwindow.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))

self.textwidget = QtGui.QWidget()
self.textwidget.setWindowTitle("Search Window")
self.textwidget.resize(250, 70)
self.findField = QtGui.QTextEdit(self)
self.findField.resize(200, 50)
self.font = QtGui.QFont("Monaco")
self.font.setPointSize(12)
self.searchButton = QtGui.QPushButton("Search")
self.searchButton.clicked.connect(self.search)
self.cancelButton = QtGui.QPushButton("Cancel")
self.cancelButton.clicked.connect(self.cancel)

self.findField.setFont(self.font)
self.textwindow.addWidget(self.findField, stretch=0)
self.buttonwindow.addWidget(self.searchButton, stretch=0)
self.buttonwindow.addWidget(self.cancelButton, stretch=0)

self.buttonwidget = QtGui.QWidget()
self.buttonwidget.setLayout(self.buttonwindow)
self.textwindow.addWidget(self.buttonwidget, stretch=0)
self.textwidget.setLayout(self.textwindow)
self.textwidget.setMinimumWidth(50)
self.textwidget.show()
self.textwidget.raise_()
self.textwidget.activateWindow()

def search(self):
# Here, we get the value printed in the findField of the "Search Window"
# TODO:
# Set Callback method or Find a way to reflect this value back to the "label.py"
# Once we populate "label.py" with the updated search-string, one can take a reference from:
# https://www.binpress.com/tutorial/building-a-text-editor-with-pyqt-part-3/147
print self.findField.toPlainText()
return self.findField.toPlainText()

def cancel(self):
self.deleteLater()