GithubHelp home page GithubHelp logo

techartorg / bqt Goto Github PK

View Code? Open in Web Editor NEW
157.0 19.0 24.0 459 KB

A Blender add-on to support & manage Qt Widgets in Blender (PySide2)

Home Page: https://github.com/techartorg/bqt/wiki

License: Mozilla Public License 2.0

Python 100.00%
blender blender-addon pyside2 tech-art qt5

bqt's Introduction

BQt

PyPI version latest tag

Add QT support to Blender, letting you create custom UI for your addons with PySide2 QtWidgets. custom ui sample

Features

feature description
fully custom UI Instead of feeling limited by N-Panel only UI. Do whatever you want.
cross app Qt widgets run nativaly in Krita, 3ds Max, Maya, … and are great to use in cross dcc pipelines
existing community hundreds of QT widgets on GitHub you can reuse, and lots of stack exchange questions answered regarding qt.
Themed BQt applies the blender-qt-stylesheet so qt widgets will by default look similar to Blender.

Requirements

  • Blender 2.83or higher.
  • Windows or Mac
  • PySide2
  • PyObjC & iterm2 (Mac only)

How to use

  1. Install & enable the bqt addon (see installation docs)
  2. Create & show your Qt widget, bqt will automatically register it with it's widget manager.
  • The bqt env vars let you toggle bqt features on and off
  • sample code: bqt_demo shows you how to use bqt with several qt demos you can run in Blender

contribute

  • i'm a technical writer and want to contribute to the docs. see readme on the wiki.
  • i'm a dev and want to contribute to bqt code, see contribute guidelines.
  • i'm a user or tester and want to report a bug or request a feature, please post here

Community

Discuss BQt on

bqt's People

Contributors

amatobahn avatar bob-white avatar friedererdmann avatar hannesdelbeke avatar jeffhanna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bqt's Issues

crash access violation on load scene

pretty major bug on my new laptop:

  1. open blender 3.2.1
  2. add a cube to the empty scene, (no camera or default cube)
  3. save scene
  4. open blend file
  5. blender crashes with ACCESS VIOLATION:
I1228 21:50:46.768488 25452 device.cpp:32] CUEW initialization succeeded
I1228 21:50:46.768488 25452 device.cpp:34] Found precompiled kernels
I1228 21:50:46.784168 25452 device.cpp:55] HIPEW initialization failed: Error opening HIP dynamic library
Error   : EXCEPTION_ACCESS_VIOLATION
Address : 0x00007FF653BE84C4
Module  : blender.exe
Thread  : 0000636c
Switching to fully guarded memory allocator.
  • default blender loads the file without crashing
  • a previously saved scene oddly can be opened in bqt without crash

pip install cleanup

pip instal cleanup

original convo

Hannes
BQT discussion
IMO the current setup that auto adds files to your blender install is dirty.
After installing bqt, your vanilla blender changed, and when uninstalling it doesn't clean up.
e.g. when used in a studio pipeline, you might want your own startup file instead.
and when not running bqt, there now is a leftover startup file from bqt that will run.
Would this be a bad idea if we changed to this:
pip install bqt adds a py-module, nothing else. keep vanilla blender clean.
if the user needs/wants to add it to startup, they can run

import bqt
bqt.install_startup()

Frieder Erdmann
yes, its also bad because it breaks if you install bqt to a virtual environment

Chris Cunningham
ah that is pretty bad then, i tend to just assume a venv for python stuff

Dominic Noble
Not requiring to add it to Blender's site-packages would be super useful, I've had to make some very specific workaround for a deployment tool I'm making just for BQT.

Bob White
I think part of the issue when we first put it together was blender didn't make it super easy to ensure that binaries were installed on PATH in a way that the dlls would be found.
From what I remember, most of those issues have been dealt with at this point, so its possible the current installation process is just a weird legacy quirk

Bob White
Or it might have been a byproduct of me using pywin32 and it being weird as hell to install now that I think about it.

Greg Amato
Definitely byproduct of pywin32

pip install fails

