mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-03 20:20:39 -06:00
uihelpers: Add VMShutdownMenu class
And use it in all the places where we are duplicating a similar menu
This commit is contained in:
parent
1683d56b8d
commit
268b462126
@ -346,6 +346,7 @@
|
|||||||
<object class="GtkMenuItem" id="details-menu-usb-redirection">
|
<object class="GtkMenuItem" id="details-menu-usb-redirection">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="tooltip_text" translatable="yes">Redirect USB device attached on host to virtual machine with SPICE graphics. USB Redirection device is required for Virtual Machine to support this functionality. Auto-redirection is enabled by default</property>
|
||||||
<property name="label" translatable="yes">_Redirect USB device</property>
|
<property name="label" translatable="yes">_Redirect USB device</property>
|
||||||
<property name="use_underline">True</property>
|
<property name="use_underline">True</property>
|
||||||
<signal name="activate" handler="on_details_menu_usb_redirection" swapped="no"/>
|
<signal name="activate" handler="on_details_menu_usb_redirection" swapped="no"/>
|
||||||
|
@ -634,14 +634,9 @@ class vmmDetails(vmmGObjectUI):
|
|||||||
|
|
||||||
def init_menus(self):
|
def init_menus(self):
|
||||||
# Virtual Machine menu
|
# Virtual Machine menu
|
||||||
self.widget("details-menu-usb-redirection").set_tooltip_text(
|
menu = uihelpers.VMShutdownMenu(self, lambda: self.vm)
|
||||||
_("Redirect USB device attached on host to virtual machine with SPICE graphics. USB Redirection device is required for Virtual Machine to support this functionality. Auto-redirection is enabled by default"))
|
self.widget("control-shutdown").set_menu(menu)
|
||||||
uihelpers.build_shutdown_button_menu(self.widget("control-shutdown"),
|
self.widget("control-shutdown").set_icon_name("system-shutdown")
|
||||||
self.control_vm_shutdown,
|
|
||||||
self.control_vm_reboot,
|
|
||||||
self.control_vm_reset,
|
|
||||||
self.control_vm_destroy,
|
|
||||||
self.control_vm_save)
|
|
||||||
|
|
||||||
for name in ["details-menu-shutdown",
|
for name in ["details-menu-shutdown",
|
||||||
"details-menu-reboot",
|
"details-menu-reboot",
|
||||||
@ -1353,6 +1348,7 @@ class vmmDetails(vmmGObjectUI):
|
|||||||
|
|
||||||
self.widget("details-menu-migrate").set_sensitive(stop)
|
self.widget("details-menu-migrate").set_sensitive(stop)
|
||||||
self.widget("control-shutdown").set_sensitive(stop)
|
self.widget("control-shutdown").set_sensitive(stop)
|
||||||
|
self.widget("control-shutdown").get_menu().update_widget_states(vm)
|
||||||
self.widget("details-menu-shutdown").set_sensitive(stop)
|
self.widget("details-menu-shutdown").set_sensitive(stop)
|
||||||
self.widget("details-menu-save").set_sensitive(stop)
|
self.widget("details-menu-save").set_sensitive(stop)
|
||||||
self.widget("control-pause").set_sensitive(stop)
|
self.widget("control-pause").set_sensitive(stop)
|
||||||
|
@ -160,6 +160,7 @@ class vmmEngine(vmmGObject):
|
|||||||
self.systray.connect("action-reboot-domain", self._do_reboot_domain)
|
self.systray.connect("action-reboot-domain", self._do_reboot_domain)
|
||||||
self.systray.connect("action-destroy-domain", self._do_destroy_domain)
|
self.systray.connect("action-destroy-domain", self._do_destroy_domain)
|
||||||
self.systray.connect("action-reset-domain", self._do_reset_domain)
|
self.systray.connect("action-reset-domain", self._do_reset_domain)
|
||||||
|
self.systray.connect("action-save-domain", self._do_save_domain)
|
||||||
self.systray.connect("action-show-vm", self._do_show_vm)
|
self.systray.connect("action-show-vm", self._do_show_vm)
|
||||||
self.systray.connect("action-exit-app", self.exit_app)
|
self.systray.connect("action-exit-app", self.exit_app)
|
||||||
|
|
||||||
|
@ -125,9 +125,8 @@ class vmmManager(vmmGObjectUI):
|
|||||||
self.prev_position = None
|
self.prev_position = None
|
||||||
|
|
||||||
self.vmmenu = Gtk.Menu()
|
self.vmmenu = Gtk.Menu()
|
||||||
self.vmmenushutdown = Gtk.Menu()
|
self.vmmenushutdown = uihelpers.VMShutdownMenu(self, self.current_vm)
|
||||||
self.vmmenu_items = {}
|
self.vmmenu_items = {}
|
||||||
self.vmmenushutdown_items = {}
|
|
||||||
self.connmenu = Gtk.Menu()
|
self.connmenu = Gtk.Menu()
|
||||||
self.connmenu_items = {}
|
self.connmenu_items = {}
|
||||||
|
|
||||||
@ -238,9 +237,8 @@ class vmmManager(vmmGObjectUI):
|
|||||||
self.vmmenu.destroy()
|
self.vmmenu.destroy()
|
||||||
self.vmmenu = None
|
self.vmmenu = None
|
||||||
self.vmmenu_items = None
|
self.vmmenu_items = None
|
||||||
self.vmmenushutdown.destroy()
|
self.vmmenushutdown.destroy() # pylint: disable=E1101
|
||||||
self.vmmenushutdown = None
|
self.vmmenushutdown = None
|
||||||
self.vmmenushutdown_items = None
|
|
||||||
self.connmenu.destroy()
|
self.connmenu.destroy()
|
||||||
self.connmenu = None
|
self.connmenu = None
|
||||||
self.connmenu_items = None
|
self.connmenu_items = None
|
||||||
@ -288,12 +286,10 @@ class vmmManager(vmmGObjectUI):
|
|||||||
def init_toolbar(self):
|
def init_toolbar(self):
|
||||||
self.widget("vm-new").set_icon_name("vm_new")
|
self.widget("vm-new").set_icon_name("vm_new")
|
||||||
self.widget("vm-open").set_icon_name("icon_console")
|
self.widget("vm-open").set_icon_name("icon_console")
|
||||||
uihelpers.build_shutdown_button_menu(self.widget("vm-shutdown"),
|
|
||||||
self.poweroff_vm,
|
menu = uihelpers.VMShutdownMenu(self, self.current_vm)
|
||||||
self.reboot_vm,
|
self.widget("vm-shutdown").set_icon_name("system-shutdown")
|
||||||
self.reset_vm,
|
self.widget("vm-shutdown").set_menu(menu)
|
||||||
self.destroy_vm,
|
|
||||||
self.save_vm)
|
|
||||||
|
|
||||||
tool = self.widget("vm-toolbar")
|
tool = self.widget("vm-toolbar")
|
||||||
tool.set_property("icon-size", Gtk.IconSize.LARGE_TOOLBAR)
|
tool.set_property("icon-size", Gtk.IconSize.LARGE_TOOLBAR)
|
||||||
@ -301,22 +297,15 @@ class vmmManager(vmmGObjectUI):
|
|||||||
c.set_homogeneous(False)
|
c.set_homogeneous(False)
|
||||||
|
|
||||||
def init_context_menus(self):
|
def init_context_menus(self):
|
||||||
def build_icon(name):
|
|
||||||
return Gtk.Image.new_from_icon_name(name, Gtk.IconSize.MENU)
|
|
||||||
|
|
||||||
def build_stock(name):
|
def build_stock(name):
|
||||||
return Gtk.Image.new_from_stock(name, Gtk.IconSize.MENU)
|
return Gtk.Image.new_from_stock(name, Gtk.IconSize.MENU)
|
||||||
|
|
||||||
shutdownmenu_icon = build_icon("system-shutdown")
|
shutdownmenu_icon = Gtk.Image.new_from_icon_name(
|
||||||
reboot_icon = build_icon("system-shutdown")
|
"system-shutdown", Gtk.IconSize.MENU)
|
||||||
shutdown_icon = build_icon("system-shutdown")
|
run_icon = build_stock(Gtk.STOCK_MEDIA_PLAY)
|
||||||
destroy_icon = build_icon("system-shutdown")
|
pause_icon = build_stock(Gtk.STOCK_MEDIA_PAUSE)
|
||||||
reset_icon = build_icon("system-shutdown")
|
resume_icon = build_stock(Gtk.STOCK_MEDIA_PAUSE)
|
||||||
run_icon = build_stock(Gtk.STOCK_MEDIA_PLAY)
|
delete_icon = build_stock(Gtk.STOCK_DELETE)
|
||||||
pause_icon = build_stock(Gtk.STOCK_MEDIA_PAUSE)
|
|
||||||
save_icon = build_stock(Gtk.STOCK_SAVE)
|
|
||||||
resume_icon = build_stock(Gtk.STOCK_MEDIA_PAUSE)
|
|
||||||
delete_icon = build_stock(Gtk.STOCK_DELETE)
|
|
||||||
|
|
||||||
def add_to_menu(menu, items, idx, text, icon, cb):
|
def add_to_menu(menu, items, idx, text, icon, cb):
|
||||||
if text[0:3] == 'gtk':
|
if text[0:3] == 'gtk':
|
||||||
@ -333,9 +322,6 @@ class vmmManager(vmmGObjectUI):
|
|||||||
|
|
||||||
def add_vm_menu(idx, text, icon, cb):
|
def add_vm_menu(idx, text, icon, cb):
|
||||||
add_to_menu(self.vmmenu, self.vmmenu_items, idx, text, icon, cb)
|
add_to_menu(self.vmmenu, self.vmmenu_items, idx, text, icon, cb)
|
||||||
def add_shutdown_menu(idx, text, icon, cb):
|
|
||||||
add_to_menu(self.vmmenushutdown, self.vmmenushutdown_items,
|
|
||||||
idx, text, icon, cb)
|
|
||||||
def add_conn_menu(idx, text, icon, cb):
|
def add_conn_menu(idx, text, icon, cb):
|
||||||
add_to_menu(self.connmenu, self.connmenu_items,
|
add_to_menu(self.connmenu, self.connmenu_items,
|
||||||
idx, text, icon, cb)
|
idx, text, icon, cb)
|
||||||
@ -352,15 +338,6 @@ class vmmManager(vmmGObjectUI):
|
|||||||
|
|
||||||
add_vm_menu("shutdown", _("_Shut Down"), shutdownmenu_icon, None)
|
add_vm_menu("shutdown", _("_Shut Down"), shutdownmenu_icon, None)
|
||||||
self.vmmenu_items["shutdown"].set_submenu(self.vmmenushutdown)
|
self.vmmenu_items["shutdown"].set_submenu(self.vmmenushutdown)
|
||||||
add_shutdown_menu("reboot", _("_Reboot"), reboot_icon, self.reboot_vm)
|
|
||||||
add_shutdown_menu("poweroff", _("_Shut Down"), shutdown_icon,
|
|
||||||
self.poweroff_vm)
|
|
||||||
add_shutdown_menu("forcereset", _("_Force Reset"), reset_icon,
|
|
||||||
self.reset_vm)
|
|
||||||
add_shutdown_menu("forcepoweroff", _("_Force Off"), destroy_icon,
|
|
||||||
self.destroy_vm)
|
|
||||||
add_sep(self.vmmenushutdown, self.vmmenushutdown_items, "sep")
|
|
||||||
add_shutdown_menu("save", _("Sa_ve"), save_icon, self.save_vm)
|
|
||||||
|
|
||||||
add_sep(self.vmmenu, self.vmmenu_items, "hsep1")
|
add_sep(self.vmmenu, self.vmmenu_items, "hsep1")
|
||||||
add_vm_menu("clone", _("_Clone..."), None, self.open_clone_window)
|
add_vm_menu("clone", _("_Clone..."), None, self.open_clone_window)
|
||||||
@ -617,36 +594,12 @@ class vmmManager(vmmGObjectUI):
|
|||||||
self.emit("action-run-domain",
|
self.emit("action-run-domain",
|
||||||
vm.conn.get_uri(), vm.get_uuid())
|
vm.conn.get_uri(), vm.get_uuid())
|
||||||
|
|
||||||
def reboot_vm(self, ignore):
|
|
||||||
vm = self.current_vm()
|
|
||||||
if vm is not None:
|
|
||||||
self.emit("action-reboot-domain",
|
|
||||||
vm.conn.get_uri(), vm.get_uuid())
|
|
||||||
|
|
||||||
def poweroff_vm(self, ignore):
|
def poweroff_vm(self, ignore):
|
||||||
vm = self.current_vm()
|
vm = self.current_vm()
|
||||||
if vm is not None:
|
if vm is not None:
|
||||||
self.emit("action-shutdown-domain",
|
self.emit("action-shutdown-domain",
|
||||||
vm.conn.get_uri(), vm.get_uuid())
|
vm.conn.get_uri(), vm.get_uuid())
|
||||||
|
|
||||||
def destroy_vm(self, ignore):
|
|
||||||
vm = self.current_vm()
|
|
||||||
if vm is not None:
|
|
||||||
self.emit("action-destroy-domain",
|
|
||||||
vm.conn.get_uri(), vm.get_uuid())
|
|
||||||
|
|
||||||
def reset_vm(self, ignore):
|
|
||||||
vm = self.current_vm()
|
|
||||||
if vm is not None:
|
|
||||||
self.emit("action-reset-domain",
|
|
||||||
vm.conn.get_uri(), vm.get_uuid())
|
|
||||||
|
|
||||||
def save_vm(self, ignore):
|
|
||||||
vm = self.current_vm()
|
|
||||||
if vm is not None:
|
|
||||||
self.emit("action-save-domain",
|
|
||||||
vm.conn.get_uri(), vm.get_uuid())
|
|
||||||
|
|
||||||
def pause_vm(self, ignore):
|
def pause_vm(self, ignore):
|
||||||
vm = self.current_vm()
|
vm = self.current_vm()
|
||||||
if vm is not None:
|
if vm is not None:
|
||||||
@ -980,6 +933,8 @@ class vmmManager(vmmGObjectUI):
|
|||||||
self.widget("vm-open").set_sensitive(show_open)
|
self.widget("vm-open").set_sensitive(show_open)
|
||||||
self.widget("vm-run").set_sensitive(show_run)
|
self.widget("vm-run").set_sensitive(show_run)
|
||||||
self.widget("vm-shutdown").set_sensitive(show_shutdown)
|
self.widget("vm-shutdown").set_sensitive(show_shutdown)
|
||||||
|
self.widget("vm-shutdown").get_menu().update_widget_states(vm)
|
||||||
|
|
||||||
self.set_pause_state(is_paused)
|
self.set_pause_state(is_paused)
|
||||||
self.widget("vm-pause").set_sensitive(show_pause)
|
self.widget("vm-pause").set_sensitive(show_pause)
|
||||||
|
|
||||||
@ -1015,7 +970,6 @@ class vmmManager(vmmGObjectUI):
|
|||||||
# Popup the vm menu
|
# Popup the vm menu
|
||||||
vm = model.get_value(_iter, ROW_HANDLE)
|
vm = model.get_value(_iter, ROW_HANDLE)
|
||||||
|
|
||||||
destroy = vm.is_destroyable()
|
|
||||||
run = vm.is_runable()
|
run = vm.is_runable()
|
||||||
stop = vm.is_stoppable()
|
stop = vm.is_stoppable()
|
||||||
paused = vm.is_paused()
|
paused = vm.is_paused()
|
||||||
@ -1029,11 +983,8 @@ class vmmManager(vmmGObjectUI):
|
|||||||
self.vmmenu_items["resume"].set_sensitive(paused)
|
self.vmmenu_items["resume"].set_sensitive(paused)
|
||||||
self.vmmenu_items["migrate"].set_sensitive(stop)
|
self.vmmenu_items["migrate"].set_sensitive(stop)
|
||||||
self.vmmenu_items["clone"].set_sensitive(not ro)
|
self.vmmenu_items["clone"].set_sensitive(not ro)
|
||||||
|
self.vmmenushutdown.update_widget_states(vm)
|
||||||
|
|
||||||
self.vmmenushutdown_items["poweroff"].set_sensitive(stop)
|
|
||||||
self.vmmenushutdown_items["reboot"].set_sensitive(stop)
|
|
||||||
self.vmmenushutdown_items["forcepoweroff"].set_sensitive(destroy)
|
|
||||||
self.vmmenushutdown_items["save"].set_sensitive(destroy)
|
|
||||||
self.vmmenu.popup(None, None, None, None, 0, event.time)
|
self.vmmenu.popup(None, None, None, None, 0, event.time)
|
||||||
else:
|
else:
|
||||||
# Pop up connection menu
|
# Pop up connection menu
|
||||||
|
@ -25,6 +25,7 @@ from gi.repository import GObject
|
|||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
# pylint: enable=E0611
|
# pylint: enable=E0611
|
||||||
|
|
||||||
|
from virtManager import uihelpers
|
||||||
from virtManager.baseclass import vmmGObject
|
from virtManager.baseclass import vmmGObject
|
||||||
from virtManager.error import vmmErrorDialog
|
from virtManager.error import vmmErrorDialog
|
||||||
|
|
||||||
@ -57,6 +58,7 @@ class vmmSystray(vmmGObject):
|
|||||||
"action-reset-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
|
"action-reset-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
|
||||||
"action-reboot-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
|
"action-reboot-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
|
||||||
"action-destroy-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
|
"action-destroy-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
|
||||||
|
"action-save-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
|
||||||
"action-show-host": (GObject.SignalFlags.RUN_FIRST, None, [str]),
|
"action-show-host": (GObject.SignalFlags.RUN_FIRST, None, [str]),
|
||||||
"action-show-vm": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
|
"action-show-vm": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
|
||||||
"action-exit-app": (GObject.SignalFlags.RUN_FIRST, None, []),
|
"action-exit-app": (GObject.SignalFlags.RUN_FIRST, None, []),
|
||||||
@ -194,45 +196,11 @@ class vmmSystray(vmmGObject):
|
|||||||
"action-run-domain", vm.get_uuid())
|
"action-run-domain", vm.get_uuid())
|
||||||
|
|
||||||
# Shutdown menu
|
# Shutdown menu
|
||||||
reboot_item = Gtk.ImageMenuItem.new_with_mnemonic(_("_Reboot"))
|
shutdown_menu = uihelpers.VMShutdownMenu(self, lambda: vm)
|
||||||
reboot_img = Gtk.Image.new_from_icon_name("system-shutdown", icon_size)
|
shutdown_menu_item = Gtk.ImageMenuItem.new_with_mnemonic(
|
||||||
reboot_item.set_image(reboot_img)
|
_("_Shut Down"))
|
||||||
reboot_item.connect("activate", self.run_vm_action,
|
shutdown_menu_item.set_image(Gtk.Image.new_from_icon_name(
|
||||||
"action-reboot-domain", vm.get_uuid())
|
"system-shutdown", icon_size))
|
||||||
reboot_item.show()
|
|
||||||
|
|
||||||
shutdown_item = Gtk.ImageMenuItem.new_with_mnemonic(_("_Shut Down"))
|
|
||||||
shutdown_img = Gtk.Image.new_from_icon_name("system-shutdown",
|
|
||||||
icon_size)
|
|
||||||
shutdown_item.set_image(shutdown_img)
|
|
||||||
shutdown_item.connect("activate", self.run_vm_action,
|
|
||||||
"action-shutdown-domain", vm.get_uuid())
|
|
||||||
shutdown_item.show()
|
|
||||||
|
|
||||||
reset_item = Gtk.ImageMenuItem.new_with_mnemonic(_("_Force Reset"))
|
|
||||||
reset_img = Gtk.Image.new_from_icon_name("system-shutdown", icon_size)
|
|
||||||
reset_item.set_image(reset_img)
|
|
||||||
reset_item.show()
|
|
||||||
reset_item.connect("activate", self.run_vm_action,
|
|
||||||
"action-reset-domain", vm.get_uuid())
|
|
||||||
|
|
||||||
destroy_item = Gtk.ImageMenuItem.new_with_mnemonic(_("_Force Off"))
|
|
||||||
destroy_img = Gtk.Image.new_from_icon_name("system-shutdown",
|
|
||||||
icon_size)
|
|
||||||
destroy_item.set_image(destroy_img)
|
|
||||||
destroy_item.show()
|
|
||||||
destroy_item.connect("activate", self.run_vm_action,
|
|
||||||
"action-destroy-domain", vm.get_uuid())
|
|
||||||
|
|
||||||
shutdown_menu = Gtk.Menu()
|
|
||||||
shutdown_menu.add(reboot_item)
|
|
||||||
shutdown_menu.add(shutdown_item)
|
|
||||||
shutdown_menu.add(reset_item)
|
|
||||||
shutdown_menu.add(destroy_item)
|
|
||||||
shutdown_menu_item = Gtk.ImageMenuItem.new_with_mnemonic(_("_Shut Down"))
|
|
||||||
shutdown_menu_img = Gtk.Image.new_from_icon_name("system-shutdown",
|
|
||||||
icon_size)
|
|
||||||
shutdown_menu_item.set_image(shutdown_menu_img)
|
|
||||||
shutdown_menu_item.set_submenu(shutdown_menu)
|
shutdown_menu_item.set_submenu(shutdown_menu)
|
||||||
|
|
||||||
sep = Gtk.SeparatorMenuItem()
|
sep = Gtk.SeparatorMenuItem()
|
||||||
@ -247,10 +215,6 @@ class vmmSystray(vmmGObject):
|
|||||||
vm_action_dict["pause"] = pause_item
|
vm_action_dict["pause"] = pause_item
|
||||||
vm_action_dict["resume"] = resume_item
|
vm_action_dict["resume"] = resume_item
|
||||||
vm_action_dict["shutdown_menu"] = shutdown_menu_item
|
vm_action_dict["shutdown_menu"] = shutdown_menu_item
|
||||||
vm_action_dict["reboot"] = reboot_item
|
|
||||||
vm_action_dict["shutdown"] = shutdown_item
|
|
||||||
vm_action_dict["reset"] = reset_item
|
|
||||||
vm_action_dict["destroy"] = destroy_item
|
|
||||||
vm_action_dict["sep"] = sep
|
vm_action_dict["sep"] = sep
|
||||||
vm_action_dict["open"] = open_item
|
vm_action_dict["open"] = open_item
|
||||||
|
|
||||||
@ -436,10 +400,7 @@ class vmmSystray(vmmGObject):
|
|||||||
actions["pause"].set_sensitive(vm.is_pauseable())
|
actions["pause"].set_sensitive(vm.is_pauseable())
|
||||||
actions["resume"].set_sensitive(vm.is_paused())
|
actions["resume"].set_sensitive(vm.is_paused())
|
||||||
actions["shutdown_menu"].set_sensitive(vm.is_active())
|
actions["shutdown_menu"].set_sensitive(vm.is_active())
|
||||||
actions["shutdown"].set_sensitive(vm.is_stoppable())
|
actions["shutdown_menu"].get_submenu().update_widget_states(vm)
|
||||||
actions["reboot"].set_sensitive(vm.is_stoppable())
|
|
||||||
actions["reset"].set_sensitive(vm.is_destroyable())
|
|
||||||
actions["destroy"].set_sensitive(vm.is_destroyable())
|
|
||||||
|
|
||||||
actions["pause"].set_visible(not is_paused)
|
actions["pause"].set_visible(not is_paused)
|
||||||
actions["resume"].set_visible(is_paused)
|
actions["resume"].set_visible(is_paused)
|
||||||
|
@ -908,55 +908,54 @@ def mediadev_set_default_selection(widget):
|
|||||||
# Build toolbar shutdown button menu (manager and details toolbar) #
|
# Build toolbar shutdown button menu (manager and details toolbar) #
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
||||||
def build_shutdown_button_menu(widget, shutdown_cb, reboot_cb, reset_cb,
|
class VMShutdownMenu(Gtk.Menu):
|
||||||
destroy_cb, save_cb):
|
# pylint: disable=E1101
|
||||||
widget.set_icon_name("system-shutdown")
|
# pylint can't detect functions we inheirit from Gtk, ex self.add
|
||||||
menu = Gtk.Menu()
|
|
||||||
widget.set_menu(menu)
|
|
||||||
|
|
||||||
rebootimg = Gtk.Image.new_from_icon_name("system-shutdown",
|
def __init__(self, src, current_vm_cb):
|
||||||
Gtk.IconSize.MENU)
|
Gtk.Menu.__init__(self)
|
||||||
shutdownimg = Gtk.Image.new_from_icon_name("system-shutdown",
|
self._parent = src
|
||||||
Gtk.IconSize.MENU)
|
self._current_vm_cb = current_vm_cb
|
||||||
destroyimg = Gtk.Image.new_from_icon_name("system-shutdown",
|
self._init_state()
|
||||||
Gtk.IconSize.MENU)
|
|
||||||
resetimg = Gtk.Image.new_from_icon_name("system-shutdown",
|
|
||||||
Gtk.IconSize.MENU)
|
|
||||||
saveimg = Gtk.Image.new_from_icon_name(Gtk.STOCK_SAVE, Gtk.IconSize.MENU)
|
|
||||||
|
|
||||||
reboot = Gtk.ImageMenuItem.new_with_mnemonic(_("_Reboot"))
|
def _init_state(self):
|
||||||
reboot.set_image(rebootimg)
|
def _add_action(label, signal, iconname="system-shutdown"):
|
||||||
reboot.show()
|
item = Gtk.ImageMenuItem.new_with_mnemonic(label)
|
||||||
reboot.connect("activate", reboot_cb)
|
icon = Gtk.Image.new_from_icon_name(iconname, Gtk.IconSize.MENU)
|
||||||
menu.add(reboot)
|
item.set_image(icon)
|
||||||
|
item.connect("activate", self._action_cb)
|
||||||
|
item.vmm_widget_name = signal
|
||||||
|
self.add(item)
|
||||||
|
|
||||||
shutdown = Gtk.ImageMenuItem.new_with_mnemonic(_("_Shut Down"))
|
_add_action(_("_Reboot"), "reboot")
|
||||||
shutdown.set_image(shutdownimg)
|
_add_action(_("_Shut Down"), "shutdown")
|
||||||
shutdown.show()
|
_add_action(_("F_orce Reset"), "reset")
|
||||||
shutdown.connect("activate", shutdown_cb)
|
_add_action(_("_Force Off"), "destroy")
|
||||||
menu.add(shutdown)
|
self.add(Gtk.SeparatorMenuItem())
|
||||||
|
_add_action(_("Sa_ve"), "save", iconname=Gtk.STOCK_SAVE)
|
||||||
|
|
||||||
reset = Gtk.ImageMenuItem.new_with_mnemonic(_("_Force Reset"))
|
self.show_all()
|
||||||
reset.set_image(resetimg)
|
|
||||||
reset.show()
|
|
||||||
reset.connect("activate", reset_cb)
|
|
||||||
menu.add(reset)
|
|
||||||
|
|
||||||
destroy = Gtk.ImageMenuItem.new_with_mnemonic(_("_Force Off"))
|
def _action_cb(self, src):
|
||||||
destroy.set_image(destroyimg)
|
vm = self._current_vm_cb()
|
||||||
destroy.show()
|
if not vm:
|
||||||
destroy.connect("activate", destroy_cb)
|
return
|
||||||
menu.add(destroy)
|
self._parent.emit("action-%s-domain" % src.vmm_widget_name,
|
||||||
|
vm.conn.get_uri(), vm.get_uuid())
|
||||||
|
|
||||||
sep = Gtk.SeparatorMenuItem()
|
def update_widget_states(self, vm):
|
||||||
sep.show()
|
statemap = {
|
||||||
menu.add(sep)
|
"reboot": bool(vm and vm.is_stoppable()),
|
||||||
|
"shutdown": bool(vm and vm.is_stoppable()),
|
||||||
|
"reset": bool(vm and vm.is_stoppable()),
|
||||||
|
"save": bool(vm and vm.is_destroyable()),
|
||||||
|
"destroy": bool(vm and vm.is_destroyable()),
|
||||||
|
}
|
||||||
|
|
||||||
save = Gtk.ImageMenuItem.new_with_mnemonic(_("Sa_ve"))
|
for child in self.get_children():
|
||||||
save.set_image(saveimg)
|
name = getattr(child, "vmm_widget_name", None)
|
||||||
save.show()
|
if name in statemap:
|
||||||
save.connect("activate", save_cb)
|
child.set_sensitive(statemap[name])
|
||||||
menu.add(save)
|
|
||||||
|
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
|
Loading…
Reference in New Issue
Block a user