Is it possible to use GL functions like glGetString without showing the widget first?
The basic use case would be taking this helloworld and instead of showing the widget, maybe I want to print a command line usage message with the GPU information and GL version. The script currently does this already after showing the widget.
In my own application I have a subclass of a QOpenGLWidget and I've tried manually creating a QOpenGLContext, setting the format, and making it current (with and without .create()), but that didn't seem to work. The subclass seems to work fine when shown.
Any help is much appreciated.
Further details: I'm one of the maintainers of the python library vispy and I'm trying to update our PyQt5 backend to use QOpenGLWidget instead of QGLWidget. The pull request is here if anyone wants to tell us what we're doing wrong: https://github.com/vispy/vispy/pull/1394
A OpenGL context needs a "window" (exactly needs a "Device Contex" or a "Display", depending on the OS) to render to. That window doesn't need to be visible, just that the gl context is current to it.
The easiest way is to hide() (or don't call show()) the window at its creation. You can make it visible later.
Related
.Hi everyone,
I`m still pretty new to python so, bear with me.
I am trying to setup a custom UI Window in maya, with a custom camera.
For this i am using the panelLayout, modelPanel and modelEditor commands.
Now, it's working so far with one exception.
The flags i've set for the modelEditor seem to be ignored entirely and i dont know why.
So here is the code:
if cmds.window("myWindow", exists=True):
cmds.deleteUI('myWindow')
cmds.window("myWindow")
cmds.paneLayout(configuration="single", w=1000, h=500)
cmds.modelPanel()
cmds.modelEditor(modelPanel="modelPanel4", allObjects=False, polymeshes=True, imagePlane=True, displayAppearance="smoothShaded")
cmds.showWindow("myWindow")
I want only polyMeshes and imgagePlanes to show in this window, aswell as to have the displayAppearance set to "smoothShaded".
Nnothing else, including the grid, should be visible at this point.
but, everything show up in the window, as if i had'nt set a single flag.
any help is much appreciated
All the flags in modelEditor() work fine in Maya 2016.5 and Maya 2018. I've checked it.
import maya.cmds as cmds
if cmds.window("myWindow", exists=True):
cmds.deleteUI('myWindow')
cmds.window("myWindow")
cmds.paneLayout(configuration="single", w=1000, h=500)
cmds.modelPanel()
cmds.modelEditor(modelPanel="modelPanel4",
allObjects=False,
polymeshes=True,
imagePlane=False,
displayAppearance="smoothShaded")
cmds.showWindow("myWindow")
The problem might appear when you click myWindow or press any key. It'll show not perspective view (modelPanel4) but the other view (for instance camera1 view).
I wants to build some GUI for retrieving and displaying some data in real time. So I though of embedding a matplotlib figure in a pyqt5 GUI, and followed this example here (https://matplotlib.org/examples/user_interfaces/embedding_in_qt5.html). However, there will be some resource for my application that require a safe destruction at exit. So I tried to overwrite the closeEvent() function of MyMplCanvas with
def closeEvent(self,ce):
print('closeEvent')
super().closeEvent(ce)
But it does not seem to show up when I run the program. Is this expected or is there anything wrong with the program? If this is not the proper way to do so, what is the right way to do some clean-up during the destruction of a QWidget?
Thanks a lot!
I am trying to code a message box that just pops up and says something and has a single button to close it however as I only have a small amount of text in the box the icon/image to the left of it is huge and looks bad. I want to know how to remove it. I am also having trouble making custom message boxes. Tutorials say that this is how you make a custom message box:
box = QMessageBox()
box.setText('text')
box.addButton(QPushButton('Close', self))
box.exec_()
However this just closes my program and returns a 1. My current code uses the about method of QMessageBox():
box = QMessageBox().about(self, 'About', 'This is a test Program')
However this has that large icon in the text window and I can't seem to do anything else to the box as it just stops the program and returns 1 again
I am in desperate need of some decent PyQt documentation. I can't seem to find documentation on much at all unless it is in C++. For instance I cannot seem to find any information of options other than question and about for QmessageBox. So if someone could also show me where some proper documentation lives it would prevent me asking too many questions here
Rather than PyQt documentation, it is better to directly use Qt documentation. You only need to switch your language mindset from Python to C++, there and back. It is not that difficult. :) See e.g. http://doc.qt.io/qt-4.8/qmessagebox.html#addButton or http://doc.qt.io/qt-4.8/qmessagebox.html#about I think this is very detailed documentation, unrivaled by most other frameworks.
Note that there are three overrides of addButton(). From the documentation it seems that you either need to pass two arguments to box.addButton(QPushButton('Close', self), QMessageBox.RejectRole) (you forgot the role!) or better, you use the override which uses standard buttons, then you only pass one argument: box.addButton(QMessageBox.Close).
And one more tip for you: I also find it easier to debug my program with PySide than PyQt because unlike PyQt, PySide catches the exception, prints that to console and keeps running. While PyQt usually just silently crashes leaving you clueless. Most of the time, I am using shims Qt.py https://pypi.python.org/pypi/Qt.py/0.6.9 or qtpy https://pypi.python.org/pypi/QtPy to be able to switch from PyQt to PySide on the fly. It also allows switching between Qt4 and Qt5 bindings easily.
I am currently using the Python Webkit DOM Bindings to interact with a website programmatically and that's working for me.
The only problem is that it insists on opening a GTK window to display the page. Has somebody figured out a way to prevent it from opening a window? I.e. to use it in a headless way?
I'm initializing the view like this:
wv = pywebkitgtk.WebView(1024, 768, url=url)
which implicitly opens the GTK window and then I have an onload event-handler to manipulate the DOM.
I first thought of subclassing WebView, but that's not possible because it is a compiled class.
Any other ideas?
I'm the developer responsible for pythonwebkit, and I have a great deal of expertise covering these areas across several platforms. Realistically, you really, really want a completely "headless" WebKit port. In pythonwebkit that actually shouldn't be too hard to do, as there are only three "entry point" functions (one for window, one for document, and one for XMLHTTPRequest).
Really, somebody should do a proper "completely headless" port of WebKit. There already is an example program which is pretty close in WebKit's source tree, maybe that will get you started.
I've been using PyQT. PyQTWebView runs on Webkit and works great. Check out Ghost.py to get started, or use PyQT's API directly. Runs fully headless, and supports a decently recent build of Webkit.
You could try using Xvfb. I like using the command line and setting my display manually, but if you don't like that you could use this: http://cgoldberg.github.io/xvfbwrapper/
Can you get a handle to the GTK window and then call window.hide()? Otherwise, you might just have to use the full Webkit library.
Create a window and add the webview there, and never show the window..
I have webviews running without showing them, and can call a show_all if I need to show them.
web_view = pywebkitgtk.WebView()
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
sw = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
sw.add(web_view)
window.add(sw)
#window.show_all()
I'm still starting out with PyQt with QtDesigner using eric4 (and still studying python as a whole).
Anyway, as I've designed in a GUI using QtDesigner I've just made a Qlabel as a placeholder which is intended to update with the latest ID that has access to a SQLite database which I'm building. I want it to setlabel to change to the next slot available in ID primary key but I honestly don't know how.
I've tried to change the UI compiled form as I noticed that it is this line:
self.ID_Number.setText(QtGui.QApplication.translate("Dialog","IDLabel", None, QtGui.QApplication.UnicodeUTF8))
that sets the label of the supposed ID_Number which would communicate with the SQLite. But I always get a compiling error when I changed "IDLabel" to a variable. I've checked that it is supposed to be a constant but would it be possible that it can be a variable instead? Or am I doing wrong to use a QLabel in QtDesigner and I should use something else?
Any help in solving the wall I'm trying break is very much appreciated bows deeply
The translate function call is used for multi-language support. You can remove it in this case and simplify the code to the following.
self.ID_Number.setText(somePythonStringVariable)