# Path: fabulous/widget.py
# class TimedProgressBar(ProgressBar):
#     """A 3-line progress bar, which looks like::
#                                       title
#         39% [================>----------------------------] ETA mm:ss
#                                      message
#     
#         p = ProgressBar('spam') # create bar
#         p.update(0, 'starting spam') # start printing it out
#         p.update(50, 'spam almost ready') # progress
#         p.update(100, 'spam complete')
#     """
#     
#     BAR_FORMAT = {'text':' %3d%% ' + '[%s'+display('dim')+'%s'+display('default')+']',
#            'length':13,
#            'padding':2 }
#     ' ETA 12:23'
#     
#     # what fraction of percent it acurate too
#     precision = 100
#     
#     def __init__(self, title = None):
#         ProgressBar.__init__(self, title)
#         self.start = datetime.today()
#     
#     def get_bar(self, percent):
#         now = datetime.today()
#         timed = now - self.start
#         etatext = ''
#         etadiv = int(percent*self.precision)
#         if timed.seconds >= 1:
#             etatext += ' '
#             if int(percent * self.precision) !=0:
#                 eta = (timed * 100 * self.precision)/int(percent * self.precision)
#                 days = eta.days
#                 min, sec = divmod(eta.seconds, 60)
#                 hours, min = divmod(min, 60)
#                 if days == 1: etatext += '1 day, '
#                 elif days: etatext += '%d days, ' % days
#                 if hours: etatext += '%02d:' % hours
#                 etatext += '%02d:%02d' % (min, sec)
#             else:
#                 etatext += 'Never'
#         barlength = (self.width - self.BAR_FORMAT['padding']*2 
#                      - self.BAR_FORMAT['length'] - len(etatext))
#         full = int( math.ceil(barlength * (percent / 100.0)) )
#         empty = int(barlength - full)
#         if full == 0 or empty == 0: fullpiece = ('=' * full)
#         else: fullpiece = ('=' * (full-1)) + '>'
#         emptypiece = ('-' * empty)
#         return [(self.BAR_FORMAT['text'] % (percent, fullpiece, emptypiece))+etatext]


from fabulous.widget import TimedProgressBar
import time
import random
#!/usr/bin/env python
#
# Copyright 2016 The Fabulous Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


p = TimedProgressBar('bar')
n = 100
for i in range(n):

# Path: fabulous/widget.py
# class TimedProgressBar(ProgressBar):
#     """A 3-line progress bar, which looks like::
#                                       title
#         39% [================>----------------------------] ETA mm:ss
#                                      message
#     
#         p = ProgressBar('spam') # create bar
#         p.update(0, 'starting spam') # start printing it out
#         p.update(50, 'spam almost ready') # progress
#         p.update(100, 'spam complete')
#     """
#     
#     BAR_FORMAT = {'text':' %3d%% ' + '[%s'+display('dim')+'%s'+display('default')+']',
#            'length':13,
#            'padding':2 }
#     ' ETA 12:23'
#     
#     # what fraction of percent it acurate too
#     precision = 100
#     
#     def __init__(self, title = None):
#         ProgressBar.__init__(self, title)
#         self.start = datetime.today()
#     
#     def get_bar(self, percent):
#         now = datetime.today()
#         timed = now - self.start
#         etatext = ''
#         etadiv = int(percent*self.precision)
#         if timed.seconds >= 1:
#             etatext += ' '
#             if int(percent * self.precision) !=0:
#                 eta = (timed * 100 * self.precision)/int(percent * self.precision)
#                 days = eta.days
#                 min, sec = divmod(eta.seconds, 60)
#                 hours, min = divmod(min, 60)
#                 if days == 1: etatext += '1 day, '
#                 elif days: etatext += '%d days, ' % days
#                 if hours: etatext += '%02d:' % hours
#                 etatext += '%02d:%02d' % (min, sec)
#             else:
#                 etatext += 'Never'
#         barlength = (self.width - self.BAR_FORMAT['padding']*2 
#                      - self.BAR_FORMAT['length'] - len(etatext))
#         full = int( math.ceil(barlength * (percent / 100.0)) )
#         empty = int(barlength - full)
#         if full == 0 or empty == 0: fullpiece = ('=' * full)
#         else: fullpiece = ('=' * (full-1)) + '>'
#         emptypiece = ('-' * empty)
#         return [(self.BAR_FORMAT['text'] % (percent, fullpiece, emptypiece))+etatext]


# Path: tests/manual/timedprogressbar.py
from fabulous.widget import TimedProgressBar
import time
import random

#!/usr/bin/env python
#
# Copyright 2016 The Fabulous Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


p = TimedProgressBar('bar')
n = 100
for i in range(n):

    p.update(float(i)/n *100, 'update '+str(i))