OpenGL with PyFace - python

How I can write an OpenGl application using Enthought Framework? I created a TasksApplication and I am stuck on this tutorial, I don't know what I can use instead PythonEditor there. I need to create something where I will be able to render.
UPDATE:
I changed the code to
def create(self, parent):
widget = GLWidget(parent)
self.control = widget
Where GlWidget is implemented like in this example.
And I have a runtime crash. But I am able to run the GL script from the example above.
UPDATE2:
Log file
UPDATE4:
Code was updated according to #Robert Kern suggestions. Now it works.
Min Example
MinExample 7z

The control trait of a TaskPane is just the Qt widget object that you are using. In the example that you link, we happen to be getting it from another PyFace widget that wraps a Qt widget in a similar fashion, so we just grab the control attribute from it. You should just directly use a QGLWidget as the control of your pane. Please consult the Qt documentation for how to use it. You can use PyOpenGL in the paintGL(), etc. methods to do the actual rendering.

Related

how to use qt in python

I am working on a module for 3D slicer. A chunk of the template code is pasted below. It is using qt for GUI. I need to add my own GUI here, But I am not able to find how to add toolbar here. I am not able to find any documentation regarding this. Whenever I google I get PyQt4, is that different from this ? So, my question is please explain the diference between qt and PyQt4 and how can I add toolbar here ?
def __init__(self, widgetClass=None):
self.parent = qt.QFrame()
self.parent.setLayout( qt.QVBoxLayout() )
# TODO: should have way to pop up python interactor
self.buttons = qt.QFrame()
self.buttons.setLayout( qt.QHBoxLayout() )
self.parent.layout().addWidget(self.buttons)
self.addDataButton = qt.QPushButton("Add Data")
self.buttons.layout().addWidget(self.addDataButton)
self.addDataButton.connect("clicked()",slicer.app.ioManager().openAddDataDialog)
self.loadSceneButton = qt.QPushButton("Load Scene")
self.buttons.layout().addWidget(self.loadSceneButton)
self.loadSceneButton.connect("clicked()",slicer.app.ioManager().openLoadSceneDialog)
import statement
import vtk, qt, ctk, slicer
I think the form/GUI is created by tool. You can have a look at this
You can add your PyQt4 code in this, that should work fine.
If the import statement is qt, 2 solution : it use an alias (it would be weird) or it use a pyqt wrapper which allow to use PySide2, PyQt5, PySide and PyQt4 the same base code.
Maybe this one : https://github.com/mottosso/Qt.py
maybe another ... If you have a requirement.txt you should be able to know
please explain the diference between qt and PyQt4
Qt is cross-platform application framework, using C++ extensions.
In order to use it in python you need a wrapper and this is what PyQt, PySide and the rest are.
Check your application documentation and probably you will find if it uses PyQt4,5, PySide or something else.

Python - Kivy, Have I Structured this wrong?

At the moment I have one Floatlayout in SHeditorMain, Inside the class SHeditormain i've declared a bunch of widgets (buttons, popups, labels, etc..) and used self.add_widget to add them.
Now i want to create a new window that opens up inside/over the FloatLayout and i can't seem to get it to works. All the examples i've seen so far regarding multiple windows is either using App as main class for the creation of widgets inside the layouts. Any suggestions or do i have to restructure the code?
class SHeditorMain(FloatLayout):
def __init__(self, **kwargs):
super(SHeditorMain, self).__init__(**kwargs)as
self.add_widget(blabla)
self.add_widget(blabla)
self.add_widget(blabla)
self.add_widget(blabla)
self.dbconnection = DBconnection()
#declare popups etc
def functionEvents(self, instance):
yaddayadda
def functionEvents(self, instance):
yaddayadda
def functionEvents(self, instance):
yaddayadda
class SHeditor(App):
def build(self):
self.root = SHeditorMain()
return self.root
Please read this answer about multiple "windows" and why it may not be desired. I can recommend you to have kivy window maximized and using ModalView as a pseudo-form that can be dragged and has some button that would close it. More control over everything, cleaner code, beginner friendly. Create a custom widget that inherits from ModalView and what it does is up to you.
You can place modals wherever you want them to be - look into popup source code in repo how the positions are set. You'll basically end up with a custom Popup that you can control without crippling the original widget.
Another way may be to use ScreenManager(or PageLayout, Carousel, xyz other widgets) which provide mobile-/presentation-like view. The sooner you get to kv language, the sooner you'll have less troubles to imagine that stuff out of pocket e.g. you see a fancy app, you can open kivy-designer or for more control/less fancy go for KivyCatalog and just type what you see that's how straightforward the kvlang is.
Example with Modals:(old attempt to create windows-like... something via Kivy = FloatLayout with Scatter(only drag enabled) as "windows")
Which leads me to the conclusion that if you think you need multiple windows or another window would be nice for whatever reason but you are not sure if it'd work or something - you actually don't and you are overcomplicating things, which steal your attention from the important parts of your code to UI.
(PS, I'd edit the answer mentioned at the top, but in that question user has a little bit more complicated problem)

Python / Gtk - embedding into X window ID

I wrote a program using Qt 4.8, which used the QX11Embed mechanism to embed a useful little python/gtk widget.
I forked the widget, got its winID and then embedded it in a Qt container widget. This worked well
Then I had to change to Qt5 and the whole QX11Embed code has been dropped:(
Apps that take a winID as a commandline arg and embed into it, like mplayer or xterm, still work with Qt5. You just create a container, pass its winID to the app, but not the other way around.
I am not a python programmmer, but even so I am considering changing the widget itself so that it embeds itself into a given winID, but I cannot find any examples or docs.
Every search that mentions embedding goes to the plug/socket mechanism for embedding INTO gtk, nothing the other way around.
How should I go about it, is it even possible, any links etc
Thanks

Custom Qt Widgets with python for Qt Designer

I am trying to write a custom widget for the Qt Designer using only Python. I was following a couple of tutorials I found online but none of them were working or anything close to what I would call to be a minimum working example.
So my questions are:
What steps are involved to make a a custom widget appear in the Widget Box of Qt Designer?
If you can spare the time: Please provide a minimum working example (like a widget with a label in it saying "A truly minimal working Qt custom widget example").
Or is it maybe not possible at all to include a custom widget using only python?
There are very few examples available on how to make a custom widget in pyqt. I wrote this article with a working example: Making a Custom Widget in PyQt
Here is the answer to your question #3: How do I use promote to in Qt Designer in pyqt4?
I am using PySide and it works the same way. This method works directly with your Python custom widget code. You do not need to write any separate plugin code.
After you have promoted your custom widget, you can right click on it and add your signals with "Change signals/slots..."
I would recommend putting all you widgets in a YourCostumWidgetsPack.UI file, and then when you load this file in Qt Designer, in addition to the UI you are working. It will load all your custom widget information.
I found this article to be your answer: https://doc.qt.io/archives/qq/qq26-pyqtdesigner.html
But, I haven't been able to install it in Qt Designer though :D

show html with pyqt4

print "hellp world" :)
i want to ask you if exist a function or class hwo can show the html code like the browser's jobe
thx
There is QtWebKit Module within Qt. It incorporates webkit rendering engine. Whereas you can get access to Qt classes using python binding, you can use Qt official manual as help. Qt designer is also included into pyqt - you can try using it to design your application's GUI (I'm almost sure you'll be able to find web browser component or similar there).
As for using html tags to decorate labels and other components showing text, you can refer to this question.

Categories