Long story short. I have one python module generated from ui file, let's say dialog.py this form contains QDialogButtonBox widget
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
The question is how can I access individual button inside this buttonBox?
I have tried using ui.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) but it did not work, the program crashed instead.
http://pyqt.sourceforge.net/Docs/PyQt4/qdialogbuttonbox.html#button
The only thing I was able to come up is this:
ui.buttonBox.buttons()[0].setEnabled(False)
note plural buttons and it works but I am not sure if this is portable and right way.
Here is original Qt link since this is pyqt5
http://doc.qt.io/qt-5.6/qdialogbuttonbox.html#button
Regards.
The only thing I can say is that I am an idiot ;-)
I forgot to import QDialogButtonBox in this module and instead run python script directly using interpreter I ran it through 'sublime text' (text editor) build menu which gave me this message:
[Finished in 3.1s with exit code -6]
So the answer is that there was no QDialogButtonBox symbol imported which I'd have known if I run it with python interpreter.
Related
I am working on QT Designer to build GUI App. I want to ask how add command for push button.
For example I want to apply this action :
self.NfmtLoginButton.clicked.connect(lambda: SecondScript.printme(self.NfmtPasswordEntry.text()))
Is it possible through the QT Designer. to be permanently saved. and no need to add all the commands again when generating new python script file from UI file.
No, it's not possible, but that should not be a problem, as the files generated using pyuic should never, ever be modified (the warning in those files is not to be undertaken).
Those files should always be left unmodified and only updated again with pyuic, as they are only meant to be imported in the actual program file, as explained in the official guidelines about using Designer (the "multiple inheritance approach is generally the most suggested).
I want to add a systemtray to an existing python based project: https://github.com/piejanssens/premiumizer
How exactly do I need to do that? I am completely new to python and I am using it for the first time, just because I want to add a little feature to and existing script.
What I want to achieve is that when the script is running that there should be a system tray icon which opens http://localhost:5000 if it is double clicked. And if it is right clicked there should be an Exit/Quit option.
I have researched a bit and I think I could achieve it with one of these two scripts https://github.com/moses-palmer/pystray or with https://github.com/Infinidat/infi.systray (I also read that infi.systray should be used because it is not dependent on pywin32 because it uses the ctypes library because that one is part of the standard Python library).
So I tried to add this code for testing to the premiumizer.py file:
from infi.systray import SysTrayIcon
def say_hello(systray):
print "Hello, World!"
menu_options = (("Say Hello", None, say_hello),)
systray = SysTrayIcon("icon.ico", "Example tray icon", menu_options)
systray.start()
But now the Console is closing itself immediately. How can I check what went wrong? Is an error log saved somewhere ?
What do I need to do to make it work? Or is there an easier way for someone "stupid" like me ?
Welcome to the world of python!
Let me assume that you copied the script you've posted into a python file and just ran the file, correct? If so, the problem is that once the script is executed the program exits and with it the tray icon.
Start an interactive console by running python or (ipython if you have it installed) in a command window and paste in your code. You'll see that the tray icon appears and stays. It disappears once you close the console.
(Remark: the code above uses the python 2.x version of print without the () and will cause an error in python 3.x, there use print("Hello, World!").)
To make this work you need to put this code somewhere in the setup/initialization part of the premiumizer. Without knowing this project I cannot be of further help where to exactly.
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
Ive got a .ui file made in designer and as soon as i group some radio buttons together, pyside-uic fails to compile the file and return with an unexpected error.
Is there a way around this or am i missing something when adding these groups. Im picking the buttons i need, right clicking and creating a button group from there.
Here is the most basic version of the ui, and this even crashes for me.
http://pastebin.com/0NYHPBUD
after debugging pysideuic, i figured that in module uiparser.py in line 212 the generator fails, because it treats a string like an object.
By changing the source (https://github.com/PySide/Tools/pysideuic/uiparser.py) from:
bg_name = bg_i18n.string
to:
bg_name = bg_i18n
the generator will be working fine.
After further investigation it seems that the implementation of the QButtonGroup changed.
It used to be a Widget.
regards
Ben
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.