opticalhelper: Move UI update routines to uihelpers

This commit is contained in:
Cole Robinson 2009-11-30 16:21:04 -05:00
parent f9b7e9cdf4
commit 8c320509ed
4 changed files with 120 additions and 104 deletions

View File

@ -23,7 +23,7 @@ import logging
import virtinst
import virtManager.opticalhelper
import virtManager.uihelpers as uihelpers
from virtManager.storagebrowse import vmmStorageBrowser
from virtManager.error import vmmErrorDialog
@ -93,7 +93,7 @@ class vmmChooseCD(gobject.GObject):
idx = cd.get_active()
model = cd.get_model()
if idx != -1:
path = model[idx][virtManager.opticalhelper.OPTICAL_PATH]
path = model[idx][uihelpers.OPTICAL_PATH]
if path == "" or path == None:
return self.err.val_err(_("Invalid Media Path"),
@ -130,7 +130,7 @@ class vmmChooseCD(gobject.GObject):
def initialize_opt_media(self):
try:
widget = self.window.get_widget("cd-path")
virtManager.opticalhelper.init_optical_combo(widget)
uihelpers.init_optical_combo(widget)
self.window.get_widget("physical-media").set_sensitive(True)
except Exception, e:
logging.error("Unable to create optical-helper widget: '%s'", e)

View File

@ -30,7 +30,6 @@ import logging
import virtinst
import virtManager.opticalhelper
import virtManager.uihelpers as uihelpers
from virtManager import util
from virtManager.error import vmmErrorDialog
@ -243,7 +242,7 @@ class vmmCreate(gobject.GObject):
# FIXME: We should disable all this if on a remote connection
try:
virtManager.opticalhelper.init_optical_combo(cd_list)
uihelpers.init_optical_combo(cd_list)
except Exception, e:
logging.exception("Unable to create optical-helper widget: '%s'", e)
cd_radio.set_sensitive(False)

View File

@ -24,102 +24,6 @@ import gtk
from virtManager.mediadev import vmmMediaDevice
OPTICAL_PATH = 0
OPTICAL_LABEL = 1
OPTICAL_IS_MEDIA_PRESENT = 2
OPTICAL_HAL_PATH = 3
OPTICAL_MEDIADEV = 4
def init_optical_combo(widget, empty_sensitive=False):
# [Device path, pretty label, has_media?, unique hal path, vmmMediaDevice]
model = gtk.ListStore(str, str, bool, str, object)
widget.set_model(model)
model.clear()
text = gtk.CellRendererText()
widget.pack_start(text, True)
widget.add_attribute(text, 'text', 1)
if not empty_sensitive:
widget.add_attribute(text, 'sensitive', 2)
helper = vmmOpticalDriveHelper()
helper.connect("optical-added", optical_added, widget)
helper.connect("optical-removed", optical_removed, widget)
widget.set_active(-1)
optical_set_default_selection(widget)
def set_row_from_object(row):
obj = row[OPTICAL_MEDIADEV]
row[OPTICAL_PATH] = obj.get_path()
row[OPTICAL_LABEL] = obj.pretty_label()
row[OPTICAL_IS_MEDIA_PRESENT] = bool(obj.get_media_label())
row[OPTICAL_HAL_PATH] = obj.get_key()
def optical_removed(ignore_helper, halpath, widget):
model = widget.get_model()
active = widget.get_active()
idx = 0
# Search for the row containing matching HAL volume path
# and update (clear) it, de-activating it if its currently
# selected
for row in model:
if row[OPTICAL_HAL_PATH] == halpath:
row[OPTICAL_MEDIADEV].set_media_label(None)
set_row_from_object(row)
if idx == active:
widget.set_active(-1)
idx = idx + 1
optical_set_default_selection(widget)
def optical_added(ignore_helper, newobj, widget):
model = widget.get_model()
active = widget.get_active()
idx = 0
found = False
# Search for the row with matching device node and
# fill in info about inserted media. If model has no current
# selection, select the new media.
for row in model:
if row[OPTICAL_PATH] == newobj.get_path():
found = True
row[OPTICAL_MEDIADEV] = newobj
set_row_from_object(row)
if active == -1:
widget.set_active(idx)
idx = idx + 1
if not found:
# Brand new device
row = [None, None, None, None, newobj]
set_row_from_object(row)
model.append(row)
if active == -1:
widget.set_active(len(model) - 1)
def optical_set_default_selection(widget):
# Set the first active cdrom device as selected, otherwise none
model = widget.get_model()
idx = 0
active = widget.get_active()
if active != -1:
# already a selection, don't change it
return
for row in model:
if row[OPTICAL_IS_MEDIA_PRESENT] == True:
widget.set_active(idx)
return
idx += 1
widget.set_active(-1)
class vmmOpticalDriveHelper(gobject.GObject):
__gsignals__ = {
"optical-added" : (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,

View File

@ -25,9 +25,19 @@ import gtk
from virtinst import VirtualNetworkInterface
from virtManager.opticalhelper import vmmOpticalDriveHelper
from virtManager.error import vmmErrorDialog
# Initialize an error object to use for validation functions
OPTICAL_PATH = 0
OPTICAL_LABEL = 1
OPTICAL_IS_MEDIA_PRESENT = 2
OPTICAL_HAL_PATH = 3
OPTICAL_MEDIADEV = 4
##############################################################
# Initialize an error object to use for validation functions #
##############################################################
err_dial = vmmErrorDialog(None,
0, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
_("Unexpected Error"),
@ -38,7 +48,11 @@ def set_error_parent(parent):
err_dial.set_parent(parent)
err_dial = err_dial
# Widgets for listing network device options (in create, addhardware)
#######################################################################
# Widgets for listing network device options (in create, addhardware) #
#######################################################################
def init_network_list(net_list):
# [ network type, source name, label, sensitive? ]
net_model = gtk.ListStore(str, str, str, bool)
@ -231,7 +245,106 @@ def generate_macaddr(conn):
return newmac
# Build toolbar shutdown button menu (manager and details toolbar)
##############################################
# Populate optical widget (choosecd, create) #
##############################################
def init_optical_combo(widget, empty_sensitive=False):
# [Device path, pretty label, has_media?, unique hal path, vmmMediaDevice]
model = gtk.ListStore(str, str, bool, str, object)
widget.set_model(model)
model.clear()
text = gtk.CellRendererText()
widget.pack_start(text, True)
widget.add_attribute(text, 'text', 1)
if not empty_sensitive:
widget.add_attribute(text, 'sensitive', 2)
helper = vmmOpticalDriveHelper()
helper.connect("optical-added", optical_added, widget)
helper.connect("optical-removed", optical_removed, widget)
widget.set_active(-1)
optical_set_default_selection(widget)
def set_row_from_object(row):
obj = row[OPTICAL_MEDIADEV]
row[OPTICAL_PATH] = obj.get_path()
row[OPTICAL_LABEL] = obj.pretty_label()
row[OPTICAL_IS_MEDIA_PRESENT] = bool(obj.get_media_label())
row[OPTICAL_HAL_PATH] = obj.get_key()
def optical_removed(ignore_helper, halpath, widget):
model = widget.get_model()
active = widget.get_active()
idx = 0
# Search for the row containing matching HAL volume path
# and update (clear) it, de-activating it if its currently
# selected
for row in model:
if row[OPTICAL_HAL_PATH] == halpath:
row[OPTICAL_MEDIADEV].set_media_label(None)
set_row_from_object(row)
if idx == active:
widget.set_active(-1)
idx = idx + 1
optical_set_default_selection(widget)
def optical_added(ignore_helper, newobj, widget):
model = widget.get_model()
active = widget.get_active()
idx = 0
found = False
# Search for the row with matching device node and
# fill in info about inserted media. If model has no current
# selection, select the new media.
for row in model:
if row[OPTICAL_PATH] == newobj.get_path():
found = True
row[OPTICAL_MEDIADEV] = newobj
set_row_from_object(row)
if active == -1:
widget.set_active(idx)
idx = idx + 1
if not found:
# Brand new device
row = [None, None, None, None, newobj]
set_row_from_object(row)
model.append(row)
if active == -1:
widget.set_active(len(model) - 1)
def optical_set_default_selection(widget):
# Set the first active cdrom device as selected, otherwise none
model = widget.get_model()
idx = 0
active = widget.get_active()
if active != -1:
# already a selection, don't change it
return
for row in model:
if row[OPTICAL_IS_MEDIA_PRESENT] == True:
widget.set_active(idx)
return
idx += 1
widget.set_active(-1)
####################################################################
# Build toolbar shutdown button menu (manager and details toolbar) #
####################################################################
def build_shutdown_button_menu(config, widget, shutdown_cb, reboot_cb,
destroy_cb):
icon_name = config.get_shutdown_icon_name()