Setting a widget's state using set_active() will trigger the "toggled" signal if the new state is different from the previous. For boolean per-vm settings which have a global default this can lead to the global default being written as per-vm settings whenever the global default changes. Disconnect the repective signals when setting initial or external state. Signed-off-by: Michael Weiser <michael.weiser@xxxxxx> --- ui/vmwindow.ui | 5 ----- virtManager/baseclass.py | 11 ++++++++++ virtManager/details/console.py | 37 +++++++++++++++++++++++----------- virtManager/vmwindow.py | 21 +++++++------------ 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/ui/vmwindow.ui b/ui/vmwindow.ui index 4d226835..a9772917 100644 --- a/ui/vmwindow.ui +++ b/ui/vmwindow.ui @@ -128,7 +128,6 @@ <property name="tooltip_text" translatable="yes">Requires guest agent to work</property> <property name="label" translatable="yes">_Sync guest time on resume</property> <property name="use_underline">True</property> - <signal name="toggled" handler="on_details_menu_sync_guest_time_on_resume_toggled" swapped="no"/> </object> </child> </object> @@ -218,7 +217,6 @@ <property name="label" translatable="yes">_Always</property> <property name="use_underline">True</property> <property name="active">True</property> - <signal name="toggled" handler="on_details_menu_view_scale_always_toggled" swapped="no"/> </object> </child> <child> @@ -229,7 +227,6 @@ <property name="use_underline">True</property> <property name="draw_as_radio">True</property> <property name="group">details-menu-view-scale-always</property> - <signal name="toggled" handler="on_details_menu_view_scale_fullscreen_toggled" swapped="no"/> </object> </child> <child> @@ -240,7 +237,6 @@ <property name="use_underline">True</property> <property name="draw_as_radio">True</property> <property name="group">details-menu-view-scale-always</property> - <signal name="toggled" handler="on_details_menu_view_scale_never_toggled" swapped="no"/> </object> </child> <child> @@ -255,7 +251,6 @@ <property name="can_focus">False</property> <property name="label" translatable="yes">Auto _resize VM with window</property> <property name="use_underline">True</property> - <signal name="toggled" handler="on_details_menu_view_resizeguest_toggled" swapped="no"/> </object> </child> </object> diff --git a/virtManager/baseclass.py b/virtManager/baseclass.py index 451e8a8a..42d6470d 100644 --- a/virtManager/baseclass.py +++ b/virtManager/baseclass.py @@ -295,6 +295,17 @@ class vmmGObjectUI(vmmGObject): def widget(self, name): return self.builder.get_object(name) + def set_active_wo_signal(self, val, sig_id, cb, widget_name=None, + widget=None): + if not widget: + widget = self.widget(widget_name) + if not widget: + return + if sig_id: + widget.disconnect(sig_id) + widget.set_active(val) + return widget.connect("toggled", cb) + def cleanup(self): if self.__cleaned_up: return diff --git a/virtManager/details/console.py b/virtManager/details/console.py index 193e79eb..82f27c82 100644 --- a/virtManager/details/console.py +++ b/virtManager/details/console.py @@ -230,11 +230,16 @@ class vmmConsolePages(vmmGObjectUI): self._scroll_size_allocate) self._refresh_widget_states() - self._refresh_scaling_from_settings() + self.details_menu_view_scale_always_toggled = None + self.details_menu_view_scale_fullscreen_toggled = None + self.details_menu_view_scale_never_toggled = None + self._refresh_scaling_from_settings() self.add_gsettings_handle( self.vm.on_console_scaling_changed( self._refresh_scaling_from_settings)) + + self.details_menu_view_resizeguest_toggled = None self._refresh_resizeguest_from_settings() self.add_gsettings_handle( self.vm.on_console_resizeguest_changed( @@ -419,10 +424,14 @@ class vmmConsolePages(vmmGObjectUI): val = self.vm.get_console_resizeguest() widget = self.widget("details-menu-view-resizeguest") + if self.details_menu_view_resizeguest_toggled: + widget.disconnect(self.details_menu_view_resizeguest_toggled) widget.set_tooltip_text(tooltip) widget.set_sensitive(not bool(tooltip)) if not tooltip: self.widget("details-menu-view-resizeguest").set_active(bool(val)) + self.details_menu_view_resizeguest_toggled = widget.connect("toggled", + self._resizeguest_ui_changed_cb) self._sync_resizeguest_with_display() @@ -465,13 +474,21 @@ class vmmConsolePages(vmmGObjectUI): def _refresh_scaling_from_settings(self): scale_type = self.vm.get_console_scaling() - self.widget("details-menu-view-scale-always").set_active( - scale_type == self.config.CONSOLE_SCALE_ALWAYS) - self.widget("details-menu-view-scale-never").set_active( - scale_type == self.config.CONSOLE_SCALE_NEVER) - self.widget("details-menu-view-scale-fullscreen").set_active( - scale_type == self.config.CONSOLE_SCALE_FULLSCREEN) - + self.details_menu_view_scale_always_toggled = self.set_active_wo_signal( + scale_type == self.config.CONSOLE_SCALE_ALWAYS, + self.details_menu_view_scale_always_toggled, + self._scaling_ui_changed_cb, + "details-menu-view-scale-always") + self.details_menu_view_scale_never_toggled = self.set_active_wo_signal( + scale_type == self.config.CONSOLE_SCALE_NEVER, + self.details_menu_view_scale_never_toggled, + self._scaling_ui_changed_cb, + "details-menu-view-scale-never") + self.details_menu_view_scale_fullscreen_toggled = self.set_active_wo_signal( + scale_type == self.config.CONSOLE_SCALE_FULLSCREEN, + self.details_menu_view_scale_fullscreen_toggled, + self._scaling_ui_changed_cb, + "details-menu-view-scale-fullscreen") self._sync_scaling_with_display() def _scaling_ui_changed_cb(self, src): @@ -1026,13 +1043,9 @@ class vmmConsolePages(vmmGObjectUI): def details_refresh_can_fullscreen(self): return self._refresh_can_fullscreen() - def details_resizeguest_ui_changed_cb(self, *args, **kwargs): - return self._resizeguest_ui_changed_cb(*args, **kwargs) def details_page_changed(self, *args, **kwargs): return self._page_changed(*args, **kwargs) - def details_scaling_ui_changed_cb(self, *args, **kwargs): - return self._scaling_ui_changed_cb(*args, **kwargs) def details_size_to_vm(self, *args, **kwargs): return self._do_size_to_vm(*args, **kwargs) diff --git a/virtManager/vmwindow.py b/virtManager/vmwindow.py index b4cf20fc..178331b1 100644 --- a/virtManager/vmwindow.py +++ b/virtManager/vmwindow.py @@ -90,6 +90,7 @@ class vmmVMWindow(vmmGObjectUI): self._vmmenu = None self.init_menus() + self.details_menu_sync_guest_time_on_resume_toggled = None self._refresh_sync_guest_time_on_resume_from_settings() self.add_gsettings_handle( self.vm.on_sync_guest_time_on_resume_changed( @@ -116,8 +117,6 @@ class vmmVMWindow(vmmGObjectUI): "on_details_menu_virtual_manager_activate": self.control_vm_menu, "on_details_menu_screenshot_activate": self.control_vm_screenshot, "on_details_menu_usb_redirection": self.control_vm_usb_redirection, - "on_details_menu_sync_guest_time_on_resume_toggled": ( - self.details_sync_guest_time_on_resume_changed), "on_details_menu_view_toolbar_activate": self.toggle_toolbar, "on_details_menu_view_manager_activate": self.view_manager, "on_details_menu_view_details_toggled": self.details_console_changed, @@ -131,14 +130,6 @@ class vmmVMWindow(vmmGObjectUI): self.console.details_toggle_fullscreen), "on_details_menu_view_size_to_vm_activate": ( self.console.details_size_to_vm), - "on_details_menu_view_scale_always_toggled": ( - self.console.details_scaling_ui_changed_cb), - "on_details_menu_view_scale_fullscreen_toggled": ( - self.console.details_scaling_ui_changed_cb), - "on_details_menu_view_scale_never_toggled": ( - self.console.details_scaling_ui_changed_cb), - "on_details_menu_view_resizeguest_toggled": ( - self.console.details_resizeguest_ui_changed_cb), "on_console_pages_switch_page": ( self.console.details_page_changed), @@ -512,11 +503,13 @@ class vmmVMWindow(vmmGObjectUI): buttons=Gtk.ButtonsType.CLOSE) def _refresh_sync_guest_time_on_resume_from_settings(self): - sync_time = self.widget("details-menu-sync-guest-time-on-resume") - does_sync_time = self.vm.get_sync_guest_time_on_resume() - sync_time.set_active(does_sync_time) + self.details_menu_sync_guest_time_on_resume_toggled = self.set_active_wo_signal( + self.vm.get_sync_guest_time_on_resume(), + self.details_menu_sync_guest_time_on_resume_toggled, + self._details_sync_guest_time_on_resume_changed, + "details-menu-sync-guest-time-on-resume") - def details_sync_guest_time_on_resume_changed(self, src): + def _details_sync_guest_time_on_resume_changed(self, src): if not src.get_sensitive(): return self.vm.set_sync_guest_time_on_resume(src.get_active()) -- 2.24.0 _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list