diff --git a/.pydevproject b/.pydevproject
index ca7ee8f..29cb7bf 100644
--- a/.pydevproject
+++ b/.pydevproject
@@ -4,5 +4,5 @@
/${PROJECT_DIR_NAME}/src
python 3.0
-Default
+Python3
diff --git a/src/FlashAir/ImageViewer.py b/src/FlashAir/ImageViewer.py
index 75fa5a3..0658923 100644
--- a/src/FlashAir/ImageViewer.py
+++ b/src/FlashAir/ImageViewer.py
@@ -47,7 +47,41 @@
from FlashAir import card
import threading
import time
-
+from QtGui import QScrollArea
+
+
+
+
+
+class MyLabel(QtGui.QLabel):
+
+ image=QtGui.QImage();
+ def __init__(self, parent=None):
+ QtGui.QLabel.__init__(self, parent)
+
+ def setImage(self, image):
+ self.image=image;
+ self.setPixmap(QtGui.QPixmap.fromImage(self.image).scaled(self.size(), QtCore.Qt.KeepAspectRatio))
+ pass
+
+ def resizeEvent(self, event):
+ self.setPixmap(QtGui.QPixmap.fromImage(self.image).scaled(event.size(), QtCore.Qt.KeepAspectRatio))
+ pass
+
+ def imageSize(self):
+ return self.image.size()
+
+
+
+class ScrollAreaEventHandler:
+ def handler(self, event, scrollarea):
+ modifiers = QtGui.QApplication.keyboardModifiers()
+ if modifiers != QtCore.Qt.ControlModifier:
+ QScrollArea.wheelEvent(scrollarea, event)
+ else:
+ event.ignore()
+ pass
+
class ImageViewer(QtGui.QMainWindow):
run=False;
ReceiveThread=0
@@ -59,8 +93,11 @@ class ImageViewer(QtGui.QMainWindow):
folder_local='.'
recursive=False
+ saeh=ScrollAreaEventHandler();
+
+
def __init__(self,ip='192.168.0.1',port=80,timeout=1000,folder_local='.',
- folder_remote='/', instant_run=False, recursive=False):
+ folder_remote='/', instant_run=False, recursive=False, debug_image=None):
super(ImageViewer, self).__init__()
self.folder_local=folder_local
@@ -74,13 +111,15 @@ def __init__(self,ip='192.168.0.1',port=80,timeout=1000,folder_local='.',
self.scaleFactor = 0.0
- self.imageLabel = QtGui.QLabel()
+ self.imageLabel = MyLabel()
self.imageLabel.setBackgroundRole(QtGui.QPalette.Base)
self.imageLabel.setSizePolicy(QtGui.QSizePolicy.Ignored,
QtGui.QSizePolicy.Ignored)
- self.imageLabel.setScaledContents(True)
+
self.scrollArea = QtGui.QScrollArea()
+
+ self.scrollArea.wheelEvent = lambda event: self.saeh.handler(event, self.scrollArea)
self.scrollArea.setBackgroundRole(QtGui.QPalette.Dark)
self.scrollArea.setWidget(self.imageLabel)
self.setCentralWidget(self.scrollArea)
@@ -97,6 +136,12 @@ def __init__(self,ip='192.168.0.1',port=80,timeout=1000,folder_local='.',
self.fitToWindowAct.setEnabled(True)
self.fitToWindowAct.setChecked(True)
+ if(debug_image!=None):
+ image=QtGui.QImage(debug_image)
+ self.emit(QtCore.SIGNAL('load_image(QImage)'), image)
+ return
+
+
if(instant_run):
print("Intant running...")
threading.Thread(target=self.image_get).start()
@@ -129,6 +174,7 @@ def open(self):
"Cannot load %s." % fileName)
return
+
self.imageLabel.setPixmap(QtGui.QPixmap.fromImage(image))
self.scaleFactor = 1.0
@@ -142,7 +188,9 @@ def open(self):
def load_image(self, image):
print("loading image ... ")
if not image.isNull():
- self.imageLabel.setPixmap(QtGui.QPixmap.fromImage(image))
+ self.printAct.setEnabled(True)
+ self.imageLabel.setImage(image)
+
self.fitToWindow()
pass
@@ -170,6 +218,8 @@ def normalSize(self):
def fitToWindow(self):
fitToWindow = self.fitToWindowAct.isChecked()
self.scrollArea.setWidgetResizable(fitToWindow)
+
+
if not fitToWindow:
self.normalSize()
@@ -222,7 +272,7 @@ def createActions(self):
def createMenus(self):
self.fileMenu = QtGui.QMenu("&File", self)
#self.fileMenu.addAction(self.openAct)
- #self.fileMenu.addAction(self.printAct)
+ self.fileMenu.addAction(self.printAct)
self.fileMenu.addSeparator()
self.fileMenu.addAction(self.exitAct)
@@ -247,15 +297,17 @@ def updateActions(self):
self.normalSizeAct.setEnabled(not self.fitToWindowAct.isChecked())
def scaleImage(self, factor):
- self.scaleFactor *= factor
- self.imageLabel.resize(self.scaleFactor * self.imageLabel.pixmap().size())
-
- self.adjustScrollBar(self.scrollArea.horizontalScrollBar(), factor)
- self.adjustScrollBar(self.scrollArea.verticalScrollBar(), factor)
-
- self.zoomInAct.setEnabled(self.scaleFactor < 3.0)
- self.zoomOutAct.setEnabled(self.scaleFactor > 0.333)
-
+ if not self.fitToWindowAct.isChecked():
+ self.scaleFactor *= factor
+
+ self.imageLabel.resize(self.scaleFactor * self.imageLabel.imageSize())
+
+ self.adjustScrollBar(self.scrollArea.horizontalScrollBar(), factor)
+ self.adjustScrollBar(self.scrollArea.verticalScrollBar(), factor)
+
+ self.zoomInAct.setEnabled(self.scaleFactor < 3.0)
+ self.zoomOutAct.setEnabled(self.scaleFactor > 0.333)
+
def adjustScrollBar(self, scrollBar, factor):
scrollBar.setValue(int(factor * scrollBar.value()
+ ((factor - 1) * scrollBar.pageStep()/2)))
@@ -265,4 +317,17 @@ def closeEvent(self, event):
print("Close")
self.runLock.release()
self.run=0
- pass
\ No newline at end of file
+ pass
+
+
+ def wheelEvent(self,event):
+ modifiers = QtGui.QApplication.keyboardModifiers()
+ if modifiers == QtCore.Qt.ControlModifier:
+ if(event.delta() >0):
+ self.zoomOut()
+ else:
+ self.zoomIn()
+ event.accept()
+ else:
+ event.ignore()
+
\ No newline at end of file
diff --git a/src/PyFlashAero.py b/src/PyFlashAero.py
index ad3a3f4..857dae7 100644
--- a/src/PyFlashAero.py
+++ b/src/PyFlashAero.py
@@ -20,7 +20,7 @@ def ImageView(args):
print("imageView")
try:
- from PyQt4x import QtGui
+ from PyQt4 import QtGui
except ImportError:
sys.exit("Using --imageViewer requires PyQt4, which is not installed.")
@@ -30,7 +30,7 @@ def ImageView(args):
port=args.card_uri.port
if(port == None):
port = 80
- imageViewer = ImageViewer.ImageViewer(socket.gethostbyname(args.card_uri.hostname), port, args.timeout, args.folder_local, args.folder_remote, args.instant, args.recursive)
+ imageViewer = ImageViewer.ImageViewer(socket.gethostbyname(args.card_uri.hostname), port, args.timeout, args.folder_local, args.folder_remote, args.instant, args.recursive, args.debug_image)
imageViewer.show()
sys.exit(app.exec_())
@@ -69,15 +69,26 @@ def SyncFolder(args):
const=True, default=False,
help='GUI will start looking for images directly')
+ parser.add_argument('--GUIDebugImage', dest='debug_image', help='path for picture to debug the GUI')
+
args = parser.parse_args()
ip = socket.gethostbyname(args.card_uri.hostname)
if(not os.path.isdir(args.folder_local)):
- print("Given folder(local) does not exist or isn't a folder!")
+ print("Given folder(local) does not exist or isn't a folder!", end='\n', file=sys.stderr)
+ exit(1)
+
+ if((args.instant or args.debug_image!=None) and not args.processing==ImageView):
+ print("Selected GUI option without selecting GUI!", end='\n', file=sys.stderr)
exit(1)
+ if(args.debug_image != None):
+ if(not os.path.isfile(args.debug_image)):
+ print("Debug image file does not exist!", end='\n', file=sys.stderr)
+ exit(1)
+
args.processing(args)
\ No newline at end of file