Skip to content

Commit

Permalink
moved Transfer __enter__ and __exit__ logic into methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismeyers committed Feb 18, 2019
1 parent b155684 commit e578fb9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
7 changes: 6 additions & 1 deletion examples/manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
before = time.time()

holding = pleasehold.hold('starting', 'complete')
transfer = pleasehold.transfer(holding)

holding.start()
time.sleep(2)
Expand All @@ -21,10 +22,14 @@
holding.end_msg = 'end'
holding.delay = 0.1
holding.symbol = '#'
holding.loading_ticks = ''

holding.start(msg='props changed')
time.sleep(2)
holding.push('pushed something')
transfer.start()
stdin = input('enter a push notification: ')
transfer.end()
holding.push(stdin)
time.sleep(2)
holding.end()

Expand Down
36 changes: 28 additions & 8 deletions pleasehold/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __exit__(self, type, value, traceback):

@property
def begin_msg(self):
'''str: gets or sets the message to the left of the loading bar'''
'''str: Gets or sets the message to the left of the loading bar'''
return self._begin_msg

@begin_msg.setter
Expand All @@ -54,7 +54,7 @@ def begin_msg(self, value):

@property
def end_msg(self):
'''str: gets or sets the message to the right of the loading bar'''
'''str: Gets or sets the message to the right of the loading bar'''
return self._end_msg

@end_msg.setter
Expand All @@ -63,7 +63,7 @@ def end_msg(self, value):

@property
def delay(self):
'''float: gets or sets the delay between printing loading symbols'''
'''float: Gets or sets the delay between printing loading symbols'''
return self._delay

@delay.setter
Expand All @@ -72,16 +72,28 @@ def delay(self, value):

@property
def symbol(self):
'''str: gets or sets the symbol that's used in the loading bar'''
'''str: Gets or sets the symbol that's used in the loading bar'''
return self._symbol

@symbol.setter
def symbol(self, value):
self._symbol = value

@property
def loading_ticks(self):
'''str: Gets or sets the loading ticks
NOTE: The setter will always reset _loading_ticks to an empty string!
'''
return self._symbol

@loading_ticks.setter
def loading_ticks(self, value):
self._loading_ticks = ''

@property
def loading_event(self):
'''str: gets the threading.Event() instance used to interact with the
'''str: Gets the threading.Event() instance used to interact with the
loading thread
'''
return self._loading_event
Expand Down Expand Up @@ -160,15 +172,23 @@ def __enter__(self):
'''Pauses the PleaseHold loading thread and prepares for input if this
class is initialized via a context manager
'''
sys.stdout = self._stream_tee
term.move_line_down()
self._holding.loading_event.clear()
self.start()
return self

def __exit__(self, type, value, traceback):
'''Cleans up input prompts and resumes the PleaseHold loading thread if
this class is initialized via a context manager
'''
self.end()

def start(self):
'''Pauses the PleaseHold loading thread and prepares for input'''
sys.stdout = self._stream_tee
term.move_line_down()
self._holding.loading_event.clear()

def end(self):
'''Cleans up input prompts and resumes the PleaseHold loading thread'''
sys.stdout = sys.__stdout__
for _ in range(self._stream_tee.num_inputs + 1):
term.clear_line()
Expand Down

0 comments on commit e578fb9

Please sign in to comment.