mirror of
https://github.com/vale981/rmview
synced 2025-03-05 09:11:39 -05:00
Merge master: auto detection of orientation
This commit is contained in:
commit
89d3bef038
3 changed files with 47 additions and 4 deletions
|
@ -39,7 +39,7 @@ The supported configuration settings are:
|
|||
// alternatively to key, "password": "****" is supported
|
||||
"timeout": 1 // in seconds
|
||||
},
|
||||
"orientation": "portrait", // default: landscape
|
||||
"orientation": "portrait", // auto for auto-detect, default: landscape
|
||||
"pen_size": 10, // set to 0 to disable
|
||||
"pen_color": "red",
|
||||
"background_color": "black", // default: white
|
||||
|
|
|
@ -65,11 +65,17 @@ class rMViewApp(QApplication):
|
|||
self.viewer.menu.addAction(act)
|
||||
self.viewer.setWindowTitle("rMview")
|
||||
self.viewer.show()
|
||||
if self.config.get('orientation', 'landscape') == 'landscape':
|
||||
|
||||
self.orient = None
|
||||
orient = self.config.get('orientation', 'landscape')
|
||||
if orient == 'landscape':
|
||||
self.viewer.rotateCW()
|
||||
self.autoResize(WIDTH / HEIGHT)
|
||||
else:
|
||||
elif orient == 'portrait':
|
||||
self.autoResize(HEIGHT / WIDTH)
|
||||
else: # orient
|
||||
self.autoResize(HEIGHT / WIDTH)
|
||||
self.orient = True
|
||||
|
||||
# bar = QMenuBar()
|
||||
# menu = bar.addMenu('&View')
|
||||
|
@ -93,6 +99,25 @@ class rMViewApp(QApplication):
|
|||
self.aboutToQuit.connect(self.joinWorkers)
|
||||
self.requestConnect()
|
||||
|
||||
def detectOrientation(self, image):
|
||||
c = image.pixel
|
||||
portrait = False
|
||||
# print(c(48, 47) , c(72, 72) , c(55, 55) , c(64, 65))
|
||||
if c(48, 47) == 4278190080 and c(72, 72) == 4278190080 and \
|
||||
(c(55, 55) == 4294967295 or c(64, 65) == 4294967295):
|
||||
if c(61, 1812) != 4278190080 or c(5,5) == 4278190080:
|
||||
portrait = True
|
||||
elif c(1356, 47) == 4278190080 and c(1329, 72) == 4278190080 and \
|
||||
(c(1348, 54) == 4294967295 or c(1336, 65) == 4294967295):
|
||||
portrait = True
|
||||
elif c(5,5) == 4278190080:
|
||||
portrait = True
|
||||
if portrait:
|
||||
self.viewer.portrait()
|
||||
self.autoResize(HEIGHT / WIDTH)
|
||||
else:
|
||||
self.viewer.landscape()
|
||||
self.autoResize(WIDTH / HEIGHT)
|
||||
|
||||
def autoResize(self, ratio):
|
||||
dg = self.desktop().availableGeometry(self.viewer)
|
||||
|
@ -144,7 +169,7 @@ class rMViewApp(QApplication):
|
|||
self.ssh = ssh
|
||||
self.viewer.setWindowTitle("rMview - " + self.config.get('ssh').get('address'))
|
||||
self.fbworker = FrameBufferWorker(ssh, delay=self.config.get('fetch_frame_delay'))
|
||||
self.fbworker.signals.onNewFrame.connect(lambda image: self.viewer.setImage(image))
|
||||
self.fbworker.signals.onNewFrame.connect(self.onNewFrame)
|
||||
self.fbworker.signals.onFatalError.connect(self.frameError)
|
||||
self.threadpool.start(self.fbworker)
|
||||
|
||||
|
@ -162,6 +187,13 @@ class rMViewApp(QApplication):
|
|||
self.penworker.signals.onPenFar.connect(self.pen.hide)
|
||||
|
||||
|
||||
@pyqtSlot(QImage)
|
||||
def onNewFrame(self, image):
|
||||
if self.orient:
|
||||
self.detectOrientation(image)
|
||||
self.orient = False
|
||||
self.viewer.setImage(image)
|
||||
|
||||
@pyqtSlot(int, int)
|
||||
def movePen(self, x, y):
|
||||
y = 20951 - y
|
||||
|
|
|
@ -151,6 +151,17 @@ class QtImageViewer(QGraphicsView):
|
|||
img = img.transformed(QTransform().rotate(self._rotation))
|
||||
img.save(fileName)
|
||||
|
||||
def landscape(self):
|
||||
self.resetTransform()
|
||||
self.rotate(90)
|
||||
self._rotation = 90
|
||||
self.updateViewer()
|
||||
|
||||
def portrait(self):
|
||||
self.resetTransform()
|
||||
self._rotation = 0
|
||||
self.updateViewer()
|
||||
|
||||
def rotateCW(self):
|
||||
self.rotate(90)
|
||||
self._rotation += 90
|
||||
|
|
Loading…
Add table
Reference in a new issue