Add named attribute access to gnome-monitor.py (New)#1916
Add named attribute access to gnome-monitor.py (New)#1916fernando79513 merged 39 commits intomainfrom
gnome-monitor.py (New)#1916Conversation
b37882d to
7e759db
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1916 +/- ##
==========================================
+ Coverage 50.46% 50.99% +0.53%
==========================================
Files 382 384 +2
Lines 41039 41591 +552
Branches 6892 7106 +214
==========================================
+ Hits 20709 21208 +499
- Misses 19585 19618 +33
- Partials 745 765 +20
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
gnome-monitor.py (New)
hanhsuan
left a comment
There was a problem hiding this comment.
Please let me know, if there is some misunderstanding. Thanks.
checkbox-support/checkbox_support/dbus/tests/test_gnome_monitor.py
Outdated
Show resolved
Hide resolved
0e0c2ce to
28ffd4a
Compare
There was a problem hiding this comment.
LGTM.
Modify the randr_cycle.py as following
from checkbox_support.dbus.gnome_monitor import MutterDisplayMode as Modeand
if args.cycle == "resolution":
monitor_config.cycle(
cycle_resolution=True,
resolution_filter=resolution_filter,
cycle_transform=False,
post_cycle_action=action,
path=screenshot_path,
)
elif args.cycle == "transform":
monitor_config.cycle(
cycle_resolution=False,
resolution_filter=resolution_filter,
cycle_transform=True,
post_cycle_action=action,
path=screenshot_path,
)
else:
monitor_config.cycle(
cycle_resolution=True,
resolution_filter=resolution_filter,
cycle_transform=True,
post_cycle_action=action,
path=screenshot_path,
)are working as expected.
fernando79513
left a comment
There was a problem hiding this comment.
Thank you for this change, It looks like a really nice quality of life improvement.
I just left two small optional comments but overall it LGTM.
I think this can be merged after implementing the suggestion of hanhsuan.
Regarding #1843, should this PR be merged before?
Yes, this one could be merged first since #1843 hasn't been reviewed by anyone and the script hasn't been used by any test case. I could rebase my PR to adapt it to this one, which will simplify the process. |
* feat: use typed namedtuple for mode and add type annotation for dbus output * feat: fully typed tuples for getCurrentMode * feat: add readonly properties for the propmap * fix: remove main * refactor: use the new classes for get resolutions and monitors * fix: 3.5 compatibility * feat: use native glib type checking * fix: remove more magic numbers * style: rename * style: print msg during cycle(), comments * fix: use const when possible, comments * test: update tests for the new api * fix: remove time.sleep * fix: override is from typing_extensions * style: formatting * fix: remove override * fix: naming * fix: preserve 6 * fix: update transformation str * style: minor naming tweaks * doc: name * fix: 1 more type check * test: increase coverage * fix: crappy names * doc: comments * style: minor name tweak and comments * doc: annotate logicalmonitorconfig * style: name and comments * style: names * fix: formatting * doc: incomplete comment * fix: styles * doc: more comments * fix: apply Fernando's suggestions * fix: add a default post cycle action * fix: remove debug code * style: add a finish message * cleanup: remove debug msg * fix: bad patching in tests
* feat: use typed namedtuple for mode and add type annotation for dbus output * feat: fully typed tuples for getCurrentMode * feat: add readonly properties for the propmap * fix: remove main * refactor: use the new classes for get resolutions and monitors * fix: 3.5 compatibility * feat: use native glib type checking * fix: remove more magic numbers * style: rename * style: print msg during cycle(), comments * fix: use const when possible, comments * test: update tests for the new api * fix: remove time.sleep * fix: override is from typing_extensions * style: formatting * fix: remove override * fix: naming * fix: preserve 6 * fix: update transformation str * style: minor naming tweaks * doc: name * fix: 1 more type check * test: increase coverage * fix: crappy names * doc: comments * style: minor name tweak and comments * doc: annotate logicalmonitorconfig * style: name and comments * style: names * fix: formatting * doc: incomplete comment * fix: styles * doc: more comments * fix: apply Fernando's suggestions * fix: add a default post cycle action * fix: remove debug code * style: add a finish message * cleanup: remove debug msg * fix: bad patching in tests
* feat: use typed namedtuple for mode and add type annotation for dbus output * feat: fully typed tuples for getCurrentMode * feat: add readonly properties for the propmap * fix: remove main * refactor: use the new classes for get resolutions and monitors * fix: 3.5 compatibility * feat: use native glib type checking * fix: remove more magic numbers * style: rename * style: print msg during cycle(), comments * fix: use const when possible, comments * test: update tests for the new api * fix: remove time.sleep * fix: override is from typing_extensions * style: formatting * fix: remove override * fix: naming * fix: preserve 6 * fix: update transformation str * style: minor naming tweaks * doc: name * fix: 1 more type check * test: increase coverage * fix: crappy names * doc: comments * style: minor name tweak and comments * doc: annotate logicalmonitorconfig * style: name and comments * style: names * fix: formatting * doc: incomplete comment * fix: styles * doc: more comments * fix: apply Fernando's suggestions * fix: add a default post cycle action * fix: remove debug code * style: add a finish message * cleanup: remove debug msg * fix: bad patching in tests
Description
This PR adds complete type annotations and named properties to the original gnome-monitors script to hopefully make it more ergonomic to use. It's not something that needs to be urgently merged so don't worry about this if you have a fire to fix xD
Basically turns this:
into this:
with nice IDE autocomplete.
#1843 could take advantage of this to more directly access resolution numbers instead of strings
Resolved issues
In the original
MonitorConfigGnome, accessing deeply nested properties from theGetCurrentState's return value was a bit awkward. If we need to get the 1st refresh rate of the 1st monitor, we need to writestate[1][1][0][1][0][3]which looks like magic numbers without looking at the original dbus xml. The originalMonitorConfigGnomeprovided nice ways to get the resolution strings but all the other properties were not included.This PR circumvents this magic index situation by providing named attribute access for the return value of
GetCurrentState, so now we can writestate.physical_monitors[0].modes[0].refresh_rateand only use indices in places where there's an actual array.Documentation
The main reference point is this xml and gnome-randr
None of the new classes (MutterDisplayConfig, PhysicalMonitor, LogicalMonitor, MonitorInfo) should be directly constructed because they assume that the input GLib.Variant has the correct type. Use
MonitorConfigGnome.get_current_state()as the entry point since it asks GLib to do a deep type check first before returning.Tests
Original unit tests