mirror of
https://github.com/ralsina/xrandroll.git
synced 2024-11-22 02:52:23 +00:00
monitor labels
This commit is contained in:
parent
01589211e9
commit
57336f7dd7
20
main.py
20
main.py
@ -1,9 +1,10 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PySide2.QtWidgets import QApplication, QGraphicsScene, QGraphicsRectItem
|
from PySide2.QtCore import QFile, QPoint, Qt
|
||||||
from PySide2.QtUiTools import QUiLoader
|
from PySide2.QtUiTools import QUiLoader
|
||||||
from PySide2.QtCore import QFile, Qt, QPoint
|
from PySide2.QtWidgets import (QApplication, QGraphicsRectItem, QGraphicsScene,
|
||||||
|
QGraphicsTextItem)
|
||||||
|
|
||||||
|
|
||||||
def parse_monitor(line):
|
def parse_monitor(line):
|
||||||
@ -49,6 +50,11 @@ class MonitorItem(QGraphicsRectItem):
|
|||||||
def __init__(self, *a, **kw):
|
def __init__(self, *a, **kw):
|
||||||
super().__init__(*a, **kw)
|
super().__init__(*a, **kw)
|
||||||
self.setAcceptedMouseButtons(Qt.LeftButton)
|
self.setAcceptedMouseButtons(Qt.LeftButton)
|
||||||
|
self.label = QGraphicsTextItem(kw['name'], self)
|
||||||
|
label_scale = min(
|
||||||
|
self.rect().width() / self.label.boundingRect().width(),
|
||||||
|
self.rect().height() / self.label.boundingRect().height())
|
||||||
|
self.label.setScale(label_scale)
|
||||||
|
|
||||||
def mousePressEvent(self, event):
|
def mousePressEvent(self, event):
|
||||||
self.setCursor(Qt.ClosedHandCursor)
|
self.setCursor(Qt.ClosedHandCursor)
|
||||||
@ -61,21 +67,19 @@ class MonitorItem(QGraphicsRectItem):
|
|||||||
view = event.widget().parent()
|
view = event.widget().parent()
|
||||||
click_pos = event.buttonDownScreenPos(Qt.LeftButton)
|
click_pos = event.buttonDownScreenPos(Qt.LeftButton)
|
||||||
current_pos = event.screenPos()
|
current_pos = event.screenPos()
|
||||||
print(current_pos - click_pos)
|
self.setPos(
|
||||||
print(view.mapToScene(view.mapFromScene(self.orig_pos) + current_pos - click_pos))
|
view.mapToScene(view.mapFromScene(self.orig_pos) + current_pos - click_pos)
|
||||||
self.setPos(view.mapToScene(view.mapFromScene(self.orig_pos) + current_pos - click_pos))
|
)
|
||||||
# self.setPos(delta.x(), delta.y())
|
|
||||||
|
|
||||||
|
|
||||||
def fill_ui(data, window):
|
def fill_ui(data, window):
|
||||||
global scene
|
global scene
|
||||||
scene = QGraphicsScene(window)
|
scene = QGraphicsScene(window)
|
||||||
scene.addText("Hello World!")
|
|
||||||
window.sceneView.setScene(scene)
|
window.sceneView.setScene(scene)
|
||||||
window.screenCombo.clear()
|
window.screenCombo.clear()
|
||||||
for name, monitor in xrandr_info.items():
|
for name, monitor in xrandr_info.items():
|
||||||
window.screenCombo.addItem(name)
|
window.screenCombo.addItem(name)
|
||||||
mon_item = MonitorItem(0, 0, monitor["res_x"], monitor["res_y"])
|
mon_item = MonitorItem(0, 0, monitor["res_x"], monitor["res_y"], name=name)
|
||||||
mon_item.setPos(monitor["pos_x"], monitor["pos_y"])
|
mon_item.setPos(monitor["pos_x"], monitor["pos_y"])
|
||||||
scene.addItem(mon_item)
|
scene.addItem(mon_item)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user