PS C:\Program Files\Blender Foundation\Blender 3.0\3.0\python\bin> python.exe -m pip install bqt
Collecting bqt
Downloading bqt-0.2.0.tar.gz (31 kB)
Preparing metadata (setup.py) ... done
Collecting PySide2
Downloading PySide2-5.15.2.1-5.15.2-cp35.cp36.cp37.cp38.cp39.cp310-none-win_amd64.whl (137.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 137.4/137.4 MB 26.2 MB/s eta 0:00:00
Collecting shiboken2==5.15.2.1
Downloading shiboken2-5.15.2.1-5.15.2-cp35.cp36.cp37.cp38.cp39.cp310-none-win_amd64.whl (2.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.3/2.3 MB 29.6 MB/s eta 0:00:00
Using legacy 'setup.py install' for bqt, since package 'wheel' is not installed.
Installing collected packages: shiboken2, PySide2, bqt
WARNING: Failed to write executable - trying to use .deleteme logic

ERROR: Could not install packages due to an OSError: [WinError 2] The system cannot find the file specified: 'C:\Python310\Scripts\pyside2-designer.exe' -> 'C:\Python310\Scripts\pyside2-designer.exe.deleteme'

possible option to remove window wrap need

right now we wrap blender in a qt window. this is the source of all our current issues.

  • focus issue: key stuck #60
  • exception on closing blender #47
  • fullscreen operator doesnt work #3
  • harder to support qt across different OS #75
  • missing file name in title bar #68
  • preferences not saved #64
  • wrap wrong window #65
  • #72
  • #45
  • #48
  • #29
  • #21
  • #109

unsure if context overrider for operators run from qt would be solved if not wrapped
investigated, it doesn't solve #62

parent widgets to blender with ctypes

using ctypes on our widget windows might solve the parenting instead
https://blenderartists.org/t/floating-windows/1163493/317

wrap widgets in a window managed by blender

Can we either extend Blender source code, creating an official PR in the blender repo to support empty windows.
Or investigate what we already can do with the current exposed Python code.

auto parent widgets

but ideally bqt works with 3rd party widgets and their show function. not requiring altering the show function.
Can we find a way to do this automatically?

Moved this to it's own issue #71

Mac OS X support

I see there is an option to run this code for MacOSX. Is it supported?

rename master to main

when all PRs are merged in, it should be a good time to rename master to main.
would need assistance of an admin since I can't edit default branch / repo options

save scene confirm dialogue behind qt windows

qt windows are always on top of blender,
so closing the blender scene results in the save scene confirm dialogue to be hidden behind any open qt windows.

expected behaviour:
save dialogue on top of qt windows.

this could be achieved by creating our own save dialogue in qt

add editable install instructions for bqt devs

for development purpose, we currently symlink a repo to the correct location in blender modules or addons folder.
so any changes auto affect blender, without need to reinstall bqt or copy folders over.

however symlink sometimes causes some bugs, where files might be deleted if i uninstall the addon.
and if i hadnt commited these files, they are gone forever.

editable pip install should be a cleaner approach similar to symlinking, with .pth file cleanly linking this.
but haven't gotten this to work yet in Blender.
think it might be related to the fact that .pth files only work in site packages folder, and blender doenst use these.

investigate

Original symlink instructions
When working on the bqt code from a repo, to prevent having to reinstall bqt every time you make a change, you can symlink the bqt folder to your blender addons folder to develop bqt. Any updates in the repo are then reflected in blender on restart. e.g.:
mklink /J "C:\Users\USERNAME\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\bqt" "C:\Users\hanne\OneDrive\Documents\repos\_Blender\bqt\bqt"

Getting it to work...

Hey

Apology, I know I'm dense but I can't get it to run.

Do we copy bqt in to blender/scripts/addons? Is it an addon that I need to enable in the community area? I can't find any bqt or

    bl_idname = "qoperator.global_app"
    bl_label = "Global QApplication"

Info inside blender addons menu...

Thanks for hello world exampel! looks simple enough to "run" but how to set the lib itself for it?

TIA

add support for deregistration

To be able to turn bqt into a blender addon, which can be enabled/disabled,
bqt needs deregistration support.

on deregistration, bqt should clean up the QApplication, any widgets, and un wrap blender from Qt.

git+ install fails due to charmap error

likely emoji in readme causes the bug

repro 100%

pip install git+https://github.com/techartorg/bqt.git

original report

Dominic Noble

It appears that this commit to BQT has broken something: cbdccf1
If I try to install any earlier version via PIP using the git+ method, it's fine, but if I try that one or any after it I get a metadata-generation-failed error. Not sure if it's just me that gets that though?

Possibly the inclusion of the ⚠️ emoji, as it's a charmap error I'm getting

Yep removed that locally when running python setup.py install and it works just fine

H

that's so weird, that a readme character affects installation 😱

could you make a ticket with the git+ command you run? so i can repro it, and fix it. (edited)

think chaning the line in setup.py to this should fix it.
long_description = (this_directory / "README.md").read_text(encoding="utf-8")
source

Linux Support ?

I've recently started a new project and I found that bqt could be extremely beneficial to it. However, I've noticed that there's currently no Linux support for bqt. As a Linux user, this is a crucial feature for me. I understand that what bqt is already doing is complex and adding Linux support may present specific challenges, specially considering all the different window systems available and the Wayland monster under the bed, but maybe a simple X11 version can be a good start ?

Although I'm not an expert, I have some experience with Python and Qt, and I'd love to offer my help in bringing Linux support to bqt. I'm looking forward to your thoughts on this, any previous attempts or known blockers, any advice or resources that could help me in potentially giving it a try will we awesome!

What I already tried was to use xprop to get the window id and return it as part of the _get_application_hwnd method, but that doesn't seem to work properly, the Blender Qt window container is actually visible as a second window, the new widgets are not parented on top of the original blender window but the Blender Qt one, and the window is frozen, I need to run QApplication.processEvents() to refresh.

Its also intriguing that you didn't create an event loop, but I'm sure there might be some design reasons for that

Thanks in advanced!

blender_window garbage collect bug

when trying to get the parent from the blender widget python returns an exception instead
please note first time you run this in blender it works, but second time you get error.

from PySide2.QtWidgets import QApplication
app = QApplication.instance()
a = app._blender_window.parent() 

# first time
# <PySide2.QtGui.QWindow(0x1e6a52d5120, name="QWindowContainerClassWindow") at 0x000001E6A66E7340>

# second
# Error: Python: Traceback (most recent call last):
#  File "\Text", line 3, in <module>
# RuntimeError: Internal C++ object (PySide2.QtGui.QWindow) already deleted.

same if you try access the children, or any other attr

Originally posted by @hannesdelbeke in #42 (comment)

add dark bar option

default blender window has a dark bar in latest blender version
image

qt default widgets don't

TODO add support to match blender's style

dynamically support blender themes in the qt stylesheet

UX / visual improvement only

Current blender stylesheet that ships with bqt is darkmode, which is Blender's default UI.
but you can customise Blender's UI with themes.
Ideally the QT theme would load these values dynamically. Note that this might be worth it's own repo/project since this likely is a big task.

update to pyside6

update to pyside6

and add support for all other qt bindings. pyside2 pyqt5 pyqt6

first time qt window size is too small

when blender is wrapped in qt for the first time
the window is too small

we can get the size from blender window before we wrap it, and the set the wrapped window to this size.

auto parent widgets without parent

devs currently need to manually parent any widget to the bqt window widget.
to ensure the qt widgets use

  • the blender stylesheet
  • and stay in front of blender, and are minimised when blender minimises

this means that any existing qt code that creates widgets needs to be changed, or the widget created needs to be parented.

A nicer way, would be to auto parent any qt widget.

proposal 1, monitor loop, auto parent top level widgets

  • an option in BQT to constantly check for widgets without parent.
  • if found parent the widget to the bqt window.

this means widgets created in bqt would just work.
no need for the dev/user to know how to parent it.
it would let the dev run pure qt code that also would work outside of blender, or inside blender without bqt.
whereas bqt parenting only works in blender if bqt is installed.

cons

some apps, e.g. Krita, have nearly every widget/menu as a top level widget.
So we can assume some devs might have done the same for their qt tools. In which case auto parenting them might break hierarchy.
No examples known currently except Krita which won't run in Blender

issue settings not saved

problem

when closing blender by clicking ❌ to close the window., on restart addons don't remember their enabled/disabled settings. Likely all preferences are not being saved.

trackdown

this happens in the latest BQT versions, but was not an issue in older BQT versions.

might be related too #47

pip install fails to copy startup script if wheel module is installed.

#15 Gets us really close to a one and done installation process, except when the user has wheel installed as pypi defaults to installing a wheeled version by default. Which skips the install script.

Need to figure out how to either adjust the package such that it can't be installed as a wheel (not sure if this is possible, and is probably a terrible long term solution)

Or figure out some other way to finalize the installation after the wheel is installed.

blender crash - Win32 Error# (6): The handle is invalid.

blender crashes when running

import bqt 
from bqt import hello_world
bqt.register()
bqt.instantiate_application()  # <== crash here

upon investigation it happens during the init of BlenderApplication()
blender crashes on this line in bqt/blender_applications/blender_application.py

self._blender_window = QWindow.fromWinId(self._hwnd)
self.blender_widget = QWidget.createWindowContainer(self._blender_window)  # crashes here

the error thrown is
Win32 Error# (6): The handle is invalid.

document operators

operators cause tons of issues with bqt.
try avoid them where possible (it almost always is)

TODO: document this.
add utils to bqt

notes

when using operators from qt, i always use

window = bpy.context.window_manager.windows[0]
with bpy.context.temp_override(window=window):
    mycode

because when querying current window. blender will say None since not compatible with current window (qt)

some operators need more context parameters, then just add them to the override. e.g.

window = bpy.context.window_manager.windows[0]
with bpy.context.temp_override(window=window, object=obj, active_object=obj):
    mycode

but ideally avoid ever using operators. they suck and make hard bugs. almost anything can be done without operators with a bit more work from your side.

How to do hello world window

Hey

Like post says, I can't find any readme/how to here. How to do basic window, where do I place files/etc/etc ?

Getting Icon fails on windows when blender is executed from command line

when i execute blender via the CLI the call to find the blender icons fails

blender.exe --debug --python bqt.py

Traceback (most recent call last):
  File "E:\projects\rsg\bqt\bqt.py", line 318, in execute
    self.__qapp = instantiate_application()
  File "E:\projects\rsg\bqt\bqt.py", line 342, in instantiate_application
    app = BlenderApplication(sys.argv)
  File "E:\projects\rsg\bqt\bqt.py", line 93, in __init__
    icon = self._get_application_icon_windows()
  File "E:\projects\rsg\bqt\bqt.py", line 253, in _get_application_icon_windows
    hdc.DrawIcon((0, 0), large[0])
IndexError: list index out of range

missing bl_info dict

Has anyone else had problems with the latest bqt version?
Using 3.3LTS and the addon no longer has the bl_info dict which causes an error on start up

slack chatlog: Shea Richardson

I had to do some fix ups to get it functional for 3.3 LTS
main one was this:
https://tech-artists.slack.com/archives/C0F73KP2N/p1666962461134569
Has anyone else had problems with the latest bqt version?
Using 3.3LTS and the addon no longer has the bl_info dict which causes an error on start up
could have been related to how we load auto-load our plugins
it caused an infinite loop if it did not exist

reported by Shea Richardson
who will make a PR 🙏

simplify widget registration with bqt manager

  • expose command to bqt.add
    current one is too verbose

it automatically works if you disabled qt wrapping for bqt by setting the env var BQT_DISABLE_WRAP to 1
it assumes you parented all widgets with bqt.widget_manager.add(my_widget)

  • add instructions to README on how to use bqt
  • inform users that blender_widget is legacy

focus method uses ctypes.windll on mac OS

Since the focus.py module imports ctypes, this likely works only on Windows.

TODO

  • Move the windows logic to the windows class.
  • figure out how to split the logic to support multiple OS in the future
  • test on Mac and Linux

relates to

update project description to appear in search results

can we update the GitHub bqt description?
bqt won't show up when searching in GitHub for "blender qt",
since it doesn't has the word qt in the description.

current description

Files to help bootstrap PySide2 with an event loop within Blender

Hello_World not working

Hi all,

I am getting this error and I was hoping that you could help?

>>> from bqt import hello_world
>>> hello_world.demo()
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/bqt/hello_world.py", line 46, in demo
    main_window = QApplication.instance().blender_widget
AttributeError: 'NoneType' object has no attribute 'blender_widget'

Thanks
AG

figure out why bqt works without event loop

when using qt without bqt, creating a QApplication and exec it in Blender freezes Blender input, untill we close the widget.
You can test this with following pseudo code

app = QApplication()
w = QWidget()
w.show()
app._exec()

to solve this, we usually create an event loop in QT scripts.

At some point in refactoring BQT, I removed the event loop since it wasnt needed to prevent blender from freezing.
But I don't understand why. It would be good to figure out what part of the code in BQT prevents Blender from freezing.

pointed out in #70, where we look at adding bqt support to linux.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.