mirror of
https://github.com/ralsina/xrandroll.git
synced 2024-11-21 18:42:22 +00:00
refactor
This commit is contained in:
parent
393c0c09b3
commit
562884609c
26
main.py
26
main.py
@ -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):
|
||||||
|
324
main.ui
324
main.ui
@ -18,222 +18,152 @@
|
|||||||
<widget class="QGraphicsView" name="sceneView"/>
|
<widget class="QGraphicsView" name="sceneView"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<property name="currentIndex">
|
<item row="0" column="0">
|
||||||
<number>1</number>
|
<widget class="QLabel" name="label">
|
||||||
</property>
|
<property name="text">
|
||||||
<widget class="QWidget" name="tabWidgetPage1">
|
<string>Settings for</string>
|
||||||
<attribute name="title">
|
|
||||||
<string>Global Settings</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QFormLayout" name="formLayout_2">
|
|
||||||
<property name="fieldGrowthPolicy">
|
|
||||||
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="formAlignment">
|
</widget>
|
||||||
<set>Qt::AlignHCenter|Qt::AlignTop</set>
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QComboBox" name="screenCombo">
|
||||||
|
<property name="sizeAdjustPolicy">
|
||||||
|
<enum>QComboBox::AdjustToContents</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="leftMargin">
|
</widget>
|
||||||
<number>6</number>
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QCheckBox" name="enabled">
|
||||||
|
<property name="text">
|
||||||
|
<string>Enabled</string>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="1">
|
</widget>
|
||||||
<widget class="QCheckBox" name="usePhysModel">
|
</item>
|
||||||
<property name="text">
|
<item row="2" column="1">
|
||||||
<string>Use physical model</string>
|
<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>
|
</property>
|
||||||
</widget>
|
<property name="singleStep">
|
||||||
</item>
|
<number>5</number>
|
||||||
<item row="1" column="0">
|
</property>
|
||||||
<widget class="QLabel" name="label_5">
|
<property name="pageStep">
|
||||||
<property name="text">
|
<number>25</number>
|
||||||
<string>Global scale:</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QSlider" name="horizontalSlider">
|
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="tickPosition">
|
||||||
|
<enum>QSlider::TicksBelow</enum>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<widget class="QLabel" name="horizontalScaleLabel">
|
||||||
<property name="orientation">
|
<property name="text">
|
||||||
<enum>Qt::Vertical</enum>
|
<string>TextLabel</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
</widget>
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</item>
|
||||||
<widget class="QWidget" name="tabWidgetPage2">
|
<item row="7" column="0">
|
||||||
<property name="layoutDirection">
|
<widget class="QLabel" name="label_7">
|
||||||
<enum>Qt::LeftToRight</enum>
|
<property name="text">
|
||||||
</property>
|
<string>Vertical Scale:</string>
|
||||||
<attribute name="title">
|
|
||||||
<string>Screen Settings</string>
|
|
||||||
</attribute>
|
|
||||||
<layout class="QFormLayout" name="formLayout">
|
|
||||||
<property name="formAlignment">
|
|
||||||
<set>Qt::AlignHCenter|Qt::AlignTop</set>
|
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="0">
|
</widget>
|
||||||
<widget class="QLabel" name="label">
|
</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">
|
<property name="text">
|
||||||
<string>Settings for</string>
|
<string>TextLabel</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</item>
|
||||||
</widget>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
@ -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(),
|
||||||
|
Loading…
Reference in New Issue
Block a user