Skip to content

Commit

Permalink
Open-proc improvement, bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
harskish committed Apr 16, 2024
1 parent 5da4e15 commit b00fc37
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyviewer/toolbar_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def mouse_pos_abs(self):

@property
def mouse_pos_content_norm(self):
return (self.mouse_pos_abs - self.output_area_tl) / self.content_size
return (self.mouse_pos_abs - self.output_pos_tl) / self.content_size

@property
def mouse_pos_img_norm(self):
Expand Down
23 changes: 17 additions & 6 deletions pyviewer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,18 +492,29 @@ def open_prog(pth, mode, name=None):
assert mode in ['r', 'rb'], 'Only r and rb supported'
total_size = int(os.path.getsize(pth))
label = Path(pth).name if name is None else name
pbar = tqdm(ncols=80, total=total_size, bar_format=f'{label} {{l_bar}}{{bar}}| Remaining: {{remaining}}', disable=False)
pbar = tqdm(ncols=80, total=total_size, bar_format=f'{label} {{l_bar}}{{bar}}| {{elapsed}}<{{remaining}}')
handle = open(pth, mode)

def newread(size, orig=None):
def update(size):
pbar.update(size)
if pbar.n == pbar.total:
pbar.refresh()
pbar.close()

def read(size, orig=None):
update(size)
return orig(size)
handle.read = partial(newread, orig=handle.read)
handle.read = partial(read, orig=handle.read)

def newreadinto(memory, orig=None):
pbar.update(memory.nbytes)
def readinto(memory, orig=None):
update(memory.nbytes)
return orig(memory)
handle.readinto = partial(newreadinto, orig=handle.readinto)
handle.readinto = partial(readinto, orig=handle.readinto)

def close(orig=None):
update(pbar.total - pbar.n) # set to 100%
return orig()
handle.close = partial(close, orig=handle.close)

return handle

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# or with: `rm -r build\ && pip wheel . && unzip -l pyviewer-*.whl`
# (not same environment, but good first step)
setup(name='pyviewer',
version='1.3.13',
version='1.3.15',
description='Interactyive python viewers',
author='Erik Härkönen',
author_email='[email protected]',
Expand Down

0 comments on commit b00fc37

Please sign in to comment.