I've developed a few Qt projects in C++ using Qt Creator in the past, but now I want to experiment with the Python implementation of Qt. I discovered that Qt Creator 2.8 and higher support Python, but I haven't been able to figure out how to create a Qt application in Python with it so far. Online documentation about it appears to be scarce.
How do I set up such a project in Qt Creator? Ideally I'm looking for a simple "Hello World" project that I can open in Qt Creator and use that as a starting point to build something.
Currently, Qt Creator allows you to create Python files (not projects) and run them. It also has syntax highlighting, but it lacks more complex features such as autocomplete.
Running scripts requires some configuration (I used this tutorial). Open Qt Creator and go to Tools->Options->Environment->External Tools. Click Add->Add category and create a new category (for example, Python). Then, select the created category and click Add->Add Tool to create a new tool - RunPy for example. Select the created tool and fill the fields on the right:
Description - any value
Executable - path to python.exe
Arguments - %{CurrentDocument:FilePath}
Working directory - %{CurrentDocument:Path}
Environment - QT_LOGGING_TO_CONSOLE=1
You get something like this:
Now, go to File->New File or Project->Python and select Python source file. To run the created script: Tools->External->Python->RunPy.
You can also add pyuic to it the same way:
Click again on the Add->Add Tool button to create a new tool - PyUic now. Select it again and fill the fields on the right:
Description - any value
Executable - path to pyuic5
Arguments - -o UI%{CurrentDocument:FileBaseName}.py -x %{CurrentDocument:FilePath}
Working directory - %{CurrentDocument:Path}
Environment - QT_LOGGING_TO_CONSOLE=1
Then you should have PyUic connected as well.
Thanks for this, it helped enormously.
I set up a build and run section of a new kit for python, using your instructions, which seems to work quite well.
Here are the build settings:
Here are the run settings:
note that I have /usr/bin/python as a link to /usr/bin/python3.6
Here are the project file settings:
The only thing that is necessary is to go into tools -> options -> build and run and unselect 'always build project before deploying it' and 'always deploy project before running it'.
Once you have designed a form, you can then click build to create the UI.py file and run the currently selected python source file by clicking run.
For PyQt noobs like myself, I found the following resource to be particularly helpful at getting started... (although I am on linux rather than windows)...
http://projects.skylogic.ca/blog/how-to-install-pyqt5-and-build-your-first-gui-in-python-3-4/
edit.
I also added pdb - the python debugger
which you can then select by clicking the button above the run button:
before clicking run. You can set breakpoints in your code using the following snippet, where I have added DEBUG = 1 to the system environment in the run settings of the pdb run and DEBUG = 0 to the run python env:
if (QtCore.QProcessEnvironment.systemEnvironment().value("DEBUG") == "1"):
import pdb; QtCore.pyqtRemoveInputHook(); pdb.set_trace()
Related
I'm attempting to turn a short Python program that I wrote into an easily-distributable application file for OS X, using py2app. I made it through the py2app tutorial, but when I click on my application file the following dialogue is shown:
A Python runtime not could be located. You may need to install a
framework build of Python, or edit the PyRuntimeLocations array in
this application's Info.plist file.
I'm not sure whether this is helpful, but clicking "Open Console" from that dialogue shows the following errors:
LaunchServices: Could not store lsd-identifiers file at /private/var/db/lsd/com.apple.lsdschemes.plist
launchservicesd[83]: SecTaskLoadEntitlements failed error=22
appleeventsd[53]: SecTaskLoadEntitlements failed error=22 11/27/16 7:29:19.787 PM
sharedfilelistd[307]: SecTaskLoadEntitlements failed error=22
I know that if py2app uses a "system" version of Python to produce an app, it won't include that Python in the distribution. However, entering $ which python in the terminal directs me to my anaconda installation, so that doesn't seem to be the issue.
This is my first time attempting to create a piece of software, so apologies in advance for any obvious missteps. Any help would be greatly appreciated, as I've been banging my head on this all day.
Is there a way to get the selected project of the MKS projects view gui started as a subprocess from the command line?
si.exe projects ... -g
When starting a custom tool from the MKS main gui accessing the selected project is possible by defining an environment file for that tool and parsing it for the variable name like SI_PROJECT1=... .
But it is only the selected file at tool start or more precisely it is only the environment from tool start. Changes in the gui don't have an effect on the environment file.
The gui itself unfortunately has no return value giving the selected project.
I'm trying to use the MKS si projects gui called as a subprocess from python or C# to select a specific project and use the selection for further processing.
Is there any way to do that (on Win7)?
Thanks in advance!
To use the GUI for selecting a specific project you can use the following command projectinfo from cli
si.exe projectinfo --settingsUI=gui
then parse the output of command and use the Project Name or Configuration Path, depending of your server configuration
Also, you can use the command in combination with --xmlapi and the output will be as xml ( I know that this option is not recommended in release application, is only for developing phase)
Sample output
Project Name: t:/projects/demo/project.pj
Repository Location: t:/projects/demo/project.pj
Server: mks-host:7001
Configuration Path: #t:/projects/demo
Last Checkpoint: 1.1
Last Checkpointed: Apr 21, 2011 4:10:50 PM
Members: 2
Subprojects: 6
Description:
Attributes: none
Development Paths: none
Associated Issues: none
Depending of your server version and configuration
The Windows 7 Control Panel "Notification Area Icons" allows you to customize which system tray icons are visible. For each of the icons, it shows two things:
an application name
a subtitle
It looks like the subtitle comes from the tooltip text, because I can set that.
But what about the application name? I'm writing a GUI in PySide and can't figure out what incantations I need to do, to set this to something other than "python.exe".
python.exe will always show up if the module is run under the python executable, regardless of via a shortcut or not. It also shows up in task manager under the process name python.exe.
To circumvent this, it is necessary to create a custom executable to run the python script under it's own name. This doesn't have to be a monolithic exe packer such as py2exe, but can be something a little more discrete.
Using effbot.org's open source ExeMaker for instance, the following steps will result in what you want.
After downloading exemaker, simply run it from the command line with
exemaker scriptname.py
and it'll create scriptname.exe.
You may then run scriptname.exe by double clicking it, and it shall run the python script under it's own name.
The advantage of this small tool is that any changes made to the python script do not require recompilation of the exe - they are effective immediately.
This is because you are launching your application using Python.exe. In your case the main application running is Python.exe, so the Notification Area Icons will always show you Python.exe as running application.
When you are done with the development of your application, use pyinstaller or py2exe to package your application. After this process you will have a exe file for your application, when you will run your application, the name in the Notification Area Icons for your application will be same as you will set for your main window title.
I did not really test it but it may work. Create a link to your .py file and choose the name. If you run that link it should show the name of the link.
PS: On command prompt title bar it works fine
I'd like to write cross platform Python scripts that are GUI frontends for command line programs. The problem is I know a few Mac users who think that using the terminal will have the same effect as throwing their computer off the top of a skyscraper. In Linux and Windows it's easy enough to setup a Python script so the user can double click an icon and the script will start without opening any extra windows. Is there an easy way to do this with OS-X? Would the user have to install a different Python than the one that comes with OS-X? I haven't been able to find a definitive answer.
You might want to look at Platypus. It's a freeware app for generating apps which wrap scripts.
Another way to do something like that is using Automator or even AppleScript Editor. Either can produce an application which just runs a script.
Update:
For Automator: Launch Automator, select the Application template, type "script" in the search field, double-click Run Shell Script, switch the shell pop-up menu to /usr/bin/python, type/paste your Python script into the text field. Or, leave the pop-menu on /bin/bash and just write an invocation of an external script in the text field. Save as an application.
You can also view help from its Help menu.
For AppleScript, launch AppleScript Editor, type the following as the script:
do shell script "/usr/bin/true"
Replace /usr/bin/true with the path to whatever script you like. Save as an application.
Again, there's help in the Help menu.
py2app does this with aplomb. You make your Python script, use whatever dependencies you need (wx, Tkinter, etc.) and py2app makes you a standalone app bundle that will run in any modern OS X environment. It bundles Python too, so you can use any Python you want (not just the system default).
The downside is that the generated apps might be large, up to 50MB if you have a lot of dependencies (though that is somewhat of an extreme).
There are two ways to do this:
Click on a script.
Press command-i to open the "get info" window.
Expand the "Open With" section (if it isn't already).
Choose "Python Launcher" from the drop-down menu.
Click "Change All" if you would like ALL Python scripts to launch when double clicked.
Possibly open Python Launcher and uncheck "Run in a Terminal window"
This will work for this machine only, so it is less portable than the following. Why? Because the default for opening a document type varies depending on what is installed (XCode and/or IDLE will both take over opening a .py file).
Method Two:
Validate the Interpreter Directive, that's the first line of the file. I suggest using /usr/bin/env python3. This will run the first python3 interpreter that is on the users path.
Make the script executable chmod a+x <script_name> from the Terminal.
Change the extension from .py to .command (this will be opened by the Terminal).
Use zip or tar for distribution so that the permissions do not get mangled.
This method will open a Terminal window, but when the Python window is closed the terminal window will also close.
If your script has dependencies outside of the standard library, then you should provide a second .command file to install those. This may make things more complicated, but using pip3 install --user <list of dependencies> should minimize complications.
Is it possible?
By debug I mean setting breakpoints, inspect values and advance step by step.
You can do remote debugging of python web apps over TCP/IP with winpdb.
(Link appears down as of June 2019. Try PyPI winpdb)
I haven't used web2py, but if it runs in a terminal window, you can use standard pdb stuff. Add this line somewhere in your code:
import pdb; pdb.set_trace()
This will invoke the debugger and break. Then you can use PDB commands: n to step to the next line, l to list code, s to step into a function, p to print values, etc.
One can debug applications built on Web2py using the following set-up:
Eclipse IDE
Install Pydev into Eclipse
Set Breakpoints on your code as needed
Within Eclipse right-click the file web2py.py and select Debug As -> Python Run
When a breakpoint is hit Eclipse will jump to the breakpoint where you can inspect variables and step thru the code
You can also use Visual Studio 2010. Here's how:
Download and install Python Tools for Visual Studio.
Create a new project from existing code (File > New > Project From Existing Code...)
Specify your web2py folder and use the defaults.
Right-click on web2py.py and choose Set as Startup File.
Set breakpoints and hit F5 (run) or right-click on web2py.py and choose Start with Debugging.
This is a nice setup if you already use visual studio.
Yes, it is possible, Due to the "span prevention" I am still not allowed to post screenshots, but here is a full screenshot hosted at my website:
http://static.techfuel.net/debug_web2py.png
I'm debugging web2py applications with Eclipse and PyDev. Here is an article:
http://www.web2pyslices.com/main/slices/take_slice/2
Here is an article on debugging python with pdb, which will work with web2py. http://sontek.net/debugging-python-with-pdb
As Carl stated, it is as easy as:
Installing PyDev in Eclipse
Right Click on your Web2Py project, selecting Debug As > Python Run
Selecting web2py.py as the file to run
No other plugins or downloads are needed.
#Ned Batchelder is almost right, but the standard way of doing it in web2py is slightly different.
Instead of `import pdb; pdb.set_trace(), you use the code:
from gluon.debug import dbg
dbg.set_trace()
When executing the web application, the application will freeze when it reaches this section of code. You then go to http://127.0.0.1:8000/admin/debug/interact (using the root URL for your application) and it will show a fully interactive, web based debugger:
See documentation.