Created
April 9, 2018 18:27
-
-
Save altendky/686b966f8b0616c9e1a68f0bcd80ac7d to your computer and use it in GitHub Desktop.
ImageBrowser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Form implementation generated from reading ui file '/Users/epi/Desktop/ImageBrowser/qtui/redox_ui.ui' | |
# | |
# Created by: PyQt5 UI code generator 5.10.1 | |
# | |
# WARNING! All changes made in this file will be lost! | |
from PyQt5 import QtCore, QtGui, QtWidgets | |
class Ui_MainWindow(object): | |
def setupUi(self, MainWindow): | |
MainWindow.setObjectName("MainWindow") | |
MainWindow.resize(1069, 864) | |
self.centralwidget = QtWidgets.QWidget(MainWindow) | |
self.centralwidget.setObjectName("centralwidget") | |
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget) | |
self.verticalLayout.setObjectName("verticalLayout") | |
self.scrollArea_3 = QtWidgets.QScrollArea(self.centralwidget) | |
self.scrollArea_3.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) | |
self.scrollArea_3.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) | |
self.scrollArea_3.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents) | |
self.scrollArea_3.setWidgetResizable(True) | |
self.scrollArea_3.setObjectName("scrollArea_3") | |
self.scrollAreaWidgetContents_4 = QtWidgets.QWidget() | |
self.scrollAreaWidgetContents_4.setGeometry(QtCore.QRect(0, 0, 1027, 653)) | |
self.scrollAreaWidgetContents_4.setObjectName("scrollAreaWidgetContents_4") | |
self.verticalLayout_12 = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents_4) | |
self.verticalLayout_12.setSizeConstraint(QtWidgets.QLayout.SetNoConstraint) | |
self.verticalLayout_12.setObjectName("verticalLayout_12") | |
self.verticalLayout_13 = QtWidgets.QVBoxLayout() | |
self.verticalLayout_13.setSizeConstraint(QtWidgets.QLayout.SetNoConstraint) | |
self.verticalLayout_13.setObjectName("verticalLayout_13") | |
self.verticalLayout_12.addLayout(self.verticalLayout_13) | |
self.scrollArea_3.setWidget(self.scrollAreaWidgetContents_4) | |
self.verticalLayout.addWidget(self.scrollArea_3) | |
self.groupBox_6 = QtWidgets.QGroupBox(self.centralwidget) | |
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed) | |
sizePolicy.setHorizontalStretch(0) | |
sizePolicy.setVerticalStretch(0) | |
sizePolicy.setHeightForWidth(self.groupBox_6.sizePolicy().hasHeightForWidth()) | |
self.groupBox_6.setSizePolicy(sizePolicy) | |
self.groupBox_6.setTitle("") | |
self.groupBox_6.setObjectName("groupBox_6") | |
self.gridLayout_8 = QtWidgets.QGridLayout(self.groupBox_6) | |
self.gridLayout_8.setObjectName("gridLayout_8") | |
self.verticalLayout_14 = QtWidgets.QVBoxLayout() | |
self.verticalLayout_14.setObjectName("verticalLayout_14") | |
self.horizontalLayout_11 = QtWidgets.QHBoxLayout() | |
self.horizontalLayout_11.setObjectName("horizontalLayout_11") | |
self.label_3 = QtWidgets.QLabel(self.groupBox_6) | |
self.label_3.setObjectName("label_3") | |
self.horizontalLayout_11.addWidget(self.label_3) | |
self.ZoomStepSlider = QtWidgets.QSlider(self.groupBox_6) | |
self.ZoomStepSlider.setMaximum(200) | |
self.ZoomStepSlider.setProperty("value", 50) | |
self.ZoomStepSlider.setOrientation(QtCore.Qt.Horizontal) | |
self.ZoomStepSlider.setTickPosition(QtWidgets.QSlider.TicksBelow) | |
self.ZoomStepSlider.setTickInterval(10) | |
self.ZoomStepSlider.setObjectName("ZoomStepSlider") | |
self.horizontalLayout_11.addWidget(self.ZoomStepSlider) | |
self.ZoomStepspinBox = QtWidgets.QSpinBox(self.groupBox_6) | |
self.ZoomStepspinBox.setMaximum(200) | |
self.ZoomStepspinBox.setProperty("value", 50) | |
self.ZoomStepspinBox.setObjectName("ZoomStepspinBox") | |
self.horizontalLayout_11.addWidget(self.ZoomStepspinBox) | |
self.verticalLayout_14.addLayout(self.horizontalLayout_11) | |
self.horizontalLayout_12 = QtWidgets.QHBoxLayout() | |
self.horizontalLayout_12.setObjectName("horizontalLayout_12") | |
self.label_4 = QtWidgets.QLabel(self.groupBox_6) | |
self.label_4.setObjectName("label_4") | |
self.horizontalLayout_12.addWidget(self.label_4) | |
self.ImageIndexSlider = QtWidgets.QSlider(self.groupBox_6) | |
self.ImageIndexSlider.setProperty("value", 0) | |
self.ImageIndexSlider.setSliderPosition(0) | |
self.ImageIndexSlider.setOrientation(QtCore.Qt.Horizontal) | |
self.ImageIndexSlider.setTickPosition(QtWidgets.QSlider.TicksBelow) | |
self.ImageIndexSlider.setTickInterval(500) | |
self.ImageIndexSlider.setObjectName("ImageIndexSlider") | |
self.horizontalLayout_12.addWidget(self.ImageIndexSlider) | |
self.ImageIndexspinBox = QtWidgets.QSpinBox(self.groupBox_6) | |
self.ImageIndexspinBox.setMinimum(0) | |
self.ImageIndexspinBox.setProperty("value", 0) | |
self.ImageIndexspinBox.setObjectName("ImageIndexspinBox") | |
self.horizontalLayout_12.addWidget(self.ImageIndexspinBox) | |
self.horizontalLayout_13 = QtWidgets.QHBoxLayout() | |
self.horizontalLayout_13.setObjectName("horizontalLayout_13") | |
self.ImageStepspinBox = QtWidgets.QSpinBox(self.groupBox_6) | |
self.ImageStepspinBox.setMinimum(1) | |
self.ImageStepspinBox.setMaximum(200) | |
self.ImageStepspinBox.setObjectName("ImageStepspinBox") | |
self.horizontalLayout_13.addWidget(self.ImageStepspinBox) | |
self.rwd = QtWidgets.QPushButton(self.groupBox_6) | |
self.rwd.setAutoRepeat(True) | |
self.rwd.setAutoRepeatDelay(500) | |
self.rwd.setObjectName("rwd") | |
self.horizontalLayout_13.addWidget(self.rwd) | |
self.fwd = QtWidgets.QPushButton(self.groupBox_6) | |
self.fwd.setFocusPolicy(QtCore.Qt.ClickFocus) | |
self.fwd.setAutoRepeat(True) | |
self.fwd.setAutoRepeatDelay(500) | |
self.fwd.setAutoDefault(False) | |
self.fwd.setObjectName("fwd") | |
self.horizontalLayout_13.addWidget(self.fwd) | |
self.horizontalLayout_12.addLayout(self.horizontalLayout_13) | |
self.verticalLayout_14.addLayout(self.horizontalLayout_12) | |
self.gridLayout_8.addLayout(self.verticalLayout_14, 0, 0, 1, 1) | |
self.verticalLayout.addWidget(self.groupBox_6) | |
MainWindow.setCentralWidget(self.centralwidget) | |
self.menubar = QtWidgets.QMenuBar(MainWindow) | |
self.menubar.setGeometry(QtCore.QRect(0, 0, 1069, 22)) | |
self.menubar.setObjectName("menubar") | |
self.menuSettings = QtWidgets.QMenu(self.menubar) | |
self.menuSettings.setObjectName("menuSettings") | |
MainWindow.setMenuBar(self.menubar) | |
self.statusbar = QtWidgets.QStatusBar(MainWindow) | |
self.statusbar.setObjectName("statusbar") | |
MainWindow.setStatusBar(self.statusbar) | |
self.actionWizard = QtWidgets.QAction(MainWindow) | |
self.actionWizard.setObjectName("actionWizard") | |
self.menuSettings.addAction(self.actionWizard) | |
self.menubar.addAction(self.menuSettings.menuAction()) | |
self.retranslateUi(MainWindow) | |
QtCore.QMetaObject.connectSlotsByName(MainWindow) | |
def retranslateUi(self, MainWindow): | |
_translate = QtCore.QCoreApplication.translate | |
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) | |
self.label_3.setText(_translate("MainWindow", "Zoom")) | |
self.label_4.setText(_translate("MainWindow", "Image switch")) | |
self.rwd.setText(_translate("MainWindow", "<<<")) | |
self.fwd.setText(_translate("MainWindow", ">>>")) | |
self.menuSettings.setTitle(_translate("MainWindow", "Settings")) | |
self.actionWizard.setText(_translate("MainWindow", "Wizard")) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from PyQt5 import QtWidgets | |
from htmap_ui import Ui_MainWindow | |
class HtMapGui(QtWidgets.QMainWindow, Ui_MainWindow): | |
def __init__(self): | |
QtWidgets.QMainWindow.__init__(self) | |
self.setupUi(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python36 | |
import sys | |
import os | |
from PyQt5.QtCore import * | |
from PyQt5.QtGui import * | |
from PyQt5.QtWidgets import * | |
from htmapui import HtMapGui | |
#from qimage import QImageWidget | |
class QImageWidget(QWidget): | |
def __init__(self, pixmap, width, height, parent=None): | |
super().__init__(parent) | |
#self.pixmap = QtGui.QPixmap('201503.20150619.200707736.246017.jpg') | |
self.pixmap = None | |
self.height_per_width = None | |
self.width = width | |
self.height = height | |
self.set_pixmap(pixmap) | |
def set_pixmap(self, pixmap): | |
self.pixmap = pixmap | |
self.height_per_width = self.pixmap.height() / self.pixmap.width() | |
def paintEvent(self, event): | |
painter = QPainter(self) | |
''' | |
current_height_per_width = self.height() / self.width() | |
if current_height_per_width > self.height_per_width: | |
width = self.width() | |
height = width * self.height_per_width | |
top = (self.height() - height) / 2 | |
left = 0 | |
else: | |
height = self.height() | |
width = height / self.height_per_width | |
left = (self.width() - width) / 2 | |
top = 0 | |
''' | |
left = 0 | |
top = 0 | |
#target = QRect(left, top, width, height) | |
target = QRect(left, top, self.width, self.height) | |
painter.drawPixmap(target, self.pixmap, self.pixmap.rect()) | |
def hasHeightForWidth(self): | |
return True | |
def heightForWidth(self, w): | |
return w * self.height_per_width | |
class MapDisplay(QObject): | |
def __init__(self): | |
super().__init__() | |
self.image=QLabel() | |
self.initUI() | |
def initUI(self): | |
self.w = HtMapGui() | |
self.imagelist = [] | |
self.imageindex = 1 | |
self.ZoomStepValue = 50 | |
self.w.fwd.clicked.connect(self.increaseimageindex) | |
self.w.fwd.clicked.connect(self.updatespinbox) | |
#self.w.scrollArea_3.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) | |
#self.w.scrollArea_3.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) | |
#self.w.fwd.clicked.connect(self.addImage) | |
self.w.rwd.clicked.connect(self.decreaseimageindex) | |
#self.w.rwd.clicked.connect(self.addImage) | |
# ZOOM | |
self.w.ZoomStepSlider.valueChanged.connect(self.setValueZoomStepspinBox) | |
#self.w.ZoomStepSlider.valueChanged.connect(self.addImage) | |
self.w.ZoomStepSlider.valueChanged.connect(self.addImage2) | |
self.w.ZoomStepspinBox.valueChanged.connect(self.setValueZoomStepSlider) | |
#self.w.ZoomStepspinBox.valueChanged.connect(self.printFunction) | |
self.w.ZoomStepSlider.valueChanged.connect(self.setValue) | |
self.w.ZoomStepspinBox.valueChanged.connect(self.setValue) | |
# Image Index | |
self.w.ImageIndexSlider.valueChanged.connect(self.setValueImageIndexspinBox) | |
#self.w.ImageIndexSlider.valueChanged.connect(self.printFunction) | |
self.w.ImageIndexspinBox.valueChanged.connect(self.setValueImageIndexSlider) | |
self.w.ImageStepspinBox.valueChanged.connect(self.setImageIndexStepValue) | |
#self.w.ImageIndexSlider.valueChanged.connect(self.addImage) | |
self.w.ImageIndexSlider.valueChanged.connect(self.addImage2) | |
# hardcoded image file and metadata | |
self.getImageDir_hard() | |
self.w.show() | |
def getImageDir_hard(self): | |
cwd = os.getcwd() #os.path.realpath(os.path.abspath(__file__)) | |
self.dirname = os.path.join(cwd,'images') | |
if self.dirname: | |
self.imagelist = os.listdir(self.dirname) | |
self.w.ImageIndexspinBox.setMaximum(len(self.imagelist) - 1) | |
self.w.ImageIndexSlider.setMaximum(len(self.imagelist) - 1) | |
def updatespinbox(self): | |
self.w.ImageIndexspinBox.setValue(self.imageindex) | |
self.w.ImageIndexSlider.update() | |
self.w.ImageIndexspinBox.update() | |
print('fwd pressed') | |
def decreaseimageindex(self): | |
self.imageindex=self.imageindex-self.w.ImageStepspinBox.value() | |
self.w.ImageIndexSlider.setValue(self.imageindex) | |
self.w.ImageIndexspinBox.setValue(self.imageindex) | |
def increaseimageindex(self): | |
self.imageindex = self.imageindex+self.w.ImageStepspinBox.value() | |
self.w.ImageIndexSlider.setValue(self.imageindex) | |
self.w.ImageIndexspinBox.setValue(self.imageindex) | |
def addImage2(self): | |
#self.w.verticalLayout_13.removeWidget(self.image) | |
self.image.setParent(None) | |
self.pixmap = QPixmap(os.path.join(self.dirname, self.imagelist[self.imageindex])) | |
width=self.pixmap.width()*(self.ZoomStepValue/100.) | |
height=self.pixmap.height()*(self.ZoomStepValue/100.) | |
#self.pixmap = self.pixmap.scaled(width, height, Qt.KeepAspectRatio) | |
self.image = QImageWidget(self.pixmap, width, height) | |
self.w.verticalLayout_13.addWidget(self.image) | |
def addImage(self): | |
#self.w.image.clear() | |
#self.w.image.setGeometry(QRect(0, 0, 1360, 1024)) | |
if any(self.imagelist) is not None: | |
self.pixmap = QPixmap(os.path.join(self.dirname, self.imagelist[self.imageindex])) | |
print('orig size:', self.pixmap.width(), self.pixmap.height()) | |
width=self.pixmap.width()*(self.ZoomStepValue/100.) | |
height=self.pixmap.height()*(self.ZoomStepValue/100.) | |
self.pixmap = self.pixmap.scaled(width, height, Qt.KeepAspectRatio) | |
print('height', self.w.image.height()) | |
print('width', self.w.image.width()) | |
print('heightMM', self.w.image.heightMM()) | |
print('widthMM', self.w.image.widthMM()) | |
#self.w.image.clear() | |
self.w.image.setGeometry(QRect(0, 0, width, height)) | |
#self.w.image.setPixmap(self.pixmap) | |
self.w.image.setPixmap(self.pixmap .scaled( | |
self.w.image.size(), | |
Qt.KeepAspectRatio, | |
Qt.SmoothTransformation)) | |
else: | |
print('both image path not be set') | |
print(' --- ') | |
def setValueZoomStepspinBox(self, z): | |
self.ZoomStepValue = int(z) | |
#self.w.ZoomStepspinBox.setRange(1, 100) | |
self.w.ZoomStepspinBox.setSingleStep(1) | |
self.w.ZoomStepspinBox.setValue(self.ZoomStepValue) | |
def setValueZoomStepSlider(self, z): | |
self.ZoomStepValue = int(z) | |
self.w.ZoomStepSlider.setMinimum(1) | |
#self.w.ZoomStepSlider.setMaximum(100) | |
self.w.ZoomStepSlider.setValue(self.ZoomStepValue) | |
def setValue(self, v): | |
self.Value = v | |
def setValueImageIndexspinBox(self, z): | |
self.imageindex = int(z) | |
self.w.ImageIndexspinBox.setSingleStep(self.w.ImageStepspinBox.value()) | |
self.w.ImageIndexspinBox.setValue(self.imageindex) | |
def setValueImageIndexSlider(self, z): | |
self.imageindex = int(z) | |
self.w.ImageIndexSlider.setSingleStep(self.w.ImageStepspinBox.value()) | |
self.w.ImageIndexSlider.setValue(self.imageindex) | |
def setImageIndexStepValue(self): | |
self.w.ImageIndexspinBox.setSingleStep(self.w.ImageStepspinBox.value()) | |
self.w.ImageIndexSlider.setSingleStep(self.w.ImageStepspinBox.value()) | |
if __name__ == "__main__": | |
import sys | |
app = QApplication(sys.argv) | |
app.processEvents() | |
p = MapDisplay() | |
p.__init__() | |
sys.exit(app.exec_()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment