[virt-tools-list] [PATCH] systray: toogle Manager on click and a pref. to keep running in tray

Cole Robinson crobinso at redhat.com
Tue Oct 20 15:43:24 UTC 2009


On 10/19/2009 03:10 PM, Jon Nordby wrote:
> Result of me scratching an itch and procrastinating on studies. First time
> using hg and glade so bear with me and give feedback if there is anything
> wrong. Or if there are other things that should/could be improved.
> 
> I believe this addresses the minimal case for: "System Icon Improvements -
> At the very least, a "Minimize to Tray" type option." on
> http://virt-manager.et.redhat.com/page/Roadmap
> The "Keep running in tray" option should however be grayed out when the
> systray is disabled to not confuse the user. I was not able to find out how
> that's done.
> 

Thanks for taking a stab at this.

I regret even adding the systray icon without making your proposed
behavior the default. I think the icon is only useful for people who
plan on having the virt-manager as a long running task, and we shouldn't
require that some top level window stay minimize that whole time.

So, I don't think this should even be an opt out option, let's just out
right enable it! This will simplify your patch substantially (though it
was fine to begin with).

The one extra piece to facilitate this will be a notification that
'virt-manager is still running' when the user closes all windows, with a
'Don't show this again' option. Though it's not required to commit this
patch.

A few comments inline.

> # HG changeset patch
> # User Jon Nordby <jononor at gmail.com>
> # Date 1255977439 -7200
> # Node ID 8250dd5fe08fdd8488ecefd117d2e99add145d7b
> # Parent  7df46187c156c7697b9b93e46e3b391a19c4fbb2
> systray: Option to keep running in tray.
> 
> Clicking the icon toggles manager (show/hide).
> 
> diff -r 7df46187c156 -r 8250dd5fe08f src/virtManager/config.py
> --- a/src/virtManager/config.py	Mon Oct 05 13:03:41 2009 -0400
> +++ b/src/virtManager/config.py	Mon Oct 19 20:37:19 2009 +0200
> @@ -290,6 +290,13 @@
>      def set_view_system_tray(self, val):
>          self.conf.set_bool(self.conf_dir + "/system-tray", val)
>  
> +    def on_keep_running_in_tray_changed(self, callback):
> +        self.conf.notify_add(self.conf_dir + "/system-tray-keep-running", callback)
> +    def get_keep_running_in_tray(self):
> +        return self.conf.get_bool(self.conf_dir + "/system-tray-keep-running")
> +    def set_keep_running_in_tray(self, val):
> +        self.conf.set_bool(self.conf_dir + "/system-tray-keep-running", val)
> +
>      def on_vmlist_stats_type_changed(self, callback):
>          self.conf.notify_add(self.conf_dir + "/vmlist-fields/stats_type",
>                               callback)
> diff -r 7df46187c156 -r 8250dd5fe08f src/virtManager/engine.py
> --- a/src/virtManager/engine.py	Mon Oct 05 13:03:41 2009 -0400
> +++ b/src/virtManager/engine.py	Mon Oct 19 20:37:19 2009 +0200
> @@ -78,7 +78,7 @@
>              logging.debug("Libvirt doesn't support threading, skipping.")
>  
>          # Counter keeping track of how many manager and details windows
> -        # are open. When it is decremented to 0, close the app
> +        # are open. When it is decremented to 0, close the app or keep running in systray
>          self.windows = 0
>  

You have a few long lines here. Please try to keep the lines under 80
columns.

>          self.netdevHelper = vmmNetDevHelper(self.config)
> @@ -95,6 +95,7 @@
>              return
>  
>          self.systray = vmmSystray(self.config, self)
> +        self.systray.connect("action-toggle-manager", self._do_toggle_manager)
>          self.systray.connect("action-view-manager", self._do_show_manager)
>          self.systray.connect("action-suspend-domain", self._do_suspend_domain)
>          self.systray.connect("action-resume-domain", self._do_resume_domain)
> @@ -237,6 +238,8 @@
>          self.show_console(uri, uuid)
>      def _do_show_manager(self, src):
>          self.show_manager()
> +    def _do_toggle_manager(self, src):
> +        self.toggle_manager()
>      def _do_refresh_console(self, src, uri, uuid):
>          self.refresh_console(uri, uuid)
>      def _do_save_domain(self, src, uri, uuid):
> @@ -366,6 +369,13 @@
>              self.windowManager.connect("action-exit-app", self._do_exit_app)
>          return self.windowManager
>  
> +    def toggle_manager(self):
> +        manager = self.get_manager()
> +        if manager.is_visible():
> +            manager.hide()
> +        else:
> +            manager.show()
> +
>      def show_manager(self):
>          self.get_manager().show()
>  
> @@ -376,7 +386,9 @@
>      def decrement_window_counter(self):
>          self.windows -= 1
>          logging.debug("window counter decremented to %s" % self.windows)
> -        if self.windows <= 0:
> +        #only keep running if the user actually has the tray enabled

Please stick a space in between the '#', and capitalize comments:

# Only keep running ...

> +        keep_running = self.config.get_view_system_tray() and self.config.get_keep_running_in_tray()
> +        if self.windows <= 0 and not keep_running:
>              self.exit_app()
>  
>      def exit_app(self):
> diff -r 7df46187c156 -r 8250dd5fe08f src/virtManager/manager.py
> --- a/src/virtManager/manager.py	Mon Oct 05 13:03:41 2009 -0400
> +++ b/src/virtManager/manager.py	Mon Oct 19 20:37:19 2009 +0200
> @@ -390,6 +390,11 @@
>          else:
>              vmlist.get_selection().select_iter(vmlist.get_model().get_iter_first())
>  
> +    def hide(self):
> +        win = self.window.get_widget("vmm-manager")
> +        win.hide()
> +        self.engine.decrement_window_counter()
> +

Hmm, this is essentially the same as the 'close' function in manager.py,
so I think you should be able to reuse it.

>      def show(self):
>          win = self.window.get_widget("vmm-manager")
>          if self.is_visible():
> diff -r 7df46187c156 -r 8250dd5fe08f src/virtManager/preferences.py
> --- a/src/virtManager/preferences.py	Mon Oct 05 13:03:41 2009 -0400
> +++ b/src/virtManager/preferences.py	Mon Oct 19 20:37:19 2009 +0200
> @@ -37,6 +37,7 @@
>          self.topwin = self.window.get_widget("vmm-preferences")
>          self.topwin.hide()
>  
> +        self.config.on_keep_running_in_tray_changed(self.refresh_keep_running_in_tray)
>          self.config.on_view_system_tray_changed(self.refresh_view_system_tray)
>          self.config.on_console_popup_changed(self.refresh_console_popup)
>          self.config.on_console_keygrab_changed(self.refresh_console_keygrab)
> @@ -48,6 +49,7 @@
>          self.config.on_stats_enable_disk_poll_changed(self.refresh_disk_poll)
>          self.config.on_stats_enable_net_poll_changed(self.refresh_net_poll)
>  
> +        self.refresh_keep_running_in_tray()
>          self.refresh_view_system_tray()
>          self.refresh_update_interval()
>          self.refresh_history_length()
> @@ -61,6 +63,7 @@
>  
>          self.window.signal_autoconnect({
>              "on_prefs_system_tray_toggled" : self.change_view_system_tray,
> +            "on_prefs_system_tray_keep_running_toggled" : self.change_keep_running_in_tray,
>              "on_prefs_stats_update_interval_changed": self.change_update_interval,
>              "on_prefs_stats_history_length_changed": self.change_history_length,
>              "on_prefs_console_popup_changed": self.change_console_popup,
> @@ -95,6 +98,11 @@
>          val = self.config.get_view_system_tray()
>          self.window.get_widget("prefs-system-tray").set_active(bool(val))
>  
> +    def refresh_keep_running_in_tray(self, ignore1=None, ignore2=None,
> +                                 ignore3=None, ignore4=None):
> +        val = self.config.get_keep_running_in_tray()
> +        self.window.get_widget("prefs-system-tray-keep-running").set_active(bool(val))
> +
>      def refresh_update_interval(self, ignore1=None,ignore2=None,ignore3=None,ignore4=None):
>          self.window.get_widget("prefs-stats-update-interval").set_value(self.config.get_stats_update_interval())
>      def refresh_history_length(self, ignore1=None,ignore2=None,ignore3=None,ignore4=None):
> @@ -129,6 +137,8 @@
>  
>      def change_view_system_tray(self, src):
>          self.config.set_view_system_tray(src.get_active())
> +    def change_keep_running_in_tray(self, src):
> +        self.config.set_keep_running_in_tray(src.get_active())
>  
>      def change_update_interval(self, src):
>          self.config.set_stats_update_interval(src.get_value_as_int())
> diff -r 7df46187c156 -r 8250dd5fe08f src/virtManager/systray.py
> --- a/src/virtManager/systray.py	Mon Oct 05 13:03:41 2009 -0400
> +++ b/src/virtManager/systray.py	Mon Oct 19 20:37:19 2009 +0200
> @@ -24,6 +24,8 @@
>  
>  class vmmSystray(gobject.GObject):
>      __gsignals__ = {
> +        "action-toggle-manager": (gobject.SIGNAL_RUN_FIRST,
> +                                gobject.TYPE_NONE, []),
>          "action-view-manager": (gobject.SIGNAL_RUN_FIRST,
>                                  gobject.TYPE_NONE, []),
>          "action-suspend-domain": (gobject.SIGNAL_RUN_FIRST,
> @@ -208,7 +210,7 @@
>      # Listeners
>  
>      def systray_activate(self, widget):
> -        self.emit("action-view-manager")
> +        self.emit("action-toggle-manager")
>  
>      def systray_popup(self, widget, button, event_time):
>          if button != 3:
> diff -r 7df46187c156 -r 8250dd5fe08f src/vmm-preferences.glade
> --- a/src/vmm-preferences.glade	Mon Oct 05 13:03:41 2009 -0400
> +++ b/src/vmm-preferences.glade	Mon Oct 19 20:37:19 2009 +0200
> @@ -33,7 +33,7 @@
>                          <child>
>                            <widget class="GtkTable" id="table5">
>                              <property name="visible">True</property>
> -                            <property name="n_rows">2</property>
> +                            <property name="n_rows">3</property>
>                              <property name="column_spacing">6</property>
>                              <property name="row_spacing">6</property>
>                              <child>
> @@ -51,6 +51,22 @@
>                                </packing>
>                              </child>
>                              <child>
> +                              <widget class="GtkCheckButton" id="prefs-system-tray-keep-running">
> +                                <property name="label" translatable="yes">Keep running after closing last window</property>
> +                                <property name="visible">True</property>
> +                                <property name="can_focus">True</property>
> +                                <property name="receives_default">False</property>
> +                                <property name="draw_indicator">True</property>
> +                                <signal name="toggled" handler="on_prefs_system_tray_keep_running_toggled"/>
> +                              </widget>
> +                              <packing>
> +                                <property name="top_attach">1</property>
> +                                <property name="bottom_attach">2</property>
> +                                <property name="x_options">GTK_FILL</property>
> +                                <property name="y_options">GTK_FILL</property>
> +                              </packing>
> +                            </child>
> +                            <child>
>                                <placeholder/>
>                              </child>
>                            </widget>
> @@ -60,7 +76,7 @@
>                      <child>
>                        <widget class="GtkLabel" id="label12">
>                          <property name="visible">True</property>
> -                        <property name="label" translatable="yes"><b>General</b></property>
> +                        <property name="label" translatable="yes"><b>System Tray</b></property>
>                          <property name="use_markup">True</property>
>                        </widget>
>                        <packing>

Thanks,
Cole




More information about the virt-tools-list mailing list