mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-11 05:17:59 +03:00
uiutil: Use list selection helpers everywhere
This commit is contained in:
parent
2771511946
commit
889ec18031
@ -1022,18 +1022,16 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
return diskpath
|
||||
|
||||
def get_config_disk_bus(self):
|
||||
widget = self.widget("config-storage-bustype")
|
||||
if widget.get_active() == -1:
|
||||
return None
|
||||
return widget.get_model()[widget.get_active()][0]
|
||||
return uiutil.get_list_selection(
|
||||
self.widget("config-storage-bustype"), 0)
|
||||
|
||||
def get_config_disk_device(self):
|
||||
widget = self.widget("config-storage-devtype")
|
||||
return widget.get_model()[widget.get_active()][0]
|
||||
return uiutil.get_list_selection(
|
||||
self.widget("config-storage-devtype"), 0)
|
||||
|
||||
def get_config_disk_cache(self):
|
||||
widget = self.widget("config-storage-cache")
|
||||
return widget.get_model()[widget.get_active()][0]
|
||||
return uiutil.get_list_selection(
|
||||
self.widget("config-storage-cache"), 0)
|
||||
|
||||
def get_config_disk_format(self):
|
||||
fmt = self.widget("config-storage-format")
|
||||
@ -1041,18 +1039,12 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
|
||||
# Input getters
|
||||
def get_config_input(self):
|
||||
target = self.widget("input-type")
|
||||
label = target.get_model().get_value(target.get_active_iter(), 0)
|
||||
_type = target.get_model().get_value(target.get_active_iter(), 1)
|
||||
bus = target.get_model().get_value(target.get_active_iter(), 2)
|
||||
return label, _type, bus
|
||||
row = uiutil.get_list_selection(self.widget("input-type"))
|
||||
return row[1], row[2]
|
||||
|
||||
# Graphics getters
|
||||
def get_config_graphics(self):
|
||||
_type = self.widget("graphics-type")
|
||||
if _type.get_active_iter() is None:
|
||||
return None
|
||||
return _type.get_model().get_value(_type.get_active_iter(), 1)
|
||||
return uiutil.get_list_selection(self.widget("graphics-type"), 1)
|
||||
|
||||
def get_config_graphics_ports(self):
|
||||
if self.widget("graphics-port-auto").get_active():
|
||||
@ -1065,8 +1057,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
return int(port), int(tlsport)
|
||||
|
||||
def get_config_graphics_address(self):
|
||||
addr = self.widget("graphics-address")
|
||||
return addr.get_model()[addr.get_active()][1]
|
||||
return uiutil.get_list_selection(self.widget("graphics-address"), 1)
|
||||
|
||||
def get_config_graphics_password(self):
|
||||
if not self.widget("graphics-password-chk").get_active():
|
||||
@ -1084,13 +1075,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
return net_type, net_src
|
||||
|
||||
def get_config_net_model(self):
|
||||
model = self.widget("net-model")
|
||||
if model.get_active_iter():
|
||||
modelxml = model.get_model().get_value(model.get_active_iter(), 0)
|
||||
modelstr = model.get_model().get_value(model.get_active_iter(), 1)
|
||||
else:
|
||||
modelxml = modelstr = None
|
||||
return modelxml, modelstr
|
||||
return uiutil.get_list_selection(self.widget("net-model"))[0]
|
||||
|
||||
def get_config_macaddr(self):
|
||||
macaddr = None
|
||||
@ -1100,9 +1085,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
|
||||
# Sound getters
|
||||
def get_config_sound_model(self):
|
||||
model = self.widget("sound-model")
|
||||
modelstr = model.get_model().get_value(model.get_active_iter(), 0)
|
||||
return modelstr
|
||||
return uiutil.get_list_selection(self.widget("sound-model"), 0)
|
||||
|
||||
# Host device getters
|
||||
def get_config_host_device_type_info(self):
|
||||
@ -1115,29 +1098,21 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
return usb_info
|
||||
|
||||
def get_config_host_device_info(self):
|
||||
devrow = uiutil.get_list_selection(self.widget("host-device"))
|
||||
if not devrow:
|
||||
return []
|
||||
return devrow
|
||||
return uiutil.get_list_selection(self.widget("host-device"))
|
||||
|
||||
# Video Getters
|
||||
def get_config_video_model(self):
|
||||
modbox = self.widget("video-model")
|
||||
return modbox.get_model()[modbox.get_active()][0]
|
||||
return uiutil.get_list_selection(self.widget("video-model"), 0)
|
||||
|
||||
# Watchdog getters
|
||||
def get_config_watchdog_model(self):
|
||||
modbox = self.widget("watchdog-model")
|
||||
return modbox.get_model()[modbox.get_active()][0]
|
||||
return uiutil.get_list_selection(self.widget("watchdog-model"), 0)
|
||||
def get_config_watchdog_action(self):
|
||||
modbox = self.widget("watchdog-action")
|
||||
return modbox.get_model()[modbox.get_active()][0]
|
||||
return uiutil.get_list_selection(self.widget("watchdog-action"), 0)
|
||||
|
||||
# Smartcard getters
|
||||
def get_config_smartcard_mode(self):
|
||||
mode = self.widget("smartcard-mode")
|
||||
modestr = mode.get_model().get_value(mode.get_active_iter(), 0)
|
||||
return modestr
|
||||
return uiutil.get_list_selection(self.widget("smartcard-mode"), 0)
|
||||
|
||||
# USB redir getters
|
||||
def get_config_usbredir_host(self):
|
||||
@ -1149,24 +1124,15 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
return host.get_text(), int(service.get_value())
|
||||
|
||||
def get_config_usbredir_type(self):
|
||||
typebox = self.widget("usbredir-list")
|
||||
return typebox.get_model()[typebox.get_active()][0]
|
||||
return uiutil.get_list_selection(self.widget("usbredir-list"), 0)
|
||||
|
||||
# TPM getters
|
||||
def get_config_tpm_type(self):
|
||||
typ = self.widget("tpm-type")
|
||||
typestr = typ.get_model().get_value(typ.get_active_iter(), 0)
|
||||
return typestr
|
||||
return uiutil.get_list_selection(self.widget("tpm-type"), 0)
|
||||
|
||||
# RNG getters
|
||||
def get_config_rng_type(self):
|
||||
src = self.widget("rng-type")
|
||||
idx = src.get_active()
|
||||
if idx < 0:
|
||||
return None
|
||||
|
||||
selected_type = src.get_model()[idx][0]
|
||||
return selected_type
|
||||
return uiutil.get_list_selection(self.widget("rng-type"), 0)
|
||||
|
||||
def get_config_rng_device(self):
|
||||
if self.get_config_rng_type() == virtinst.VirtualRNGDevice.TYPE_RANDOM:
|
||||
@ -1202,18 +1168,10 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
return None
|
||||
|
||||
def get_config_rng_backend_type(self):
|
||||
active = self.widget("rng-backend-type").get_active()
|
||||
model = self.widget("rng-backend-type").get_model()
|
||||
if active < 0:
|
||||
return None
|
||||
return model[active][0]
|
||||
return uiutil.get_list_selection(self.widget("rng-backend-type"), 0)
|
||||
|
||||
def get_config_rng_backend_mode(self):
|
||||
active = self.widget("rng-backend-mode").get_active()
|
||||
model = self.widget("rng-backend-mode").get_model()
|
||||
if active < 0:
|
||||
return None
|
||||
return model[active][0]
|
||||
return uiutil.get_list_selection(self.widget("rng-backend-mode"), 0)
|
||||
|
||||
################
|
||||
# UI listeners #
|
||||
@ -1379,18 +1337,15 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
self.widget("page-title-label").set_markup(markup)
|
||||
|
||||
def change_tpm_device_type(self, src):
|
||||
idx = src.get_active()
|
||||
if idx < 0:
|
||||
devtype = uiutil.get_list_selection(src, 0)
|
||||
if devtype is None:
|
||||
return
|
||||
|
||||
tpm_widget_mappings = {
|
||||
"device_path" : "tpm-device-path",
|
||||
}
|
||||
|
||||
devtype = src.get_model()[src.get_active()][0]
|
||||
conn = self.conn.get_backend()
|
||||
|
||||
self._dev = VirtualTPMDevice(conn)
|
||||
self._dev = VirtualTPMDevice(self.conn.get_backend())
|
||||
self._dev.type = devtype
|
||||
|
||||
for param_name, widget_name in tpm_widget_mappings.items():
|
||||
@ -1420,8 +1375,8 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
uiutil.set_row_selection(self.widget("char-device-type"), settype)
|
||||
|
||||
def change_char_device_type(self, src):
|
||||
idx = src.get_active()
|
||||
if idx < 0:
|
||||
devtype = uiutil.get_list_selection(src, 0)
|
||||
if devtype is None:
|
||||
return
|
||||
|
||||
char_widget_mappings = {
|
||||
@ -1433,14 +1388,12 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
}
|
||||
|
||||
char_class = self.get_char_type()
|
||||
devtype = src.get_model()[src.get_active()][0]
|
||||
conn = self.conn.get_backend()
|
||||
ischan = char_class.virtual_device_type == "channel"
|
||||
iscon = char_class.virtual_device_type == "console"
|
||||
show_auto = (devtype == "unix" and ischan and
|
||||
self.conn.check_support(self.conn.SUPPORT_CONN_AUTOSOCKET))
|
||||
|
||||
self._dev = char_class(conn)
|
||||
self._dev = char_class(self.conn.get_backend())
|
||||
self._dev.type = devtype
|
||||
|
||||
for param_name, widget_name in char_widget_mappings.items():
|
||||
@ -1461,11 +1414,9 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
self.widget("char-mode").set_active(0)
|
||||
|
||||
def change_usbredir_type(self, src):
|
||||
idx = src.get_active()
|
||||
if idx < 0:
|
||||
showhost = uiutil.get_list_selection(src, 2)
|
||||
if showhost is None:
|
||||
return
|
||||
|
||||
showhost = src.get_model()[src.get_active()][2]
|
||||
uiutil.set_grid_row_visible(self.widget("usbredir-host-box"),
|
||||
showhost)
|
||||
|
||||
@ -1746,7 +1697,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
def validate_page_network(self):
|
||||
nettype, devname = self.get_config_network()
|
||||
mac = self.get_config_macaddr()
|
||||
model = self.get_config_net_model()[0]
|
||||
model = self.get_config_net_model()
|
||||
|
||||
if not nettype:
|
||||
return self.err.val_err(_("Network selection error."),
|
||||
@ -1764,7 +1715,7 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
self._dev = ret
|
||||
|
||||
def validate_page_input(self):
|
||||
ignore, inp_type, inp_bus = self.get_config_input()
|
||||
inp_type, inp_bus = self.get_config_input()
|
||||
dev = virtinst.VirtualInputDevice(self.conn.get_backend())
|
||||
dev.type = inp_type
|
||||
dev.bus = inp_bus
|
||||
@ -1795,16 +1746,15 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
return self.err.val_err(_("Sound device parameter error"), e)
|
||||
|
||||
def validate_page_hostdev(self):
|
||||
ret = self.get_config_host_device_info()
|
||||
nodedev_name = ret and ret[1] or None
|
||||
row = self.get_config_host_device_info()
|
||||
is_dup = False
|
||||
|
||||
if nodedev_name is None:
|
||||
if row is None:
|
||||
return self.err.val_err(_("Physical Device Required"),
|
||||
_("A device must be selected."))
|
||||
|
||||
devtype = ret[2]
|
||||
nodedev = ret[3]
|
||||
devtype = row[2]
|
||||
nodedev = row[3]
|
||||
if devtype == "usb_device":
|
||||
vendor = nodedev.vendor_id
|
||||
product = nodedev.product_id
|
||||
@ -1828,20 +1778,20 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
modebox = self.widget("char-mode")
|
||||
devbox = self.widget("char-device-type")
|
||||
typebox = self.widget("char-target-type")
|
||||
devtype = devbox.get_model()[devbox.get_active()][0]
|
||||
devtype = uiutil.get_list_selection(devbox, 0)
|
||||
conn = self.conn.get_backend()
|
||||
|
||||
devclass = charclass(conn)
|
||||
devclass.type = devtype
|
||||
|
||||
source_path = self.widget("char-path").get_text()
|
||||
source_mode = modebox.get_model()[modebox.get_active()][0]
|
||||
source_mode = uiutil.get_list_selection(modebox, 0)
|
||||
source_host = self.widget("char-host").get_text()
|
||||
bind_host = self.widget("char-bind-host").get_text()
|
||||
source_port = self.widget("char-port").get_value()
|
||||
bind_port = self.widget("char-bind-port").get_value()
|
||||
target_name = self.widget("char-target-name").get_child().get_text()
|
||||
target_type = typebox.get_model()[typebox.get_active()][0]
|
||||
target_type = uiutil.get_list_selection(typebox, 0)
|
||||
|
||||
if self.widget("char-use-telnet").get_active():
|
||||
protocol = VirtualSerialDevice.PROTOCOL_TELNET
|
||||
|
@ -24,6 +24,7 @@ import logging
|
||||
from gi.repository import GObject
|
||||
# pylint: enable=E0611
|
||||
|
||||
from virtManager import uiutil
|
||||
from virtManager import sharedui
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
from virtManager.mediadev import MEDIA_FLOPPY
|
||||
@ -94,16 +95,11 @@ class vmmChooseCD(vmmGObjectUI):
|
||||
self.widget("iso-image").set_active(True)
|
||||
|
||||
def ok(self, ignore1=None, ignore2=None):
|
||||
path = None
|
||||
|
||||
if self.widget("iso-image").get_active():
|
||||
path = self.widget("iso-path").get_text()
|
||||
else:
|
||||
cd = self.widget("cd-path")
|
||||
idx = cd.get_active()
|
||||
model = cd.get_model()
|
||||
if idx != -1:
|
||||
path = model[idx][sharedui.OPTICAL_DEV_PATH]
|
||||
path = uiutil.get_list_selection(self.widget("cd-path"),
|
||||
sharedui.OPTICAL_DEV_PATH)
|
||||
|
||||
if path == "" or path is None:
|
||||
return self.err.val_err(_("Invalid Media Path"),
|
||||
|
@ -984,11 +984,8 @@ class vmmCreate(vmmGObjectUI):
|
||||
return self.widget("create-vm-name").get_text()
|
||||
|
||||
def get_config_machine(self):
|
||||
lst = self.widget("config-machine")
|
||||
idx = lst.get_active()
|
||||
if not lst.get_visible() or idx == -1:
|
||||
return None
|
||||
return lst.get_model()[idx][0]
|
||||
return uiutil.get_list_selection(self.widget("config-machine"),
|
||||
rowindex=0, check_visible=True)
|
||||
|
||||
def is_install_page(self):
|
||||
notebook = self.widget("create-pages")
|
||||
@ -1012,23 +1009,19 @@ class vmmCreate(vmmGObjectUI):
|
||||
return INSTALL_PAGE_CONTAINER_OS
|
||||
|
||||
def get_config_os_info(self):
|
||||
d_list = self.widget("install-os-type")
|
||||
d_idx = d_list.get_active()
|
||||
v_list = self.widget("install-os-version")
|
||||
v_idx = v_list.get_active()
|
||||
drow = uiutil.get_list_selection(self.widget("install-os-type"))
|
||||
vrow = uiutil.get_list_selection(self.widget("install-os-version"))
|
||||
distro = None
|
||||
dlabel = None
|
||||
variant = None
|
||||
vlabel = None
|
||||
|
||||
if d_idx >= 0:
|
||||
row = d_list.get_model()[d_idx]
|
||||
distro = row[0]
|
||||
dlabel = row[1]
|
||||
if v_idx >= 0:
|
||||
row = v_list.get_model()[v_idx]
|
||||
variant = row[0]
|
||||
vlabel = row[1]
|
||||
if drow:
|
||||
distro = drow[0]
|
||||
dlabel = drow[1]
|
||||
if vrow:
|
||||
variant = vrow[0]
|
||||
vlabel = vrow[1]
|
||||
|
||||
return (distro and str(distro),
|
||||
variant and str(variant),
|
||||
@ -1036,12 +1029,9 @@ class vmmCreate(vmmGObjectUI):
|
||||
|
||||
def get_config_local_media(self, store_media=False):
|
||||
if self.widget("install-local-cdrom").get_active():
|
||||
cd = self.widget("install-local-cdrom-combo")
|
||||
idx = cd.get_active()
|
||||
model = cd.get_model()
|
||||
if idx != -1:
|
||||
return model[idx][sharedui.OPTICAL_DEV_PATH]
|
||||
return None
|
||||
return uiutil.get_list_selection(
|
||||
self.widget("install-local-cdrom-combo"),
|
||||
sharedui.OPTICAL_DEV_PATH)
|
||||
else:
|
||||
ret = self.widget("install-local-box").get_child().get_text()
|
||||
if ret and store_media:
|
||||
@ -1132,13 +1122,9 @@ class vmmCreate(vmmGObjectUI):
|
||||
|
||||
# Listeners
|
||||
def conn_changed(self, src):
|
||||
idx = src.get_active()
|
||||
model = src.get_model()
|
||||
|
||||
if idx < 0:
|
||||
conn = None
|
||||
else:
|
||||
uri = model[idx][0]
|
||||
uri = uiutil.get_list_selection(src, 0)
|
||||
conn = None
|
||||
if uri:
|
||||
conn = self.engine.conns[uri]["conn"]
|
||||
|
||||
# If we aren't visible, let reset_state handle this for us, which
|
||||
@ -1163,13 +1149,11 @@ class vmmCreate(vmmGObjectUI):
|
||||
self.check_network_selection()
|
||||
|
||||
def check_network_selection(self):
|
||||
src = self.widget("config-netdev")
|
||||
idx = src.get_active()
|
||||
row = uiutil.get_list_selection(self.widget("config-netdev"))
|
||||
show_pxe_warn = True
|
||||
pxe_install = (self.get_config_install_page() == INSTALL_PAGE_PXE)
|
||||
|
||||
if not idx < 0:
|
||||
row = src.get_model()[idx]
|
||||
if row:
|
||||
ntype = row[0]
|
||||
key = row[6]
|
||||
|
||||
@ -1189,21 +1173,18 @@ class vmmCreate(vmmGObjectUI):
|
||||
_("Network selection does not support PXE"), False)
|
||||
|
||||
def hv_changed(self, src):
|
||||
idx = src.get_active()
|
||||
if idx < 0:
|
||||
hv = uiutil.get_list_selection(src, 1)
|
||||
if not hv:
|
||||
return
|
||||
|
||||
row = src.get_model()[idx]
|
||||
|
||||
self.change_caps(row[1])
|
||||
self.change_caps(hv)
|
||||
self.populate_arch()
|
||||
|
||||
def arch_changed(self, src):
|
||||
idx = src.get_active()
|
||||
if idx < 0:
|
||||
arch = uiutil.get_list_selection(src, 0)
|
||||
if not arch:
|
||||
return
|
||||
|
||||
arch = src.get_model()[idx][0]
|
||||
self.change_caps(self.capsguest.os_type, arch)
|
||||
|
||||
def url_box_changed(self, ignore):
|
||||
@ -1237,13 +1218,7 @@ class vmmCreate(vmmGObjectUI):
|
||||
self.detect_media_os()
|
||||
|
||||
def _selected_os_row(self):
|
||||
box = self.widget("install-os-type")
|
||||
model = box.get_model()
|
||||
idx = box.get_active()
|
||||
if idx == -1:
|
||||
return None
|
||||
|
||||
return model[idx]
|
||||
return uiutil.get_list_selection(self.widget("install-os-type"))
|
||||
|
||||
def change_os_type(self, box):
|
||||
ignore = box
|
||||
@ -1260,28 +1235,22 @@ class vmmCreate(vmmGObjectUI):
|
||||
variant.set_active(0)
|
||||
|
||||
def change_os_version(self, box):
|
||||
model = box.get_model()
|
||||
idx = box.get_active()
|
||||
if idx == -1:
|
||||
show_all = uiutil.get_list_selection(box, 3)
|
||||
if not show_all:
|
||||
return
|
||||
|
||||
# Get previous
|
||||
os_type_list = self.widget("install-os-type")
|
||||
os_type_model = os_type_list.get_model()
|
||||
type_row = self._selected_os_row()
|
||||
if not type_row:
|
||||
return
|
||||
os_type = type_row[0]
|
||||
|
||||
show_all = model[idx][3]
|
||||
if not show_all:
|
||||
return
|
||||
|
||||
self.show_all_os = True
|
||||
self.populate_os_type_model()
|
||||
|
||||
os_type_list = self.widget("install-os-type")
|
||||
os_type_model = os_type_list.get_model()
|
||||
for idx in range(len(os_type_model)):
|
||||
if os_type_model[idx][0] == os_type:
|
||||
if os_type_model[idx][0] == type_row[0]:
|
||||
os_type_list.set_active(idx)
|
||||
break
|
||||
|
||||
|
@ -588,8 +588,7 @@ class vmmCreateInterface(vmmGObjectUI):
|
||||
#########################
|
||||
|
||||
def get_config_interface_type(self):
|
||||
type_list = self.widget("interface-type")
|
||||
return type_list.get_model()[type_list.get_active()][0]
|
||||
return uiutil.get_list_selection(self.widget("interface-type"), 0)
|
||||
|
||||
def set_interface_name(self, name):
|
||||
if self.widget("interface-name-entry").get_visible():
|
||||
@ -606,8 +605,7 @@ class vmmCreateInterface(vmmGObjectUI):
|
||||
return self.widget("interface-name-label").get_text()
|
||||
|
||||
def get_config_interface_startmode(self):
|
||||
start_list = self.widget("interface-startmode")
|
||||
return start_list.get_model()[start_list.get_active()][0]
|
||||
return uiutil.get_list_selection(self.widget("interface-startmode"), 0)
|
||||
|
||||
def get_config_selected_interfaces(self):
|
||||
iface_list = self.widget("interface-list")
|
||||
@ -672,8 +670,7 @@ class vmmCreateInterface(vmmGObjectUI):
|
||||
self.set_interface_name(name)
|
||||
|
||||
def bond_monitor_mode_changed(self, src):
|
||||
model = src.get_model()
|
||||
value = model[src.get_active()][1]
|
||||
value = uiutil.get_list_selection(src, 1)
|
||||
bond_pages = self.widget("bond-pages")
|
||||
|
||||
if value == "arpmon":
|
||||
@ -707,13 +704,8 @@ class vmmCreateInterface(vmmGObjectUI):
|
||||
self.widget("bridge-config-label").set_text(txt)
|
||||
|
||||
def update_bond_desc(self):
|
||||
mode_list = self.widget("bond-mode")
|
||||
model = mode_list.get_model()
|
||||
mode = model[mode_list.get_active()][0]
|
||||
|
||||
mon_list = self.widget("bond-monitor-mode")
|
||||
model = mon_list.get_model()
|
||||
mon = model[mon_list.get_active()][1]
|
||||
mode = uiutil.get_list_selection(self.widget("bond-mode"), 0)
|
||||
mon = uiutil.get_list_selection(self.widget("bond-monitor-mode"), 1)
|
||||
|
||||
txt = mode
|
||||
if mon:
|
||||
@ -765,13 +757,6 @@ class vmmCreateInterface(vmmGObjectUI):
|
||||
return self.build_ip_info()
|
||||
|
||||
def build_ip_info(self):
|
||||
def get_row(widget):
|
||||
combo = widget.get_model()
|
||||
active = widget.get_active()
|
||||
if active == -1:
|
||||
return None
|
||||
return combo[active]
|
||||
|
||||
def build_ip(addr_str):
|
||||
if not addr_str:
|
||||
return None, None
|
||||
@ -784,7 +769,8 @@ class vmmCreateInterface(vmmGObjectUI):
|
||||
|
||||
is_manual = self.widget("ip-do-manual").get_active()
|
||||
|
||||
copy_row = get_row(self.widget("ip-copy-interface-combo"))
|
||||
copy_row = uiutil.get_list_selection(
|
||||
self.widget("ip-copy-interface-combo"))
|
||||
|
||||
v4_mode = self.widget("ipv4-mode").get_active()
|
||||
v4_addr = self.widget("ipv4-address").get_text()
|
||||
@ -1017,21 +1003,10 @@ class vmmCreateInterface(vmmGObjectUI):
|
||||
|
||||
|
||||
def validate_bond(self, iobj, ifaces):
|
||||
mode_list = self.widget("bond-mode")
|
||||
model = mode_list.get_model()
|
||||
mode = model[mode_list.get_active()][1]
|
||||
|
||||
mon_list = self.widget("bond-monitor-mode")
|
||||
model = mon_list.get_model()
|
||||
mon = model[mon_list.get_active()][1]
|
||||
|
||||
val_list = self.widget("arp-validate")
|
||||
val_model = val_list.get_model()
|
||||
arp_val = val_model[val_list.get_active()][0]
|
||||
|
||||
car_list = self.widget("mii-carrier")
|
||||
car_model = car_list.get_model()
|
||||
mii_car = car_model[car_list.get_active()][0]
|
||||
mode = uiutil.get_list_selection(self.widget("bond-mode"), 1)
|
||||
mon = uiutil.get_list_selection(self.widget("bond-monitor-mode"), 1)
|
||||
arp_val = uiutil.get_list_selection(self.widget("arp-validate"), 0)
|
||||
mii_car = uiutil.get_list_selection(self.widget("mii-carrier"), 0)
|
||||
|
||||
# ARP params
|
||||
arp_int = self.widget("arp-interval").get_value()
|
||||
|
@ -221,13 +221,8 @@ class vmmCreateNetwork(vmmGObjectUI):
|
||||
if self.widget("net-forward-none").get_active():
|
||||
return [None, None]
|
||||
|
||||
dev = self.widget("net-forward")
|
||||
model = dev.get_model()
|
||||
active = dev.get_active()
|
||||
name = model[active][1]
|
||||
|
||||
mode_w = self.widget("net-forward-mode")
|
||||
mode = mode_w.get_model()[mode_w.get_active()][1]
|
||||
name = uiutil.get_list_selection(self.widget("net-forward"), 1)
|
||||
mode = uiutil.get_list_selection(self.widget("net-forward-mode"), 1)
|
||||
return [name, mode]
|
||||
|
||||
def get_config_routev4_network(self):
|
||||
|
@ -290,10 +290,7 @@ class vmmCreatePool(vmmGObjectUI):
|
||||
|
||||
|
||||
def get_config_type(self):
|
||||
typ = self.widget("pool-type")
|
||||
if typ.get_active_iter() is not None:
|
||||
return typ.get_model().get_value(typ.get_active_iter(), 0)
|
||||
return None
|
||||
return uiutil.get_list_selection(self.widget("pool-type"), 0)
|
||||
|
||||
def get_config_name(self):
|
||||
return self.widget("pool-name").get_text()
|
||||
@ -303,12 +300,9 @@ class vmmCreatePool(vmmGObjectUI):
|
||||
if not src.get_sensitive():
|
||||
return None
|
||||
|
||||
# If we provide the user with a drop down
|
||||
model = src.get_model()
|
||||
selection = src.get_active()
|
||||
if selection != -1:
|
||||
return model[selection][1]
|
||||
|
||||
ret = uiutil.get_list_selection(src, 1)
|
||||
if ret is not None:
|
||||
return ret
|
||||
return src.get_child().get_text()
|
||||
|
||||
def get_config_source_path(self):
|
||||
@ -316,12 +310,9 @@ class vmmCreatePool(vmmGObjectUI):
|
||||
if not src.get_sensitive():
|
||||
return None
|
||||
|
||||
# If we provide the user with a drop down
|
||||
model = src.get_model()
|
||||
selection = src.get_active()
|
||||
if selection != -1:
|
||||
return model[selection][1]
|
||||
|
||||
ret = uiutil.get_list_selection(src, 1)
|
||||
if ret is not None:
|
||||
return ret
|
||||
return src.get_child().get_text().strip()
|
||||
|
||||
def get_config_host(self):
|
||||
@ -331,12 +322,7 @@ class vmmCreatePool(vmmGObjectUI):
|
||||
return None
|
||||
|
||||
def get_config_format(self):
|
||||
format_combo = self.widget("pool-format")
|
||||
model = format_combo.get_model()
|
||||
if format_combo.get_active_iter() is not None:
|
||||
model = format_combo.get_model()
|
||||
return model.get_value(format_combo.get_active_iter(), 0)
|
||||
return None
|
||||
return uiutil.get_list_selection(self.widget("pool-format"), 0)
|
||||
|
||||
def get_config_iqn(self):
|
||||
iqn = self.widget("pool-iqn")
|
||||
@ -459,11 +445,9 @@ class vmmCreatePool(vmmGObjectUI):
|
||||
source_list = self.widget("pool-source-path")
|
||||
target_list = self.widget("pool-target-path")
|
||||
|
||||
pool = None
|
||||
if source_list.get_active() != -1:
|
||||
pool = source_list.get_model()[source_list.get_active()][2]
|
||||
elif target_list.get_active() != -1:
|
||||
pool = target_list.get_model()[target_list.get_active()][2]
|
||||
pool = uiutil.get_list_selection(source_list, 2)
|
||||
if pool is None:
|
||||
pool = uiutil.get_list_selection(target_list, 2)
|
||||
|
||||
return pool
|
||||
|
||||
|
@ -202,12 +202,7 @@ class vmmCreateVolume(vmmGObjectUI):
|
||||
|
||||
|
||||
def get_config_format(self):
|
||||
format_combo = self.widget("vol-format")
|
||||
model = format_combo.get_model()
|
||||
if format_combo.get_active_iter() is not None:
|
||||
model = format_combo.get_model()
|
||||
return model.get_value(format_combo.get_active_iter(), 0)
|
||||
return None
|
||||
return uiutil.get_list_selection(self.widget("vol-format"), 0)
|
||||
|
||||
def populate_vol_format(self):
|
||||
stable_whitelist = ["raw", "qcow2", "qed"]
|
||||
|
@ -112,14 +112,6 @@ class vmmDeleteDialog(vmmGObjectUI):
|
||||
uiutil.set_grid_row_visible(
|
||||
self.widget("delete-storage-scroll"), dodel)
|
||||
|
||||
def get_config_format(self):
|
||||
format_combo = self.widget("vol-format")
|
||||
model = format_combo.get_model()
|
||||
if format_combo.get_active_iter() is not None:
|
||||
model = format_combo.get_model()
|
||||
return model.get_value(format_combo.get_active_iter(), 0)
|
||||
return None
|
||||
|
||||
def get_paths_to_delete(self):
|
||||
del_list = self.widget("delete-storage-list")
|
||||
model = del_list.get_model()
|
||||
|
@ -1011,8 +1011,9 @@ class vmmDetails(vmmGObjectUI):
|
||||
|
||||
def get_combo_entry(self, widgetname):
|
||||
combo = self.widget(widgetname)
|
||||
if combo.get_active() >= 0:
|
||||
return combo.get_model()[combo.get_active()][0]
|
||||
ret = uiutil.get_list_selection(combo, 0)
|
||||
if ret:
|
||||
return ret
|
||||
if not combo.get_has_entry():
|
||||
return None
|
||||
return combo.get_child().get_text().strip()
|
||||
@ -1054,26 +1055,16 @@ class vmmDetails(vmmGObjectUI):
|
||||
else:
|
||||
self.widget("toolbar-box").hide()
|
||||
|
||||
def get_selected_row(self, widget):
|
||||
selection = widget.get_selection()
|
||||
model, treepath = selection.get_selected()
|
||||
if treepath is None:
|
||||
return None
|
||||
return model[treepath]
|
||||
|
||||
def get_boot_selection(self):
|
||||
return self.get_selected_row(self.widget("config-boot-list"))
|
||||
return uiutil.get_list_selection(self.widget("config-boot-list"))
|
||||
|
||||
def set_hw_selection(self, page, disable_apply=True):
|
||||
if disable_apply:
|
||||
self.disable_apply()
|
||||
|
||||
hwlist = self.widget("hw-list")
|
||||
selection = hwlist.get_selection()
|
||||
selection.select_path(str(page))
|
||||
uiutil.set_list_selection(self.widget("hw-list"), page)
|
||||
|
||||
def get_hw_row(self):
|
||||
return self.get_selected_row(self.widget("hw-list"))
|
||||
return uiutil.get_list_selection(self.widget("hw-list"))
|
||||
|
||||
def get_hw_selection(self, field):
|
||||
row = self.get_hw_row()
|
||||
|
@ -142,52 +142,28 @@ class vmmFSDetails(vmmGObjectUI):
|
||||
return self._dev
|
||||
|
||||
def get_config_fs_mode(self):
|
||||
name = "fs-mode-combo"
|
||||
combo = self.widget(name)
|
||||
if not combo.get_visible():
|
||||
return None
|
||||
|
||||
return combo.get_model()[combo.get_active()][0]
|
||||
return uiutil.get_list_selection(self.widget("fs-mode-combo"),
|
||||
rowindex=0, check_visible=True)
|
||||
|
||||
def get_config_fs_wrpolicy(self):
|
||||
name = "fs-wrpolicy-combo"
|
||||
combo = self.widget(name)
|
||||
if not combo.get_visible():
|
||||
return None
|
||||
|
||||
return combo.get_model()[combo.get_active()][0]
|
||||
return uiutil.get_list_selection(self.widget("fs-wrpolicy-combo"),
|
||||
rowindex=0, check_visible=True)
|
||||
|
||||
def get_config_fs_type(self):
|
||||
name = "fs-type-combo"
|
||||
combo = self.widget(name)
|
||||
if not combo.get_visible():
|
||||
return None
|
||||
|
||||
return combo.get_model()[combo.get_active()][0]
|
||||
return uiutil.get_list_selection(self.widget("fs-type-combo"),
|
||||
rowindex=0, check_visible=True)
|
||||
|
||||
def get_config_fs_readonly(self):
|
||||
name = "fs-readonly"
|
||||
check = self.widget(name)
|
||||
if not check.get_visible():
|
||||
return None
|
||||
|
||||
return check.get_active()
|
||||
return uiutil.get_list_selection(self.widget("fs-readonly"),
|
||||
rowindex=0, check_visible=True)
|
||||
|
||||
def get_config_fs_driver(self):
|
||||
name = "fs-driver-combo"
|
||||
combo = self.widget(name)
|
||||
if not combo.get_visible():
|
||||
return None
|
||||
|
||||
return combo.get_model()[combo.get_active()][0]
|
||||
return uiutil.get_list_selection(self.widget("fs-driver-combo"),
|
||||
rowindex=0, check_visible=True)
|
||||
|
||||
def get_config_fs_format(self):
|
||||
name = "fs-format-combo"
|
||||
combo = self.widget(name)
|
||||
if not combo.get_visible():
|
||||
return None
|
||||
|
||||
return combo.get_model()[combo.get_active()][0]
|
||||
return uiutil.get_list_selection(self.widget("fs-format-combo"),
|
||||
rowindex=0, check_visible=True)
|
||||
|
||||
# Setters
|
||||
def set_dev(self, dev):
|
||||
|
@ -507,18 +507,16 @@ class vmmHost(vmmGObjectUI):
|
||||
self.enable_net_apply(EDIT_NET_AUTOSTART)
|
||||
|
||||
def current_network(self):
|
||||
model, _iter = self.widget("net-list").get_selection().get_selected()
|
||||
if not _iter:
|
||||
return
|
||||
key = uiutil.get_list_selection(self.widget("net-list"), 0)
|
||||
try:
|
||||
return self.conn.get_net(model[_iter][0])
|
||||
return key and self.conn.get_net(key)
|
||||
except KeyError:
|
||||
return
|
||||
return None
|
||||
|
||||
def refresh_network(self, src_ignore, uuid):
|
||||
uilist = self.widget("net-list")
|
||||
sel = uilist.get_selection()
|
||||
active = sel.get_selected()
|
||||
model, treeiter = sel.get_selected()
|
||||
net = self.conn.get_net(uuid)
|
||||
net.tick()
|
||||
|
||||
@ -526,9 +524,8 @@ class vmmHost(vmmGObjectUI):
|
||||
if row[0] == uuid:
|
||||
row[4] = net.is_active()
|
||||
|
||||
if active[1] is not None:
|
||||
currname = active[0].get_value(active[1], 0)
|
||||
if currname == uuid:
|
||||
if treeiter is not None:
|
||||
if model[treeiter][0] == uuid:
|
||||
self.net_selected(sel)
|
||||
|
||||
def set_net_error_page(self, msg):
|
||||
@ -537,15 +534,14 @@ class vmmHost(vmmGObjectUI):
|
||||
self.widget("network-error-label").set_text(msg)
|
||||
|
||||
def net_selected(self, src):
|
||||
selected = src.get_selected()
|
||||
if (selected[1] is None or
|
||||
selected[0].get_value(selected[1], 0) is None):
|
||||
model, treeiter = src.get_selected()
|
||||
if treeiter is None:
|
||||
self.set_net_error_page(_("No virtual network selected."))
|
||||
return
|
||||
|
||||
self.widget("network-pages").set_current_page(0)
|
||||
try:
|
||||
net = self.conn.get_net(selected[0].get_value(selected[1], 0))
|
||||
net = self.conn.get_net(model[treeiter][0])
|
||||
except KeyError:
|
||||
self.disable_net_apply()
|
||||
return
|
||||
@ -808,24 +804,22 @@ class vmmHost(vmmGObjectUI):
|
||||
self.refresh_storage_pool(None, cp.get_uuid())
|
||||
|
||||
def current_pool(self):
|
||||
model, _iter = self.widget("pool-list").get_selection().get_selected()
|
||||
if not _iter:
|
||||
return
|
||||
key = uiutil.get_list_selection(self.widget("pool-list"), 0)
|
||||
try:
|
||||
return self.conn.get_pool(model[_iter][0])
|
||||
return key and self.conn.get_pool(key)
|
||||
except KeyError:
|
||||
return
|
||||
return None
|
||||
|
||||
def current_vol(self):
|
||||
pool = self.current_pool()
|
||||
if not pool:
|
||||
return None
|
||||
sel = self.widget("vol-list").get_selection()
|
||||
active = sel.get_selected()
|
||||
if active[1] is not None:
|
||||
curruuid = active[0].get_value(active[1], 0)
|
||||
return pool.get_volume(curruuid)
|
||||
return None
|
||||
|
||||
key = uiutil.get_list_selection(self.widget("vol-list"), 0)
|
||||
try:
|
||||
return key and pool.get_volume(key)
|
||||
except KeyError:
|
||||
return None
|
||||
|
||||
def pool_apply(self, src_ignore):
|
||||
pool = self.current_pool()
|
||||
@ -868,14 +862,13 @@ class vmmHost(vmmGObjectUI):
|
||||
self.widget("storage-error-label").set_text(msg)
|
||||
|
||||
def pool_selected(self, src):
|
||||
selected = src.get_selected()
|
||||
if (selected[1] is None or
|
||||
selected[0].get_value(selected[1], 0) is None):
|
||||
model, treeiter = src.get_selected()
|
||||
if treeiter is None:
|
||||
self.set_storage_error_page(_("No storage pool selected."))
|
||||
return
|
||||
|
||||
self.widget("storage-pages").set_current_page(0)
|
||||
uuid = selected[0].get_value(selected[1], 0)
|
||||
uuid = model[treeiter][0]
|
||||
|
||||
try:
|
||||
self.populate_pool_state(uuid)
|
||||
@ -960,9 +953,9 @@ class vmmHost(vmmGObjectUI):
|
||||
self.disable_pool_apply()
|
||||
|
||||
def vol_selected(self, src):
|
||||
selected = src.get_selected()
|
||||
if (selected[1] is None or
|
||||
selected[0].get_value(selected[1], 0) is None):
|
||||
model, treeiter = src.get_selected()
|
||||
ignore = model
|
||||
if treeiter is None:
|
||||
self.widget("vol-delete").set_sensitive(False)
|
||||
return
|
||||
|
||||
@ -1061,23 +1054,19 @@ class vmmHost(vmmGObjectUI):
|
||||
self.refresh_interface(None, cp.get_name())
|
||||
|
||||
def current_interface(self):
|
||||
model, _iter = self.widget("interface-list").get_selection(
|
||||
).get_selected()
|
||||
if not _iter:
|
||||
return
|
||||
key = uiutil.get_list_selection(self.widget("interface-list"), 0)
|
||||
try:
|
||||
return self.conn.get_interface(model[_iter][0])
|
||||
return key and self.conn.get_interface(key)
|
||||
except KeyError:
|
||||
return
|
||||
return None
|
||||
|
||||
def interface_apply(self, src_ignore):
|
||||
interface = self.current_interface()
|
||||
if interface is None:
|
||||
return
|
||||
|
||||
start_list = self.widget("interface-startmode")
|
||||
model = start_list.get_model()
|
||||
newmode = model[start_list.get_active()][0]
|
||||
newmode = uiutil.get_list_selection(
|
||||
self.widget("interface-startmode"), 0)
|
||||
|
||||
logging.debug("Applying changes for interface '%s'",
|
||||
interface.get_name())
|
||||
@ -1100,14 +1089,13 @@ class vmmHost(vmmGObjectUI):
|
||||
self.widget("interface-error-label").set_text(msg)
|
||||
|
||||
def interface_selected(self, src):
|
||||
selected = src.get_selected()
|
||||
if (selected[1] is None or
|
||||
selected[0].get_value(selected[1], 0) is None):
|
||||
model, treeiter = src.get_selected()
|
||||
if treeiter is None:
|
||||
self.set_interface_error_page(_("No interface selected."))
|
||||
return
|
||||
|
||||
self.widget("interface-pages").set_current_page(INTERFACE_PAGE_INFO)
|
||||
name = selected[0].get_value(selected[1], 0)
|
||||
name = model[treeiter][0]
|
||||
|
||||
try:
|
||||
self.populate_interface_state(name)
|
||||
@ -1205,7 +1193,7 @@ class vmmHost(vmmGObjectUI):
|
||||
def refresh_interface(self, src_ignore, name):
|
||||
iface_list = self.widget("interface-list")
|
||||
sel = iface_list.get_selection()
|
||||
active = sel.get_selected()
|
||||
model, treeiter = sel.get_selected()
|
||||
iface = self.conn.get_interface(name)
|
||||
iface.tick()
|
||||
|
||||
@ -1213,9 +1201,8 @@ class vmmHost(vmmGObjectUI):
|
||||
if row[0] == name:
|
||||
row[4] = iface.is_active()
|
||||
|
||||
if active[1] is not None:
|
||||
currname = active[0].get_value(active[1], 0)
|
||||
if currname == name:
|
||||
if treeiter is not None:
|
||||
if model[treeiter][0] == name:
|
||||
self.interface_selected(sel)
|
||||
|
||||
|
||||
|
@ -196,7 +196,7 @@ class vmmManager(vmmGObjectUI):
|
||||
vmlist = self.widget("vm-list")
|
||||
if len(vmlist.get_model()) != 0:
|
||||
vmlist.get_selection().select_iter(
|
||||
vmlist.get_model().get_iter_first())
|
||||
vmlist.get_model().get_iter_first())
|
||||
|
||||
# Queue up the default connection detector
|
||||
self.idle_emit("add-default-conn")
|
||||
@ -423,14 +423,7 @@ class vmmManager(vmmGObjectUI):
|
||||
##################
|
||||
|
||||
def current_row(self):
|
||||
vmlist = self.widget("vm-list")
|
||||
selection = vmlist.get_selection()
|
||||
active = selection.get_selected()
|
||||
|
||||
treestore, treeiter = active
|
||||
if treeiter is not None:
|
||||
return treestore[treeiter]
|
||||
return None
|
||||
return uiutil.get_list_selection(self.widget("vm-list"))
|
||||
|
||||
def current_vm(self):
|
||||
row = self.current_row()
|
||||
@ -617,7 +610,7 @@ class vmmManager(vmmGObjectUI):
|
||||
|
||||
parent = self.rows[conn.get_uri()].iter
|
||||
for row in range(model.iter_n_children(parent)):
|
||||
vm = model.get_value(model.iter_nth_child(parent, row), ROW_HANDLE)
|
||||
vm = model[model.iter_nth_child(parent, row)][ROW_HANDLE]
|
||||
if vm.get_uuid() == vmuuid:
|
||||
model.remove(model.iter_nth_child(parent, row))
|
||||
del self.rows[self.vm_row_key(vm)]
|
||||
@ -754,7 +747,7 @@ class vmmManager(vmmGObjectUI):
|
||||
|
||||
child = model.iter_children(parent)
|
||||
while child is not None:
|
||||
del self.rows[self.vm_row_key(model.get_value(child, ROW_HANDLE))]
|
||||
del self.rows[self.vm_row_key(model[child][ROW_HANDLE])]
|
||||
model.remove(child)
|
||||
child = model.iter_children(parent)
|
||||
model.remove(parent)
|
||||
@ -807,7 +800,7 @@ class vmmManager(vmmGObjectUI):
|
||||
missing = True
|
||||
for row in range(model.iter_n_children(parent)):
|
||||
_iter = model.iter_nth_child(parent, row)
|
||||
if model.get_value(_iter, ROW_HANDLE) == vm:
|
||||
if model[_iter][ROW_HANDLE] == vm:
|
||||
missing = False
|
||||
break
|
||||
|
||||
@ -907,10 +900,8 @@ class vmmManager(vmmGObjectUI):
|
||||
if Gdk.keyval_name(event.keyval) != "Menu":
|
||||
return False
|
||||
|
||||
vmlist = self.widget("vm-list")
|
||||
treeselection = vmlist.get_selection()
|
||||
model, _iter = treeselection.get_selected()
|
||||
self.popup_vm_menu(model, _iter, event)
|
||||
model, treeiter = self.widget("vm-list").get_selection().get_selected()
|
||||
self.popup_vm_menu(model, treeiter, event)
|
||||
return True
|
||||
|
||||
def popup_vm_menu_button(self, widget, event):
|
||||
@ -930,13 +921,13 @@ class vmmManager(vmmGObjectUI):
|
||||
def popup_vm_menu(self, model, _iter, event):
|
||||
if model.iter_parent(_iter) is not None:
|
||||
# Popup the vm menu
|
||||
vm = model.get_value(_iter, ROW_HANDLE)
|
||||
vm = model[_iter][ROW_HANDLE]
|
||||
self.vmmenu.update_widget_states(vm)
|
||||
self.vmmenu.popup( # pylint: disable=E1101
|
||||
None, None, None, None, 0, event.time)
|
||||
else:
|
||||
# Pop up connection menu
|
||||
conn = model.get_value(_iter, ROW_HANDLE)
|
||||
conn = model[_iter][ROW_HANDLE]
|
||||
disconn = (conn.get_state() == vmmConnection.STATE_DISCONNECTED)
|
||||
conning = (conn.get_state() == vmmConnection.STATE_CONNECTING)
|
||||
|
||||
@ -954,39 +945,38 @@ class vmmManager(vmmGObjectUI):
|
||||
#################
|
||||
|
||||
def vmlist_name_sorter(self, model, iter1, iter2, ignore):
|
||||
return cmp(model.get_value(iter1, ROW_SORT_KEY),
|
||||
model.get_value(iter2, ROW_SORT_KEY))
|
||||
return cmp(model[iter1][ROW_SORT_KEY], model[iter2][ROW_SORT_KEY])
|
||||
|
||||
def vmlist_guest_cpu_usage_sorter(self, model, iter1, iter2, ignore):
|
||||
obj1 = model.get_value(iter1, ROW_HANDLE)
|
||||
obj2 = model.get_value(iter2, ROW_HANDLE)
|
||||
obj1 = model[iter1][ROW_HANDLE]
|
||||
obj2 = model[iter2][ROW_HANDLE]
|
||||
|
||||
return cmp(obj1.guest_cpu_time_percentage(),
|
||||
obj2.guest_cpu_time_percentage())
|
||||
|
||||
def vmlist_host_cpu_usage_sorter(self, model, iter1, iter2, ignore):
|
||||
obj1 = model.get_value(iter1, ROW_HANDLE)
|
||||
obj2 = model.get_value(iter2, ROW_HANDLE)
|
||||
obj1 = model[iter1][ROW_HANDLE]
|
||||
obj2 = model[iter2][ROW_HANDLE]
|
||||
|
||||
return cmp(obj1.host_cpu_time_percentage(),
|
||||
obj2.host_cpu_time_percentage())
|
||||
|
||||
def vmlist_memory_usage_sorter(self, model, iter1, iter2, ignore):
|
||||
obj1 = model.get_value(iter1, ROW_HANDLE)
|
||||
obj2 = model.get_value(iter2, ROW_HANDLE)
|
||||
obj1 = model[iter1][ROW_HANDLE]
|
||||
obj2 = model[iter2][ROW_HANDLE]
|
||||
|
||||
return cmp(obj1.stats_memory(),
|
||||
obj2.stats_memory())
|
||||
|
||||
def vmlist_disk_io_sorter(self, model, iter1, iter2, ignore):
|
||||
obj1 = model.get_value(iter1, ROW_HANDLE)
|
||||
obj2 = model.get_value(iter2, ROW_HANDLE)
|
||||
obj1 = model[iter1][ROW_HANDLE]
|
||||
obj2 = model[iter2][ROW_HANDLE]
|
||||
|
||||
return cmp(obj1.disk_io_rate(), obj2.disk_io_rate())
|
||||
|
||||
def vmlist_network_usage_sorter(self, model, iter1, iter2, ignore):
|
||||
obj1 = model.get_value(iter1, ROW_HANDLE)
|
||||
obj2 = model.get_value(iter2, ROW_HANDLE)
|
||||
obj1 = model[iter1][ROW_HANDLE]
|
||||
obj2 = model[iter2][ROW_HANDLE]
|
||||
|
||||
return cmp(obj1.network_traffic_rate(), obj2.network_traffic_rate())
|
||||
|
||||
|
@ -31,6 +31,7 @@ from gi.repository import Gtk
|
||||
import libvirt
|
||||
from virtinst import util
|
||||
|
||||
from virtManager import uiutil
|
||||
from virtManager.baseclass import vmmGObjectUI
|
||||
from virtManager.asyncjob import vmmAsyncJob
|
||||
from virtManager.domain import vmmDomain
|
||||
@ -187,12 +188,12 @@ class vmmMigrateDialog(vmmGObjectUI):
|
||||
self.reset_state()
|
||||
|
||||
def destconn_changed(self, src):
|
||||
active = src.get_active()
|
||||
row = uiutil.get_list_selection(src)
|
||||
tooltip = ""
|
||||
if active == -1:
|
||||
if row:
|
||||
tooltip = _("A valid destination connection must be selected.")
|
||||
|
||||
self.widget("migrate-finish").set_sensitive(active != -1)
|
||||
self.widget("migrate-finish").set_sensitive(bool(row))
|
||||
self.widget("migrate-finish").set_tooltip_text(tooltip)
|
||||
|
||||
def toggle_set_rate(self, src):
|
||||
@ -215,17 +216,9 @@ class vmmMigrateDialog(vmmGObjectUI):
|
||||
self.widget("migrate-port").set_sensitive(enable)
|
||||
|
||||
def get_config_destconn(self):
|
||||
combo = self.widget("migrate-dest")
|
||||
model = combo.get_model()
|
||||
|
||||
idx = combo.get_active()
|
||||
if idx == -1:
|
||||
row = uiutil.get_list_selection(self.widget("migrate-dest"))
|
||||
if not row or not row[2]:
|
||||
return None
|
||||
|
||||
row = model[idx]
|
||||
if not row[2]:
|
||||
return None
|
||||
|
||||
return row[1]
|
||||
|
||||
def get_config_offline(self):
|
||||
|
@ -298,22 +298,13 @@ class vmmPreferences(vmmGObjectUI):
|
||||
def change_new_vm_sound(self, src):
|
||||
self.config.set_new_vm_sound(src.get_active())
|
||||
def change_graphics_type(self, src):
|
||||
gtype = 'vnc'
|
||||
idx = src.get_active()
|
||||
if idx >= 0:
|
||||
gtype = src.get_model()[idx][0]
|
||||
self.config.set_graphics_type(gtype.lower())
|
||||
typ = uiutil.get_list_selection(src, 0) or "vnc"
|
||||
self.config.set_graphics_type(typ.lower())
|
||||
def change_storage_format(self, src):
|
||||
typ = 'default'
|
||||
idx = src.get_active()
|
||||
if idx >= 0:
|
||||
typ = src.get_model()[idx][0]
|
||||
typ = uiutil.get_list_selection(src, 0) or "default"
|
||||
self.config.set_storage_format(typ.lower())
|
||||
def change_cpu_default(self, src):
|
||||
typ = 'default'
|
||||
idx = src.get_active()
|
||||
if idx >= 0:
|
||||
typ = src.get_model()[idx][0]
|
||||
typ = uiutil.get_list_selection(src, 0) or "default"
|
||||
self.config.set_default_cpu_setting(typ.lower())
|
||||
|
||||
def change_disk_poll(self, src):
|
||||
|
@ -230,14 +230,12 @@ def check_path_search_for_qemu(err, conn, path):
|
||||
|
||||
def _net_list_changed(net_list, bridge_box,
|
||||
source_mode_combo, vport_expander):
|
||||
active = net_list.get_active()
|
||||
if active < 0:
|
||||
return
|
||||
|
||||
if not bridge_box:
|
||||
return
|
||||
|
||||
row = net_list.get_model()[active]
|
||||
row = uiutil.get_list_selection(net_list)
|
||||
if not row:
|
||||
return
|
||||
|
||||
if source_mode_combo is not None:
|
||||
doshow = (row[0] == virtinst.VirtualNetworkInterface.TYPE_DIRECT)
|
||||
@ -287,11 +285,10 @@ def build_network_list(net_list, bridge_box, source_mode_combo=None,
|
||||
|
||||
|
||||
def get_network_selection(net_list, bridge_entry):
|
||||
idx = net_list.get_active()
|
||||
if idx == -1:
|
||||
row = uiutil.get_list_selection(net_list)
|
||||
if not row:
|
||||
return None, None
|
||||
|
||||
row = net_list.get_model()[net_list.get_active()]
|
||||
net_type = row[0]
|
||||
net_src = row[1]
|
||||
net_check_bridge = row[5]
|
||||
|
@ -170,13 +170,11 @@ class vmmSnapshotPage(vmmGObjectUI):
|
||||
###################
|
||||
|
||||
def _get_selected_snapshot(self):
|
||||
widget = self.widget("snapshot-list")
|
||||
selection = widget.get_selection()
|
||||
model, treepath = selection.get_selected()
|
||||
if treepath is None:
|
||||
name = uiutil.get_list_selection(self.widget("snapshot-list"), 0)
|
||||
if not name:
|
||||
return None
|
||||
|
||||
try:
|
||||
name = model[treepath][0]
|
||||
for snap in self.vm.list_snapshots():
|
||||
if name == snap.get_name():
|
||||
return snap
|
||||
|
@ -46,6 +46,9 @@ def set_combo_text_column(combo, col):
|
||||
|
||||
|
||||
def spin_get_helper(widget):
|
||||
"""
|
||||
Safely get spin button contents, converting to int if possible
|
||||
"""
|
||||
adj = widget.get_adjustment()
|
||||
txt = widget.get_text()
|
||||
|
||||
@ -55,17 +58,36 @@ def spin_get_helper(widget):
|
||||
return adj.get_value()
|
||||
|
||||
|
||||
def get_list_selection(widget):
|
||||
selection = widget.get_selection()
|
||||
active = selection.get_selected()
|
||||
def get_list_selection(widget, rowindex=None, check_visible=False):
|
||||
"""
|
||||
Helper to simplify getting the selected row in a list/tree/combo
|
||||
"""
|
||||
if check_visible and not widget.get_visible():
|
||||
return None
|
||||
|
||||
treestore, treeiter = active
|
||||
if treeiter is not None:
|
||||
return treestore[treeiter]
|
||||
return None
|
||||
if hasattr(widget, "get_selection"):
|
||||
selection = widget.get_selection()
|
||||
model, treeiter = selection.get_selected()
|
||||
if treeiter is None:
|
||||
return None
|
||||
|
||||
row = model[treeiter]
|
||||
else:
|
||||
idx = widget.get_active()
|
||||
if idx == -1:
|
||||
return None
|
||||
|
||||
row = widget.get_model()[idx]
|
||||
|
||||
if rowindex is None:
|
||||
return row
|
||||
return row[rowindex]
|
||||
|
||||
|
||||
def set_list_selection(widget, rownum):
|
||||
"""
|
||||
Helper to set list selection from the passed row number
|
||||
"""
|
||||
path = str(rownum)
|
||||
selection = widget.get_selection()
|
||||
|
||||
@ -75,6 +97,10 @@ def set_list_selection(widget, rownum):
|
||||
|
||||
|
||||
def set_row_selection(listwidget, prevkey):
|
||||
"""
|
||||
Set a list or tree selection given the passed key. The key is
|
||||
expected to be element 0 in the list rows.
|
||||
"""
|
||||
model = listwidget.get_model()
|
||||
_iter = None
|
||||
if prevkey:
|
||||
@ -97,8 +123,10 @@ def set_row_selection(listwidget, prevkey):
|
||||
|
||||
|
||||
def child_get_property(parent, child, propname):
|
||||
# Wrapper for child_get_property, which pygobject doesn't properly
|
||||
# introspect
|
||||
"""
|
||||
Wrapper for child_get_property, which pygobject doesn't properly
|
||||
introspect
|
||||
"""
|
||||
value = GObject.Value()
|
||||
value.init(GObject.TYPE_INT)
|
||||
parent.child_get_property(child, propname, value)
|
||||
@ -106,11 +134,12 @@ def child_get_property(parent, child, propname):
|
||||
|
||||
|
||||
def set_grid_row_visible(child, visible):
|
||||
# For the passed widget, find its parent GtkGrid, and hide/show all
|
||||
# elements that are in the same row as it. Simplifies having to name
|
||||
# every element in a row when we want to dynamically hide things
|
||||
# based on UI interraction
|
||||
|
||||
"""
|
||||
For the passed widget, find its parent GtkGrid, and hide/show all
|
||||
elements that are in the same row as it. Simplifies having to name
|
||||
every element in a row when we want to dynamically hide things
|
||||
based on UI interraction
|
||||
"""
|
||||
parent = child.get_parent()
|
||||
if not type(parent) is Gtk.Grid:
|
||||
raise RuntimeError("Programming error, parent must be grid, "
|
||||
|
Loading…
Reference in New Issue
Block a user