{"id":19797834,"url":"https://github.com/podgorskiy/bimpy","last_synced_at":"2025-04-05T20:03:56.486Z","repository":{"id":53691816,"uuid":"107902588","full_name":"podgorskiy/bimpy","owner":"podgorskiy","description":"imgui for python ","archived":false,"fork":false,"pushed_at":"2021-03-19T08:02:24.000Z","size":6445,"stargazers_count":205,"open_issues_count":16,"forks_count":32,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-29T19:04:13.590Z","etag":null,"topics":["dear-imgui","gl3w","glfw","glfw3","gui","imgui","pybind11","python","ui"],"latest_commit_sha":null,"homepage":"https://podgorskiy.github.io/bimpy/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/podgorskiy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-22T21:02:28.000Z","updated_at":"2025-03-11T09:25:35.000Z","dependencies_parsed_at":"2022-09-05T07:10:47.093Z","dependency_job_id":null,"html_url":"https://github.com/podgorskiy/bimpy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/podgorskiy%2Fbimpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/podgorskiy%2Fbimpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/podgorskiy%2Fbimpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/podgorskiy%2Fbimpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/podgorskiy","download_url":"https://codeload.github.com/podgorskiy/bimpy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393551,"owners_count":20931811,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dear-imgui","gl3w","glfw","glfw3","gui","imgui","pybind11","python","ui"],"created_at":"2024-11-12T07:27:00.895Z","updated_at":"2025-04-05T20:03:56.468Z","avatar_url":"https://github.com/podgorskiy.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"bimpy - bundled imgui for python \n================================\n\n\u003cimg src=\"doc_sources/logo.svg\"\u003e\n\n\u003ch4 align=\"center\"\u003e\n\u003cstrong\u003ebimpy\u003c/strong\u003e is a a native extension for Python built with C++ and \u003ca href=\"https://github.com/pybind/pybind11\"\u003e\u003c/a\u003e that provides bindings to \u003ca href=\"https://github.com/ocornut/imgui\"\u003edear imgui\u003c/a\u003e and distributed as a self-contained package bundled with \u003ca href=\"https://github.com/glfw/glfw\"\u003eglfw\u003c/a\u003e and \u003ca href=\"https://github.com/skaslev/gl3w\"\u003egl3w\u003c/a\u003e\n\u003c/h4\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://badge.fury.io/py/bimpy\"\u003e\u003cimg src=\"https://badge.fury.io/py/bimpy.svg\" alt=\"PyPI version\" height=\"18\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://pepy.tech/project/bimpy\"\u003e\u003cimg src=\"https://pepy.tech/badge/bimpy\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg src=\"https://img.shields.io/pypi/l/bimpy\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://api.travis-ci.com/podgorskiy/bimpy.svg?branch=master\"\u003e\u003cimg src=\"https://travis-ci.org/podgorskiy/bimpy.svg?branch=master\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\nFeatures:\n\n* Immediate mode UI with python. The API is kept as close to the original dear imgui as possible.\n\n* **bimpy** already has all necessary functionality for window/OpenGL context creation and hides those details from the user.\n\n* **bimpy** can display images from ndarrays, PIL Images, numpy arrays, etc., \n\n* **bimpy** works on Windows, GNU Linux, and macOS.\n\n* **bimpy** does not have dependencies and can be easily built from sources. Building relies only on distutils.\n\n\n# Hello world with bimpy\n\nCore API tries to map to the Dear ImGui as close as possible. There is additional API, such as `bimpy.App` class that simplifies **bimpy** usage\n\n\u003ctable\u003e\n\u003ctr\u003e\u003ctd\u003e\n \nCore API\n\n\u003c/td\u003e \u003ctd\u003e \n\nUsing `bimpy.App` class \u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\n```python\nimport bimpy as bp\n\nctx = bp.Context()\n\nctx.init(600, 600, \"Hello\")\n\ns = bp.String()\nf = bp.Float()\n\nwhile not ctx.should_close():\n    with ctx:\n        bp.text(\"Hello, world!\")\n\n        if bp.button(\"OK\"):\n            print(s.value)\n\n        bp.input_text('string', str, 256)\n\n        bp.slider_float(\"float\", f, 0, 1)\n```\n\n\u003c/td\u003e\n\u003ctd\u003e \n\n```python\nimport bimpy as bp\n\n\nclass App(bp.App):\n    def __init__(self):\n        super(App, self).__init__(title='Test')\n        self.s = bp.String()\n        self.f = bp.Float()\n\n    def on_update(self):\n        bp.text(\"Hello, world!\")\n\n        if bp.button(\"OK\"):\n            print(self.s.value)\n\n        bp.input_text('string', self.s, 256)\n\n        bp.slider_float(\"float\", self.f, 0, 1)\n\n\napp = App()\napp.run()\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n\n\n![Screenshot from 2020-12-05 08-38-39](https://user-images.githubusercontent.com/3229783/101244661-bfe01600-36d5-11eb-9d39-3d19c091abba.png)\n\n   \n# Display images\n\n\nDisplay PIL image:\n\n\u003ctable\u003e\n\u003ctr\u003e\u003ctd\u003e\n \n```python\nimport bimpy\nfrom PIL import Image\n\nctx = bimpy.Context()\nctx.init(800, 800, \"Image\")\n\nimage = Image.open(\"test.png\")\nim = bimpy.Image(image)\n\nwhile not ctx.should_close():\n    with ctx:\n        bimpy.text(\"Display PIL Image\")\n        bimpy.image(im)\n```\n\n\u003c/td\u003e \u003ctd\u003e \n\n![Screenshot from 2020-12-06 06-58-02](https://user-images.githubusercontent.com/3229783/101279465-743e7280-3790-11eb-9364-137c336b78a2.png)\n\n\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n\nSimilarly, numpy arrays with 2 dimensions, 3 dimensions (2, 3 or 4 channels) of type **np.uint8** can be displayed.\n\n\nDisplay numpy, ndarray image:\n\n\u003ctable\u003e\n\u003ctr\u003e\u003ctd\u003e\n \n```python\nimport bimpy\nfrom PIL import Image\nimport numpy as np\n\nctx = bimpy.Context()\nctx.init(800, 800, \"Image\")\n\nimage = np.asarray(Image.open(\"3.png\"), dtype=np.uint8)\nim = bimpy.Image(image)\n\nwhile not ctx.should_close():\n    with ctx:\n        bimpy.text(\"Display Image of type:\")\n        bimpy.same_line()\n        bimpy.text(str(type(image)))\n        bimpy.image(im)\n```\n\n\u003c/td\u003e \u003ctd\u003e \n\n![Screenshot from 2020-12-06 07-05-08](https://user-images.githubusercontent.com/3229783/101279636-8ff64880-3791-11eb-8646-9957b0c42d1a.png)\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\nMore examples here: https://github.com/podgorskiy/bimpy/blob/master/examples/image.py\n\nNon-english text\n================\n\nUse builtin `bp.load_fonts` to load fonts with CJK, cyrillic, greek  characters\n\n\u003ctable\u003e\n\u003ctr\u003e\u003ctd\u003e\n \n```python\nimport bimpy as bp\n\n\nctx = bp.Context()\n\nctx.init(600, 600, \"Hello\")\n\nbp.load_fonts(\n    chinese=True, \n    latin_ext=True, \n    japanese=True, \n    cyrillic=True\n)\n\n\nwhile not ctx.should_close():\n    with ctx:\n        chinese = u\"學而不思則罔，思而不學則殆。\"\n        japanese = u\"二兎を追う者は一兎をも得ず。 \"\n\n        hiragana = u\"あ い う え お か ...\"\n        katakana = u\"ア イ ウ エ オ カ ...\"\n        kanji = \"川 月 木 心 火 左 北 今...\"\n\n        ukrainian = \"Садок вишневий коло...\"\n        polish = \"Hej, tam gdzieś z nad...\"\n        russian = \"Ночь, улица, фонарь, ...\"\n\n        bp.text('Chinese:')\n        bp.indent()\n        bp.text(chinese)\n        bp.unindent()\n        bp.text('Japanese:')\n        bp.indent()\n        bp.text(japanese)\n        bp.bullet_text(\"hiragana: \" + hiragana)\n        bp.bullet_text(\"katakana: \" + katakana)\n        bp.bullet_text(\"kanji: \" + kanji)\n        bp.unindent()\n        bp.separator()\n        bp.text('Ukrainian:')\n        bp.indent()\n        bp.text(ukrainian)\n        bp.unindent()\n        bp.separator()\n        bp.text('Polish:')\n        bp.indent()\n        bp.text(polish)\n        bp.unindent()\n        bp.separator()\n        bp.text('Russian:')\n        bp.indent()\n        bp.text(russian)\n        bp.unindent()\n        bp.separator()\n\n```\n\n\u003c/td\u003e \u003ctd\u003e \n\n![Screenshot from 2020-12-06 08-31-13](https://user-images.githubusercontent.com/3229783/101281665-4b24de80-379e-11eb-8170-fe09d6bfa894.png)\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n\nInstall\n=======\n\nInstallation is easy since the package does not have dependencies:\n\n```shell\npip install bimpy\n```\n\nOr you can build and install from sources:\n\n```shell\npython setup.py install\n```\n\nAll c/c++ sources are built with distutils. All you need is a compiler with C++11 support.\n\nWindows users, who use python 2.7 may encounter problems, because on Windows, python 2.7 uses MSVC 9.0, which doesn't have support for c++11. However, you still can build it with more recent MSVC (for example MSVC 14.0, which is Visual C++ 2015) using the commands below:\n\n```shell\ncall \"%VS140COMNTOOLS%\\VsDevCmd.bat\"\nset VS90COMNTOOLS=%VS140COMNTOOLS%\npython setup.py install\n```\n\nIf building on Linux, the following dependencies will be needed:\n\n```shell\nsudo apt-get install mesa-common-dev libxi-dev libxinerama-dev libxrandr-dev libxcursor-dev\n```\n\nTo build all wheels for linux package distribution (manylinux) run `build_manylinux_wheels.sh`.\n\nFor testing/debugging there is a CMakeList.txt included. It is not used by setup.py, but can be handy in order to build/debug package from certain IDEs.\n\nHow to use it?\n==============\n\nIntro\n-----\n\n**bimpy** is python binding for `dear imgui \u003chttps://github.com/ocornut/imgui\u003e`__ and tries to match the C++ API. Also, it has some additional functions to create a window and some other differences.\n\nIt has binding for the most functions from **dear imgui**. All functions are renamed from **CamelCase** to **snake_case**, which is more common for python. For example ``ImGui::InputText`` is mapped to ``bimpy.input_text``.\n\nContext and window\n------------------\n\nFirst of all, you need to import **bimpy**\n\n```python\nimport bimpy\n```\n\nDistinctively from **dear imgui**, bimpy does not have global state (**dear imgui** has it by default, but it has an option not to have one). So, you will need to create a context.\n\n```python\nctx = bimpy.Context(width, height, name)\n```\n\nWhere integers *width* and *height* specify the size of the window, and string *name* is a caption of the window.\n\nAll calls to **bimpy**'s API must be within *with* statement applied to the context object:\n\n```python\nwith ctx:\n    bimpy.text(\"Hello, world!\")\n```\n\n\nAnd there must be only one *with* statement applied to the context object per frame.\n\nOr, a second option is to manualy call ``ctx.new_frame()`` before all API calls, and then ``ctx.render()`` after.\n\n```python\nctx.new_frame()\nbimpy.text(\"Hello, world!\")\nctx.render()\n```\n\n\nYou can have multiple *Context* objects for multiple windows, however, API is not thread-safe.\n\nVariables\n------------------\n\nAll **imgui** API that provides user input (such as *InputText*, *SliderFloat*, etc.) modifies the variable through the reference to it. However, in python, such objects as integers, floats and strings are passed always by value. Because of this, **bimpy** provides special wrappers, that allow passing those variables by reference.\n\nFor example, to use *slider_float*, you will need first to create a variable that will hold the state:\n\n```python\nf = bimpy.Float();\n```\n\nYou can access the value in the following way: ``f.value``\n\nTo use it with *slider_float* simply pass it to that function:\n\n```python\nbimpy.slider_float(\"float slider\", f, 0.0, 1.0)\n```\n\n\nAll **imgui** input functions that provide multiple inputs, like *SliderFloat2*, *SliderInt4*, *InputInt3*, etc. are mapped to equivalent functions, but instead of passing an array of variables, you need to list all variables in the argument list:\n\n```python\nf1 = bimpy.Float();\nf2 = bimpy.Float();\nf3 = bimpy.Float();\n\nwhile(not ctx.should_close()):\n\twith ctx:\n\t\tbimpy.slider_float3(\"float\", f1, f2, f3, 0.0, 1.0)\n```\n\nDraw commands\n------------------\nSome draw commands are exposed. In contrast to C++ API, the exposed functions are not methods of **ImDrawList**, but global functions. All drawing functions should be called inside the *begin/end* calls of a window.\n\nList of exposed drawing functions:\n\n```python\n    add_circle(centre: _bimpy.Vec2, radius: float, col: int, num_segments: int=12, thickness: float=1.0) -\u003e None\n    add_circle_filled(centre: _bimpy.Vec2, radius: float, col: int, num_segments: int=12) -\u003e None\n    add_line(a: _bimpy.Vec2, b: _bimpy.Vec2, col: int, thickness: float=1.0) -\u003e None\n    add_quad(a: _bimpy.Vec2, b: _bimpy.Vec2, c: _bimpy.Vec2, d: _bimpy.Vec2, col: int, thickness: float=1.0) -\u003e None\n    add_quad_filled(a: _bimpy.Vec2, b: _bimpy.Vec2, c: _bimpy.Vec2, d: _bimpy.Vec2, col: int) -\u003e None\n    add_rect(a: _bimpy.Vec2, b: _bimpy.Vec2, col: int, rounding: float=0.0, rounding_corners_flags: int=Corner.All, thickness: float=1.0) -\u003e None\n    add_rect_filled(a: _bimpy.Vec2, b: _bimpy.Vec2, col: int, rounding: float=0.0, rounding_corners_flags: int=Corner.All) -\u003e None\n    add_rect_filled_multicolor(a: _bimpy.Vec2, b: _bimpy.Vec2, col_upr_left: int, col_upr_right: int, col_bot_right: int, col_bot_lefs: int) -\u003e None\n    add_triangle(a: _bimpy.Vec2, b: _bimpy.Vec2, c: _bimpy.Vec2, col: int, thickness: float=1.0) -\u003e None\n    add_triangle_filled(a: _bimpy.Vec2, b: _bimpy.Vec2, c: _bimpy.Vec2, col: int) -\u003e None\n```\n\nSimple usage example below:\n\n![hello-world](https://i.imgur.com/MU5Vhfl.png)\n\n```python\n\timport bimpy\n\timport numpy as np\n\n\tctx = bimpy.Context()\n\n\tctx.init(1200, 1200, \"Draw Commands Test\")\n\n\twith ctx:\n\t\tbimpy.themes.set_light_theme()\n\n\tDATA_POINTS = bimpy.Int(30)\n\tCLASTERS = bimpy.Int(4)\n\n\tstd = bimpy.Float(0.5)\n\n\tcolors = [0x4b19e6, 0x4bb43c, 0x19e1ff, 0xc88200, 0x3182f5, 0xb41e91, 0xf0f046, 0xf032e6, 0xd2f53c,\n\t\t\t  0xfabebe, 0x008080, 0xe6beff, 0xaa6e28, 0xfffac8, 0x800000, 0xaaffc3, 0x808000, 0xffd8b1,\n\t\t\t  0x000080, 0x808080, 0xFFFFFF, 0x000000]\n\n\tdatapoints = []\n\n\n\tdef generate_fake_data():\n\t\tdatapoints.clear()\n\t\tfor i in range(CLASTERS.value):\n\t\t\tx = np.random.normal(size=(DATA_POINTS.value, 2))\n\t\t\talpha = np.random.rand()\n\t\t\tscale = std.value * np.random.rand(2) * np.eye(2, 2)\n\t\t\tposition = np.random.rand(2) * 5\n\t\t\trotation = np.array([[np.cos(alpha), np.sin(alpha)], [-np.sin(alpha), np.cos(alpha)]])\n\t\t\tx = np.matmul(x, scale)\n\t\t\tx = np.matmul(x, rotation)\n\t\t\tx += position\n\t\t\tdatapoints.append((x, rotation, position, scale))\n\n\taxis = x = np.array([[-1, 0], [1, 0], [0, -1], [0, 1]])\n\n\twhile not ctx.should_close():\n\t\tctx.new_frame()\n\n\t\tbimpy.set_next_window_pos(bimpy.Vec2(20, 20), bimpy.Condition.Once)\n\t\tbimpy.set_next_window_size(bimpy.Vec2(800, 600), bimpy.Condition.Once)\n\t\tbimpy.begin(\"Drawings\")\n\n\t\twindow_pos = bimpy.get_window_pos()\n\n\t\tcenter = bimpy.Vec2(100, 100) + window_pos\n\t\tm = 100.0\n\t\tfor i in range(len(datapoints)):\n\t\t\t(x, R, P, S) = datapoints[i]\n\n\t\t\tfor j in range(x.shape[0]):\n\t\t\t\tpoint = bimpy.Vec2(x[j, 0], x[j, 1])\n\t\t\t\tbimpy.add_circle_filled(point * m + center, 5, 0xAF000000 + colors[i], 100)\n\n\t\t\taxis_ = np.matmul(axis, S * 2.0)\n\t\t\taxis_ = np.matmul(axis_, R) + P\n\n\t\t\tbimpy.add_line(\n\t\t\t\tcenter + bimpy.Vec2(axis_[0, 0], axis_[0, 1]) * m,\n\t\t\t\tcenter + bimpy.Vec2(axis_[1, 0], axis_[1, 1]) * m,\n\t\t\t\t0xFFFF0000, 1)\n\n\t\t\tbimpy.add_line(\n\t\t\t\tcenter + bimpy.Vec2(axis_[2, 0], axis_[2, 1]) * m,\n\t\t\t\tcenter + bimpy.Vec2(axis_[3, 0], axis_[3, 1]) * m,\n\t\t\t\t0xFFFF0000, 1)\n\n\t\tbimpy.end()\n\n\t\tbimpy.set_next_window_pos(bimpy.Vec2(20, 640), bimpy.Condition.Once)\n\t\tbimpy.set_next_window_size(bimpy.Vec2(800, 140), bimpy.Condition.Once)\n\t\tbimpy.begin(\"Controls\")\n\n\t\tbimpy.input_int(\"Data points count\", DATA_POINTS)\n\t\tbimpy.input_int(\"Clasters count\", CLASTERS)\n\n\t\tbimpy.slider_float(\"std\", std, 0.0, 3.0)\n\n\t\tif bimpy.button(\"Generate data\"):\n\t\t\tgenerate_fake_data()\n\n\t\tbimpy.end()\n\n\t\tctx.render()\n```\n\n\nAcknowledgements\n================\n\n* robobuggy https://github.com/gfannes\n* njazz https://github.com/njazz\n* Florian Rott https://github.com/sauberfred\n* zakx https://github.com/zakx\n* Joel Linn https://github.com/JoelLinn\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpodgorskiy%2Fbimpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpodgorskiy%2Fbimpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpodgorskiy%2Fbimpy/lists"}