Skip to content

Commit

Permalink
Readme update, version bump to v1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
harskish committed Oct 11, 2024
1 parent 6af60ef commit 79b46ae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,29 @@ A viewer that shows ImGui UI elemets on the left, and a large image on the right
* Bundles a [custom build](https://github.com/harskish/pyplotgui) of PyImGui with plotting support (via ImPlot)
* Dynamically rescalable user interface
* Window resizing to integer multiple of content resolution
* Pan and zoom of the main image

## Installation
`pip install pyviewer`

## Usage
See `examples/demo.py` for a usage example.

## API highlights
`PannableArea::screen_to_uv_xform`<br>
Maps absolute screen coordinates (e.g. `imgui.get_mouse_pos()`) to transformed image UVs, useful for picking etc.<br>

`PannableArea::uv_to_screen_xform`<br>
Maps image UVs to absolute screen coordinates. Useful when combined with imgui's [draw lists](https://pyimgui.readthedocs.io/en/latest/reference/imgui.core.html#imgui.core._DrawList).

`PannableArea::get_visible_box_image()`<br>
Returns the top-left and bottom-right UV coordinates of the currently visible image region.<br>

`PannableArea::get_hovered_uv_image()`<br>
Returns the image UVs that lie under the mouse cursor.

`PannableArea::get_hovered_uv_canvas()`<br>
Returns the *canvas* UVs that lie under the mouse cursor. Differs from the image UVs in case of non-matching image and window aspect ratios.

`from pyviewer.single_image_viewer import draw; draw(img_chw=...)`<br>
One-liner that opens a new viewer (unless already open) and draws the provided image. Runs in a separate process and thus works even when execution is halted by e.g. a debugger.
6 changes: 2 additions & 4 deletions pyviewer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ def draw_to_canvas(self, texture_in, tW, tH, cW, cH, pan_enabled=True):
self.pan_enabled = pan_enabled

# Update pan & zoom state
self.handle_pan()
if self.pan_enabled:
self.handle_pan()

#gl.glDisable(gl.GL_BLEND)
gl.glDisable(gl.GL_CULL_FACE)
Expand Down Expand Up @@ -438,9 +439,6 @@ def get_hovered_uv_image(self):

# Handle pan action
def handle_pan(self):
if not self.pan_enabled:
return

if imgui.is_mouse_clicked(0) and self.mouse_hovers_content():
u, v = self.get_hovered_uv_canvas()
self.pan_start = (u, 1 - v) # convert to y-up
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# or with: `rm -r build\ && pip wheel . && unzip -l pyviewer-*.whl`
# (not same environment, but good first step)
setup(name='pyviewer',
version='1.5.1',
version='1.6.0',
description='Interactyive python viewers',
author='Erik Härkönen',
author_email='erik.harkonen@hotmail.com',
Expand Down

0 comments on commit 79b46ae

Please sign in to comment.