addhardware: Show host devices in a list, not a combo

Some of the listings can be pretty large, so a list is better suited for
browsing and resizing.
This commit is contained in:
Cole Robinson
2010-12-11 15:12:22 -05:00
parent 965570670b
commit 76fa12ea39
2 changed files with 68 additions and 33 deletions

View File

@@ -56,6 +56,19 @@ char_widget_mappings = {
"protocol" : "char-use-telnet",
}
def get_list_selection(widget):
selection = widget.get_selection()
active = selection.get_selected()
treestore, treeiter = active
if treeiter != None:
return treestore[treeiter]
return None
def set_list_selection(widget, rownum):
selection = widget.get_selection()
selection.select_path(str(rownum))
class vmmAddHardware(vmmGObjectUI):
__gsignals__ = {
"action-show-help": (gobject.SIGNAL_RUN_FIRST,
@@ -261,14 +274,17 @@ class vmmAddHardware(vmmGObjectUI):
host_devtype.pack_start(text, True)
host_devtype.add_attribute(text, 'text', 0)
# model = [ Description, nodedev name ]
host_dev = self.window.get_widget("host-device")
# Description, nodedev name
host_dev_model = gtk.ListStore(str, str)
host_dev.set_model(host_dev_model)
host_col = gtk.TreeViewColumn()
text = gtk.CellRendererText()
host_dev.pack_start(text, True)
host_dev.add_attribute(text, 'text', 0)
host_col.pack_start(text, True)
host_col.add_attribute(text, 'text', 0)
host_dev_model.set_sort_column_id(0, gtk.SORT_ASCENDING)
host_dev.append_column(host_col)
# Video device
video_dev = self.window.get_widget("video-model")
@@ -634,8 +650,10 @@ class vmmAddHardware(vmmGObjectUI):
return devbox.get_model()[devbox.get_active()]
def get_config_host_device_info(self):
devbox = self.window.get_widget("host-device")
return devbox.get_model()[devbox.get_active()]
devrow = get_list_selection(self.window.get_widget("host-device"))
if not devrow:
return []
return devrow
# Video Getters
def get_config_video_model(self):
@@ -655,19 +673,10 @@ class vmmAddHardware(vmmGObjectUI):
################
def set_hw_selection(self, page):
hwlist = self.window.get_widget("hardware-list")
selection = hwlist.get_selection()
selection.select_path(str(page))
set_list_selection(self.window.get_widget("hardware-list"), page)
def get_hw_selection(self):
vmlist = self.window.get_widget("hardware-list")
selection = vmlist.get_selection()
active = selection.get_selected()
treestore, treeiter = active
if treeiter != None:
return treestore[treeiter]
return None
return get_list_selection(self.window.get_widget("hardware-list"))
def hw_selected(self, src=None):
ignore = src
@@ -785,7 +794,7 @@ class vmmAddHardware(vmmGObjectUI):
subtype, subcap) = src.get_model()[src.get_active()]
self.populate_host_device_model(devbox.get_model(), devtype, devcap,
subtype, subcap)
devbox.set_active(0)
set_list_selection(devbox, 0)
# Char device listeners
def get_char_type(self):
@@ -1101,7 +1110,8 @@ class vmmAddHardware(vmmGObjectUI):
return self.err.val_err(_("Sound device parameter error"), str(e))
def validate_page_hostdev(self):
ignore, nodedev_name = self.get_config_host_device_info()
ret = self.get_config_host_device_info()
nodedev_name = ret and ret[1] or None
if nodedev_name == None:
return self.err.val_err(_("Physical Device Required"),

View File

@@ -1312,22 +1312,10 @@ to connect to the virtual machine.</property>
<child>
<widget class="GtkTable" id="table3">
<property name="visible">True</property>
<property name="n_rows">2</property>
<property name="n_rows">3</property>
<property name="n_columns">2</property>
<property name="column_spacing">12</property>
<property name="row_spacing">6</property>
<child>
<widget class="GtkComboBox" id="host-device">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkComboBox" id="host-device-type">
<property name="visible">True</property>
@@ -1337,6 +1325,7 @@ to connect to the virtual machine.</property>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
@@ -1345,12 +1334,12 @@ to connect to the virtual machine.</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Device:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">host-device</property>
</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>
@@ -1363,13 +1352,49 @@ to connect to the virtual machine.</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<property name="shadow_type">etched-in</property>
<child>
<widget class="GtkTreeView" id="host-device">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">False</property>
</widget>
</child>
</widget>
<packing>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment11">
<property name="visible">True</property>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>