This commit is contained in:
Roberto Alsina 2020-01-31 17:20:47 -03:00
parent 393c0c09b3
commit 562884609c
3 changed files with 138 additions and 214 deletions

26
main.py
View File

@ -68,15 +68,7 @@ class Window(QObject):
for name, monitor in self.xrandr_info.items(): for name, monitor in self.xrandr_info.items():
self.ui.screenCombo.addItem(name) self.ui.screenCombo.addItem(name)
mon_item = MonitorItem( mon_item = MonitorItem(0, 0, 0, 0, data=monitor, window=self, name=name,)
0,
0,
monitor["res_x"],
monitor["res_y"],
data=monitor,
window=self,
name=name,
)
mon_item.setPos(monitor["pos_x"], monitor["pos_y"]) mon_item.setPos(monitor["pos_x"], monitor["pos_y"])
self.scene.addItem(mon_item) self.scene.addItem(mon_item)
monitor["item"] = mon_item monitor["item"] = mon_item
@ -86,18 +78,18 @@ class Window(QObject):
def monitor_moved(self): def monitor_moved(self):
"Update xrandr_info with new monitor positions" "Update xrandr_info with new monitor positions"
for _, mon in self.xrandr_info.items(): for _, mon in self.xrandr_info.items():
item = mon['item'] item = mon["item"]
mon['pos_x'] = item.x() mon["pos_x"] = item.x()
mon['pos_y'] = item.y() mon["pos_y"] = item.y()
self.update_replica_of_data() self.update_replica_of_data()
for _, mon in self.xrandr_info.items(): for _, mon in self.xrandr_info.items():
mon['item'].update_visuals(mon) mon["item"].update_visuals(mon)
self.adjust_view() self.adjust_view()
def adjust_view(self): def adjust_view(self):
self.ui.sceneView.resetTransform() self.ui.sceneView.resetTransform()
self.ui.sceneView.ensureVisible(self.scene.sceneRect(), 100, 100) self.ui.sceneView.ensureVisible(self.scene.sceneRect(), 100, 100)
scale_factor = .8 * min( scale_factor = 0.8 * min(
self.ui.sceneView.width() / self.scene.sceneRect().width(), self.ui.sceneView.width() / self.scene.sceneRect().width(),
self.ui.sceneView.height() / self.scene.sceneRect().height(), self.ui.sceneView.height() / self.scene.sceneRect().height(),
) )
@ -142,10 +134,10 @@ class Window(QObject):
def update_replica_of_data(self): def update_replica_of_data(self):
for a in self.xrandr_info: for a in self.xrandr_info:
self.xrandr_info[a]['replica_of'] = [] self.xrandr_info[a]["replica_of"] = []
for b in self.xrandr_info: for b in self.xrandr_info:
if a != b and is_replica_of(self.xrandr_info[a], self.xrandr_info[b]): if a != b and is_replica_of(self.xrandr_info[a], self.xrandr_info[b]):
self.xrandr_info[a]['replica_of'].append(b) self.xrandr_info[a]["replica_of"].append(b)
def monitor_selected(self, name): def monitor_selected(self, name):
# Show modes # Show modes
@ -168,7 +160,7 @@ class Window(QObject):
for mon in self.xrandr_info: for mon in self.xrandr_info:
if mon != name: if mon != name:
self.ui.replicaOf.addItem(mon) self.ui.replicaOf.addItem(mon)
if mon in self.xrandr_info[name]['replica_of']: if mon in self.xrandr_info[name]["replica_of"]:
self.ui.replicaOf.setCurrentText(mon) self.ui.replicaOf.setCurrentText(mon)
def updateScaleLabels(self): def updateScaleLabels(self):

90
main.ui
View File

@ -18,71 +18,7 @@
<widget class="QGraphicsView" name="sceneView"/> <widget class="QGraphicsView" name="sceneView"/>
</item> </item>
<item> <item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="tabWidgetPage1">
<attribute name="title">
<string>Global Settings</string>
</attribute>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
</property>
<property name="formAlignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<property name="leftMargin">
<number>6</number>
</property>
<item row="0" column="1">
<widget class="QCheckBox" name="usePhysModel">
<property name="text">
<string>Use physical model</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Global scale:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="horizontalSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabWidgetPage2">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<attribute name="title">
<string>Screen Settings</string>
</attribute>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="formAlignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
@ -160,16 +96,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Vertical Scale:</string>
</property>
</widget>
</item>
<item row="6" column="1"> <item row="6" column="1">
<widget class="QWidget" name="widget" native="true"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QSlider" name="horizontalScale"> <widget class="QSlider" name="horizontalScale">
<property name="maximum"> <property name="maximum">
@ -192,16 +120,21 @@
<item> <item>
<widget class="QLabel" name="horizontalScaleLabel"> <widget class="QLabel" name="horizontalScaleLabel">
<property name="text"> <property name="text">
<string/> <string>TextLabel</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Vertical Scale:</string>
</property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="7" column="1">
<widget class="QWidget" name="widget_2" native="true"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<widget class="QSlider" name="verticalScale"> <widget class="QSlider" name="verticalScale">
<property name="maximum"> <property name="maximum">
@ -224,16 +157,13 @@
<item> <item>
<widget class="QLabel" name="verticalScaleLabel"> <widget class="QLabel" name="verticalScaleLabel">
<property name="text"> <property name="text">
<string/> <string>TextLabel</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget>
</item> </item>
</layout> </layout>
</widget>
</widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">

View File

@ -20,6 +20,8 @@ class MonitorItem(QGraphicsRectItem, QObject):
label_text = f"{self.name} [{','.join(data['replica_of'])}]" label_text = f"{self.name} [{','.join(data['replica_of'])}]"
else: else:
label_text = self.name label_text = self.name
self.setRect(0, 0, data['res_x'], data['res_y'])
self.setPos(data['pos_x'], data['pos_y'])
self.label.setPlainText(label_text) self.label.setPlainText(label_text)
label_scale = min( label_scale = min(
self.rect().width() / self.label.boundingRect().width(), self.rect().width() / self.label.boundingRect().width(),