Pull createmeter out into its own class

This commit is contained in:
Hugh O. Brock 2007-04-23 15:26:46 -04:00
parent 3be8db49d3
commit 2257049c06
3 changed files with 68 additions and 90 deletions

View File

@ -35,6 +35,7 @@ import traceback
from virtManager.asyncjob import vmmAsyncJob
from virtManager.error import vmmErrorDialog
from virtManager.createmeter import vmmCreateMeter
VM_STORAGE_PARTITION = 1
VM_STORAGE_FILE = 2
@ -46,52 +47,6 @@ PAGE_DISK = 1
PAGE_NETWORK = 2
PAGE_SUMMARY = 3
class vmmCreateMeter(progress.BaseMeter):
def __init__(self, asyncjob):
# progress meter has to run asynchronously, so pass in the
# async job to call back to with progress info
progress.BaseMeter.__init__(self)
self.asyncjob = asyncjob
def _do_start(self, now):
if self.text is not None:
text = self.text
else:
text = self.basename
if self.size is None:
out = " %5sB" % (0)
self.asyncjob.pulse_pbar(out, text)
else:
out = "%3i%% %5sB" % (0, 0)
self.asyncjob.set_pbar_fraction(0, out, text)
def _do_update(self, amount_read, now=None):
if self.text is not None:
text = self.text
else:
text = self.basename
fread = progress.format_number(amount_read)
if self.size is None:
out = " %5sB" % (fread)
self.asyncjob.pulse_pbar(out, text)
else:
frac = self.re.fraction_read()
out = "%3i%% %5sB" % (frac*100, fread)
self.asyncjob.set_pbar_fraction(frac, out, text)
def _do_end(self, amount_read, now=None):
if self.text is not None:
text = self.text
else:
text = self.basename
fread = progress.format_number(amount_read)
if self.size is None:
out = " %5sB" % (fread)
self.asyncjob.pulse_pbar(out, text)
else:
out = "%3i%% %5sB" % (100, fread)
self.asyncjob.set_pbar_done(out, text)
class vmmAddHardware(gobject.GObject):
__gsignals__ = {
"action-show-help": (gobject.SIGNAL_RUN_FIRST,

View File

@ -35,6 +35,7 @@ import traceback
from virtManager.asyncjob import vmmAsyncJob
from virtManager.error import vmmErrorDialog
from virtManager.createmeter import vmmCreateMeter
VM_PARA_VIRT = 1
VM_FULLY_VIRT = 2
@ -59,51 +60,7 @@ PAGE_SUMMARY = 8
KEYBOARD_DIR = "/etc/sysconfig/keyboard"
class vmmCreateMeter(progress.BaseMeter):
def __init__(self, asyncjob):
# progress meter has to run asynchronously, so pass in the
# async job to call back to with progress info
progress.BaseMeter.__init__(self)
self.asyncjob = asyncjob
def _do_start(self, now):
if self.text is not None:
text = self.text
else:
text = self.basename
if self.size is None:
out = " %5sB" % (0)
self.asyncjob.pulse_pbar(out, text)
else:
out = "%3i%% %5sB" % (0, 0)
self.asyncjob.set_pbar_fraction(0, out, text)
def _do_update(self, amount_read, now=None):
if self.text is not None:
text = self.text
else:
text = self.basename
fread = progress.format_number(amount_read)
if self.size is None:
out = " %5sB" % (fread)
self.asyncjob.pulse_pbar(out, text)
else:
frac = self.re.fraction_read()
out = "%3i%% %5sB" % (frac*100, fread)
self.asyncjob.set_pbar_fraction(frac, out, text)
def _do_end(self, amount_read, now=None):
if self.text is not None:
text = self.text
else:
text = self.basename
fread = progress.format_number(amount_read)
if self.size is None:
out = " %5sB" % (fread)
self.asyncjob.pulse_pbar(out, text)
else:
out = "%3i%% %5sB" % (100, fread)
self.asyncjob.set_pbar_done(out, text)
class vmmCreate(gobject.GObject):
__gsignals__ = {

View File

@ -0,0 +1,66 @@
#
# 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 urlgrabber.progress as progress
class vmmCreateMeter(progress.BaseMeter):
def __init__(self, asyncjob):
# progress meter has to run asynchronously, so pass in the
# async job to call back to with progress info
progress.BaseMeter.__init__(self)
self.asyncjob = asyncjob
def _do_start(self, now):
if self.text is not None:
text = self.text
else:
text = self.basename
if self.size is None:
out = " %5sB" % (0)
self.asyncjob.pulse_pbar(out, text)
else:
out = "%3i%% %5sB" % (0, 0)
self.asyncjob.set_pbar_fraction(0, out, text)
def _do_update(self, amount_read, now=None):
if self.text is not None:
text = self.text
else:
text = self.basename
fread = progress.format_number(amount_read)
if self.size is None:
out = " %5sB" % (fread)
self.asyncjob.pulse_pbar(out, text)
else:
frac = self.re.fraction_read()
out = "%3i%% %5sB" % (frac*100, fread)
self.asyncjob.set_pbar_fraction(frac, out, text)
def _do_end(self, amount_read, now=None):
if self.text is not None:
text = self.text
else:
text = self.basename
fread = progress.format_number(amount_read)
if self.size is None:
out = " %5sB" % (fread)
self.asyncjob.pulse_pbar(out, text)
else:
out = "%3i%% %5sB" % (100, fread)
self.asyncjob.set_pbar_done(out, text)