-
Notifications
You must be signed in to change notification settings - Fork 9
/
startprogress.py
42 lines (33 loc) · 1.44 KB
/
startprogress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
# This file is part of Gertrude.
#
# Gertrude 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 3 of the License, or
# (at your option) any later version.
#
# Gertrude 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 Gertrude; if not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
from __future__ import print_function
class ProgressHandler(object):
def __init__(self, display_fn=None, gauge_fn=None, min=None, max=None):
self.display_fn = display_fn
self.gauge_fn = gauge_fn
self.min, self.max = min, max
self.value = min
def set(self, value):
if self.gauge_fn:
self.gauge_fn(self.min + (self.max - self.min) * value / 100)
def display(self, s):
print(s)
if self.display_fn:
self.display_fn(s + "\n")
def new(self, ratio):
return ProgressHandler(self.display_fn, self.gauge_fn, self.value, self.value + (self.max - self.min) * ratio / 100)
default_progress_handler = ProgressHandler()