Skip to content

Commit

Permalink
Merge branch 'release/V1.1.6_b'
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Holl committed Jul 27, 2014
2 parents e312056 + a3e5c44 commit d3fef6f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .pydevproject
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<path>/${PROJECT_DIR_NAME}/src</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 3.0</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Python3</pydev_property>
</pydev_project>
97 changes: 81 additions & 16 deletions src/FlashAir/ImageViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -129,6 +174,7 @@ def open(self):
"Cannot load %s." % fileName)
return


self.imageLabel.setPixmap(QtGui.QPixmap.fromImage(image))
self.scaleFactor = 1.0

Expand All @@ -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

Expand Down Expand Up @@ -170,6 +218,8 @@ def normalSize(self):
def fitToWindow(self):
fitToWindow = self.fitToWindowAct.isChecked()
self.scrollArea.setWidgetResizable(fitToWindow)


if not fitToWindow:
self.normalSize()

Expand Down Expand Up @@ -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)

Expand All @@ -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)))
Expand All @@ -265,4 +317,17 @@ def closeEvent(self, event):
print("Close")
self.runLock.release()
self.run=0
pass
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()

17 changes: 14 additions & 3 deletions src/PyFlashAero.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand All @@ -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_())

Expand Down Expand Up @@ -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)


0 comments on commit d3fef6f

Please sign in to comment.