-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Text box can be used to set DPI #960
Text box can be used to set DPI #960
Conversation
Find and apply closest resolution in self.resolutions. [Needed?] Store value on textbox focus in. [Needed?] Do not apply DPI value if the same as previous value. DPI entry and resolution sliders affect each others' values.
Remove focus methods.
Pass reference to ResolutionsPage when initialising ResolutionRow. Use reference to invoke `ResolutionsPage._on_row_activated()`. Do not toggle Revealer on DPI entry text box focus-in-event if Revealer is already expanded. Grammar: dpi -> DPI
Prefix unused vars with underscores. Actioned suggested import order from linter.
Apply the res value on focus-out-event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some quick testing shows:
Piper started:
/path/to/piper/piper/resolutionrow.py:170: Warning: g_value_get_int: assertion 'G_VALUE_HOLDS_INT (value)' failed
self.dpi_entry.set_text(str(res))
Slider moved:
/path/to/piper/piper/resolutionrow.py:218: Warning: g_value_get_int: assertion 'G_VALUE_HOLDS_INT (value)' failed
self.dpi_entry.set_text(str(res))
/path/to/piper/piper/resolutionrow.py:96: Warning: g_value_get_int: assertion 'G_VALUE_HOLDS_INT (value)' failed
self.dpi_entry.set_text(str(value))
Typing non-numeric characters:
/usr/lib/python3.12/site-packages/gi/overrides/Gio.py:42: Warning: g_value_get_int: assertion 'G_VALUE_HOLDS_INT (value)' failed
return Gio.Application.run(self, *args, **kwargs)
Not sure after which action:
/path/to/piper/piper/resolutionrow.py:191: Warning: g_value_get_int: assertion 'G_VALUE_HOLDS_INT (value)' failed
entry.set_text(str(closest_res))
/path/to/piper/piper/resolutionrow.py:200: Warning: g_value_get_int: assertion 'G_VALUE_HOLDS_INT (value)' failed
entry.set_text(str(self._resolution.resolution[0]))
Even a simple set_text call on Gtk.Entry when signal callbacks are present is enough to trigger those warnings. Seems to be a pygobject bug: https://gitlab.gnome.org/GNOME/pygobject/-/issues/12 Looks like Lutris has had same warnings at some point, and they fixed it by sub-classing Gtk.Entry: lutris/lutris#394 |
Following the advice from https://bugzilla.gnome.org/show_bug.cgi?id=708676 I have suppressed all warnings except for the one originating from Gio.py. I'll need to investigate this more, but the warning occurs before anything in the method to handle text input is run, so probably something to do with the signalling. with warnings.catch_warnings():
warnings.simplefilter("ignore")
self.dpi_entry.set_text(str(value)) If we made a class to wrap around Gtk.Entry, would we not be able to use it in the UI files? I'm not familiar with GTK or UI files. What would make it uglier? While suppressing the warnings isn't too bad currently because we're not doing it much, I think it would be a good idea to do something like Lutris' solution in the future if Gtk Entry components end up being used more. |
Seems like the issue occurs due to another instance of this same bug, where some parameters - like position, are invalid when handled using signals. The last assertion warning that I haven't suppressed yet is in Gio.py (when handling the insert-text signal). It seems like a solution is to make a class that inherits both A problem I see already is that the components are of a new Gtk.Template.Child(), so I'm not sure how to make this work with this custom class. Any advice is appreciated! |
Grab DPIEntry focus when revealing ResolutionRow. Revert import order. Removed unused 'previous DPI value' var. Remove 'private' convention underscore from ResolutionsPage._on_row_activate(). Remove callback method for DPI entry on ResolutionRow. UI file uses DPIEntry. Remove insert-text signal for DPIEntry from UI file.
Using this new class as suggested in the StackOverflow link results in no warnings anymore. Feel free to test. |
Underscored unused parameter (PEP convention).
revealer: Gtk.Revealer = Gtk.Template.Child() # type: ignore | ||
scale: Gtk.Scale = Gtk.Template.Child() # type: ignore | ||
|
||
CAP_SEPARATE_XY_RESOLUTION = False | ||
CAP_DISABLE = False | ||
|
||
def __init__(self, resolution: RatbagdResolution, *args, **kwargs) -> None: | ||
def __init__( | ||
self, resolution: RatbagdResolution, resolutions_page, *args, **kwargs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I wonder if we could type-hint 'resolutions_page'. My Python is rusty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments seem superfluous (and so are existing ones; explain the reason behind code if needed, instead of rephrasing code into words), but otherwise looks good to me. Glad you figured out how to work-around GTK. :)
You seem not to have allowed maintainer push access, I prefer rebasing manually which requires that.
Regardless, merged with GitHub UI instead. Thank you for your contribution. :) |
resolves #423
I've found clicking and dragging the sliders to set DPIs to be a bit finnicky, so I have added GtkEntry objects where the DPI labels would appear. This allows for setting the DPI via keyboard input.
Changes
ResolutionRow()
init takes reference toResolutionsPage
as to call_on_row_activated()
when the DPI text box is focused.