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():
|
||||
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):
|
||||
|
90
main.ui
90
main.ui
@ -18,71 +18,7 @@
|
||||
<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>
|
||||
</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">
|
||||
<property name="formAlignment">
|
||||
<set>Qt::AlignHCenter|Qt::AlignTop</set>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
@ -160,16 +96,8 @@
|
||||
</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">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QSlider" name="horizontalScale">
|
||||
<property name="maximum">
|
||||
@ -192,16 +120,21 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="horizontalScaleLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Vertical Scale:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QSlider" name="verticalScale">
|
||||
<property name="maximum">
|
||||
@ -224,16 +157,13 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="verticalScaleLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
|
@ -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(),
|
||||
|
Loading…
Reference in New Issue
Block a user