Make the progress bar threaded so that it will bounce back and forth in the background (still doesn't work) and abstract the progress bar functionality

This commit is contained in:
Hugh O. Brock 2006-07-20 11:16:07 -04:00
parent 0a319ddd07
commit a5c0597604
6 changed files with 116 additions and 24 deletions

View File

@ -49,9 +49,10 @@
<property name="label" translatable="yes">New machine...</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menu_file_new_activate" last_modification_time="Tue, 28 Mar 2006 17:06:34 GMT"/>
<accelerator key="n" modifiers="GDK_MOD1_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image42">
<widget class="GtkImage" id="image65">
<property name="visible">True</property>
<property name="stock">gtk-new</property>
<property name="icon_size">1</property>
@ -64,6 +65,29 @@
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="restore_saved">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Restore a saved machine from a filesystem image</property>
<property name="label" translatable="yes">Restore saved machine...</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menu_restore_saved_activate" last_modification_time="Wed, 19 Jul 2006 18:10:04 GMT"/>
<accelerator key="r" modifiers="GDK_MOD1_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image66">
<property name="visible">True</property>
<property name="stock">gtk-open</property>
<property name="icon_size">1</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separator4">
<property name="visible">True</property>
@ -78,7 +102,7 @@
<signal name="activate" handler="on_menu_file_open_connection_activate" last_modification_time="Mon, 12 Jun 2006 20:34:47 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image43">
<widget class="GtkImage" id="image67">
<property name="visible">True</property>
<property name="stock">gtk-connect</property>
<property name="icon_size">1</property>
@ -136,7 +160,7 @@
<signal name="activate" handler="on_menu_edit_details_activate" last_modification_time="Tue, 28 Mar 2006 17:06:34 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image44">
<widget class="GtkImage" id="image68">
<property name="visible">True</property>
<property name="stock">gtk-properties</property>
<property name="icon_size">1</property>
@ -157,7 +181,7 @@
<signal name="activate" handler="on_menu_edit_delete_activate" last_modification_time="Tue, 28 Mar 2006 17:06:34 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image45">
<widget class="GtkImage" id="image69">
<property name="visible">True</property>
<property name="stock">gtk-delete</property>
<property name="icon_size">1</property>
@ -3265,7 +3289,7 @@ Inactive virtual machines</property>
</child>
</widget>
<widget class="GtkWindow" id="vmm-save-progress">
<widget class="GtkWindow" id="vmm-progress">
<property name="visible">True</property>
<property name="title" translatable="yes">Saving VM Image</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
@ -3290,7 +3314,7 @@ Inactive virtual machines</property>
<child>
<widget class="GtkLabel" id="label94">
<property name="visible">True</property>
<property name="label" translatable="yes">Please wait while the VM image saves...</property>
<property name="label" translatable="yes">Please wait...</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>

View File

@ -20,6 +20,7 @@
#
import gtk
gtk.threads_init()
import dbus
import dbus.glib

View File

@ -0,0 +1,54 @@
#
# Copyright (C) 2006 Red Hat, Inc.
# Copyright (C) 2006 Hugh O. Brock <hbrock@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
import threading
import gtk
import gtk.glade
import gobject
# Displays a progress bar while executing the "callback" method.
class asyncJob(gobject.GObject):
def __init__(self, config, callback, args=None, title="Progress"):
self.__gobject_init__()
self.config = config
self.callback = callback
self.args = args
self.pbar_glade = gtk.glade.XML(self.config.get_glade_file(), "vmm-progress")
self.pbar_win = self.pbar_glade.get_widget("vmm-progress")
self.pbar = self.pbar_glade.get_widget("pbar")
self.pbar_win.set_title(title)
self.pbar_win.hide()
self.bg_thread = threading.Thread(target=self.callback, args=self.args)
def run(self):
self.timer = gobject.timeout_add (100, self.pulse_pbar)
self.pbar_win.present()
self.bg_thread.start()
gtk.main()
gobject.source_remove(self.timer)
self.timer = 0
self.pbar_win.destroy()
def pulse_pbar(self):
print "About to frobnicate the pbar"
if(self.bg_thread.isAlive()):
self.pbar.pulse()
else:
gtk.main_quit()

View File

@ -85,6 +85,8 @@ class vmmConnection(gobject.GObject):
def host_maximum_processor_count(self):
return self.hostinfo[4] * self.hostinfo[5] * self.hostinfo[6] * self.hostinfo[7]
def restore(self, frm):
self.vmm.restore(frm)
def tick(self):
if self.vmm == None:

View File

@ -28,6 +28,7 @@ from virtManager.preferences import vmmPreferences
from virtManager.manager import vmmManager
from virtManager.details import vmmDetails
from virtManager.console import vmmConsole
from virtManager.asyncjob import asyncJob
class vmmEngine:
def __init__(self, config):
@ -216,24 +217,11 @@ class vmmEngine:
gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT),
None)
self.fcdialog.set_do_overwrite_confirmation(True)
# also set up the progress bar now
self.pbar_glade = gtk.glade.XML(config.get_glade_file(), "vmm-save-progress")
self.pbar_win = self.pbar_glade.get_widget("vmm-save-progress")
self.pbar_win.hide()
response = self.fcdialog.run()
self.fcdialog.hide()
if(response == gtk.RESPONSE_ACCEPT):
uri_to_save = self.fcdialog.get_filename()
# show a lovely bouncing progress bar until the vm actually saves
self.timer = gobject.timeout_add (100,
self.pbar_glade.get_widget("pbar").pulse)
self.pbar_win.present()
# actually save the vm
vm.save( uri_to_save )
gobject.source_remove(self.timer)
self.timer = 0
self.pbar_win.hide()
self.fcdialog.destroy()
self.pbar_win.destroy()
file_to_save = self.fcdialog.get_filename()
progWin = asyncJob(self.config, vm.save,
[file_to_save], "Saving Virtual Machine")
progWin.run()
self.fcdialog.destroy()

View File

@ -20,9 +20,12 @@
import gobject
import gtk
import gtk.glade
import threading
import sparkline
from virtManager.asyncjob import asyncJob
VMLIST_SORT_ID = 1
VMLIST_SORT_NAME = 2
VMLIST_SORT_CPU_USAGE = 3
@ -104,6 +107,7 @@ class vmmManager(gobject.GObject):
"on_menu_file_open_connection_activate": self.open_connection,
"on_menu_file_quit_activate": self.exit_app,
"on_menu_file_close_activate": self.close,
"on_menu_restore_saved_activate": self.restore_saved,
"on_vmm_close_clicked": self.close,
"on_vm_details_clicked": self.show_vm_details,
"on_vm_open_clicked": self.open_vm_console,
@ -138,6 +142,25 @@ class vmmManager(gobject.GObject):
def open_connection(self, src=None):
self.emit("action-show-connect")
def restore_saved(self, src=None):
# get filename
self.fcdialog = gtk.FileChooserDialog("Restore Virtual Machine",
self.window.get_widget("vmm-manager"),
gtk.FILE_CHOOSER_ACTION_OPEN,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT),
None)
# pop up progress dialog
response = self.fcdialog.run()
self.fcdialog.hide()
if(response == gtk.RESPONSE_ACCEPT):
file_to_load = self.fcdialog.get_filename()
progWin = asyncJob(self.config, self.connection.restore,
[file_to_load], "Restoring Virtual Machine")
progWin.run()
self.fcdialog.destroy()
def vm_added(self, connection, uri, vmuuid):
vmlist = self.window.get_widget("vm-list")
model = vmlist.get_model()