Working with PyQt4 - python

I''ve been experimenting with PyQt4 and I'm having a hard time with getting it to run the way I need it to. What I'm looking for is a way to have my own code run in a widget independent of gui events. Is there something like an 'onRender' command for your widget to run bckground code?

Related

How to call independent or async func in PyQt5

I have a basic PyQt5 application. I want to make it so that when a certain button is clicked, a function is called that will run until another button is clicked. How is it possible to implement it?
Something like this (of course it doesn't work):
...
self.ui.start_button.clicked.connect(infinity_before_cancel_method)
self.ui.stop_button.clicked.connect(infinity_before_cancel_method)
...
def infinity_before_cancel_method():
...
while True:
do_something()
I have absolutely no idea how to do this in PyQt5. I've seen that this can be done using a multiprocessing library or similar, but I don't quite understand how to apply it to a PyQt5 application. Any hints would be helpful!

How to make PyQt5 program starts like pycharm

As the title says i want to know how to make PyQt5 program starts like pycharm/spyder/photoshop/etc so when i open the program an image shows with progress bar(or without) like spyder,etc
Sounds like you want a splash screen. QSplashScreen will probably be your friend.

pyqt embed in photoshop

This is complex to explain, I hope this will not end up being a vague question getting vague answers.
If this is not the right place to ask this, you may help me to find the proper one.
I have a plugin for Photoshop based on the Listener, so it captures any input from the user.
The plugin creates a python module (called here "ps") containing basically the hInstance and the hwnd of the photoshop window.
Then this plugin, using plain python commands in the plugin for the module like those
PyRun_SimpleString("import Photoshop");
PyRun_SimpleString("Photoshop.showTools()");
will load a special module (here called "Photoshop") that will initialize pyqt and using the QtWinMigrate and the ps module to get the hInstance like this: QMfcApp.pluginInstance(ps.GetPluginInstance()), will start pyqt in photoshop. Here an example code of the Photoshop module using the ps module:
from PyQt4.QtWinMigrate import QMfcApp
from PyQt4.QtGui import QPushButton
import ps #this is implemented in the photoshop plugin (based on the Listener plugin)
#create the plugin instance here
app=QMfcApp.pluginInstance(ps.GetPluginInstance())
def showTools():
box = QPushButton()
box.show()
app.exec_()
Again then, the sequence is like this:
When the plugin starts in photoshop "ps" module is created, then it will load the "Photoshop" module that will load and bind properly pyqt. In the "Photoshop" module I can load any python module, widgets are properly working and everything works really well inside Photoshop.
But now the problem is: using Wacom tablets in Photoshop loose stroke sensitivity, the driver works and everything else works but the pressure sensitivity.
Apparently QMfcApp.pluginInstance will install an event filter to drive the Qt event loop while photoshop still owns the event loop. ( http://doc.qt.digia.com/solutions/4/qtwinmigrate/qmfcapp.html )
and on the paper looks fine to me.. but I could not manage to solve this by myself and I tried, more or less carefully, different approaches:
the listener plugin is not the problem. If Listener plugin runs but python is not initialized sensitivity works fine.
python itself is not a problem. If the listener starts python without gui nor pyqt, then works fine.
as soon as I call pluginInstance which should create the QApplication the issue starts and pressure is lost from the tablet. Even with the small code I wrote before.
Someone may have put pyqt as a plugin somewhere else, since the only purpose of QMfcApp is apparently this one. There is something I can configure to make it work? Is a known issue?
I would rather keep the approach (instead of connecting to photoshop externally like with COM)
I am not able to post the entire code here but let me know if you need something.. I probably can show more.
Thanks a lot for your help

Adding new window to MDI on click in PySide

I'm wrinting a program in Python using PySide as GUI creator but I'm stuck now i want to get a new window in the MDI when user clicks something like 'new' button but I'm not able to figure it out how that can happen so need some help...
Thanks in Advance
Since your question is very light on details, I will just give you some links to a simple example application that probably does a lot of what you want.
It is based on this Qt MDI example:
The PySide code itself can be dowloaded from the PySide Examples Repository.
For more examples like this, see the PySide Examples and Demos.

Using Tkinter to open a webpage

So my App needs to be able to open a single webpage(and it must be from the internet and not saved) in it, and specifically I'd like to use the Tkinter GUI toolkit since it's the one i'm most comfortable with. On top of that though, I'd like to be able to generate events in the window(say a mouse click) but without actually using the mouse. What's a good method to go about this?
EDIT: I suppose to clarify this a bit, I need a way to load a webpage, or maybe even a specific java applet into a tkinter widget or window. Or if not that perhaps another method to do this where I can generate mouse and keyboard events without using either the mouse of the keyboard.
If you want it to be opened inside your GUI use Bryans suggestion, if you just want to open a webpage you can use:
import webbrowser
webbrowser.open("page.html")
Tkinter does not have a widget that can render a web page.
So i found this module named pywebview
pip install pywebview
sample code:-
import webview
webview.create_window('duckduckgo', 'https://www.duckduckgo.com')
webview.start() #this will open the webpage in a new window
You should use pywebview it is very easy only code three lines .
I used it but in my case it didn't work everywhere. Comment and let me know if it works for you.
The best option that works everywhere is PyQt's QtWebview module. You might run into one problem that is to rename the window, so here is the solution
web.setWindowTitle(title)
You can use all the functions as it is but just replace window or self with web like the above code.

Categories