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():
self.ui.screenCombo.addItem(name)
mon_item = MonitorItem(
0,
0,
monitor["res_x"],
monitor["res_y"],
data=monitor,
window=self,
name=name,
)
mon_item = MonitorItem(0, 0, 0, 0, data=monitor, window=self, name=name,)
mon_item.setPos(monitor["pos_x"], monitor["pos_y"])
self.scene.addItem(mon_item)
monitor["item"] = mon_item
@ -86,18 +78,18 @@ class Window(QObject):
def monitor_moved(self):
"Update xrandr_info with new monitor positions"
for _, mon in self.xrandr_info.items():
item = mon['item']
mon['pos_x'] = item.x()
mon['pos_y'] = item.y()
item = mon["item"]
mon["pos_x"] = item.x()
mon["pos_y"] = item.y()
self.update_replica_of_data()
for _, mon in self.xrandr_info.items():
mon['item'].update_visuals(mon)
mon["item"].update_visuals(mon)
self.adjust_view()
def adjust_view(self):
self.ui.sceneView.resetTransform()
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.height() / self.scene.sceneRect().height(),
)
@ -142,10 +134,10 @@ class Window(QObject):
def update_replica_of_data(self):
for a in self.xrandr_info:
self.xrandr_info[a]['replica_of'] = []
self.xrandr_info[a]["replica_of"] = []
for b in self.xrandr_info:
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):
# Show modes
@ -168,7 +160,7 @@ class Window(QObject):
for mon in self.xrandr_info:
if mon != name:
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)
def updateScaleLabels(self):

324
main.ui
View File

@ -18,222 +18,152 @@
<widget class="QGraphicsView" name="sceneView"/>
</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>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Settings for</string>
</property>
<property name="formAlignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="screenCombo">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
<property name="leftMargin">
<number>6</number>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="enabled">
<property name="text">
<string>Enabled</string>
</property>
<item row="0" column="1">
<widget class="QCheckBox" name="usePhysModel">
<property name="text">
<string>Use physical model</string>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="primary">
<property name="text">
<string>Primary</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Resolution</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="modes">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Orientation</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="comboBox_3">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Replica of:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="replicaOf">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Horizontal Scale:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QSlider" name="horizontalScale">
<property name="maximum">
<number>400</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Global scale:</string>
<property name="singleStep">
<number>5</number>
</property>
<property name="pageStep">
<number>25</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="horizontalSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<item>
<widget class="QLabel" name="horizontalScaleLabel">
<property name="text">
<string>TextLabel</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</widget>
</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">
<property name="formAlignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Vertical Scale:</string>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
</widget>
</item>
<item row="7" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSlider" name="verticalScale">
<property name="maximum">
<number>400</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
<property name="pageStep">
<number>25</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="verticalScaleLabel">
<property name="text">
<string>Settings for</string>
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="screenCombo">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="enabled">
<property name="text">
<string>Enabled</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="primary">
<property name="text">
<string>Primary</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Resolution</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="modes">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Orientation</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="comboBox_3">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Replica of:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="replicaOf">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Horizontal Scale:</string>
</property>
</widget>
</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">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSlider" name="horizontalScale">
<property name="maximum">
<number>400</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
<property name="pageStep">
<number>25</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="horizontalScaleLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="7" column="1">
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QSlider" name="verticalScale">
<property name="maximum">
<number>400</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
<property name="pageStep">
<number>25</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="verticalScaleLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">

View File

@ -20,6 +20,8 @@ class MonitorItem(QGraphicsRectItem, QObject):
label_text = f"{self.name} [{','.join(data['replica_of'])}]"
else:
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)
label_scale = min(
self.rect().width() / self.label.boundingRect().width(),