PyQt: Running pyuic.py without command line - python-2.7

I am unable to use the command prompt due to security restrictions on my work PC and I am trying unsuccessfully to find a way to convert .ui files to .py without the pyuic4 batch file.
I have found the uic/pyuic.py program but have been unsuccessful in my attempts to run it from a python console.
Any help with this would be great.
Cheers.

Thanks ekhumoro,
Was able to implement the uic successfully, using compileUiDir, since I have multiple .ui files. Final code was:
from PyQt4 import uic
folderToConvert = r'filePathGoesHere'
uic.compileUiDir(folderToConvert,recurse=False)
This is a .py file that I run or call/execute prior to running the main program. Very handy!

Related

Single executable file created by py2exe not working

I've created a Python app using Pyqt4 to open up a dialog and do some image processing using opencv2. The app is working fine when executing the script as:
python script.py
To create a single executable file for the script, I'm using py2exe with bundle_files = 1 option. It is creating a single exe file but when clicking the file, a console appears stays for few seconds and a pop-up appears saying program has stopped responding.
I'm working on Windows with anaconda. Please help me with this.
Py2exe generates a logfile.txt in the same folder you first-time execute the generated .exe.
Check this logfile to debug.
Most of the time you need to exclude some dll`s and include at least sip-module;
In your setup.py file:
from distutils.core import setup
import shutil, py2exe
opts = {'py2exe': {'compressed': True, "dll_excludes": ["MSVCP90.dll"], "includes" : ["sip"]}}
setup(console=[{"script" : "main.py"}], options=opts)
shutil.rmtree('build', ignore_errors=True) #Remove the build folder
Personally I did not encounter the need to include PyQt4 modules for compilation..
And btw be glad that python is an interpreted language, otherwise you`ll have to worry about linking to libraries on every build (like in cpp.., which is annoying)
Greets Dr Cobra

How can I pass commands to the elevated application in a batch file?

I was wondering if anyone can help me. I'm currently working on a game engine project which involves its own c++ compiler. For this I'm "borrowing" the visual studio 2013 c++ compiler. everything works fine. The problem I am having is a cant figure out how I would pass commands to the elevated program in a batch file.
Let me Explain, right now I am using a program which calls the "vcvarsall.bat" file and passes in "x86" as a parameter. This is great for manual entry as it then allows me to input the commands to compile files. E.G "cl /EHsc <cpp files>"
As of now, when I add commands after I call "vcvarsall.bat", they just give me a command reference error saying the command is not recognized.
What I want to achieve is being able to call one bat file which executes and compiles all of my code for me. instead of having to manually type in the commands every time. This way the entire process is easier for the user.
Any help would be appreciated,
Thank you in advance!
when I add commands after I call "vcvarsall.bat"
Maybe it has been too long since I last did a batch file .. hope the following gets you started:
I think any .bat file will accept parameters, and internally, the .bat writer (i.e. you) uses special identifiers. Often they are named something like %1 and %2, etc. (some scripting languages use $1, and probably a few other approaches)
Without consuming these parameters in your .bat file, the command line interpreter tries to use the parameter as another command (so you get 'command not recognized')
Search all .bat files on your system for %1 (or $1 or whatever) ... maybe you'll find enough hints.
Thank you all for the help, the way I solved the problem was by finding the last batch file which was called and making the end of the file call another batch file in the main compile directory, this means I can programatically generate this batch file making it incredibly easy to generate custom compilations. thank you all,
Alister

Run a jar Rhapsody app file

I have created some Java applications to extend Rhapsody using Java API and I have deployed them successfully to the Rhapsody environment (Right click on the project -> Apps).
I can see the exported .jar files under the directory RhapsodyApps/apps.
My question is, How can I run them from the command line (Under windows 7)???
Thank you in advance
What I managed to do is to create a .bat file, using "Generate Apps Execution Batch File". As I mentioned in my last post it did not exist in the "Apps" menu of rhapsody. Besides, it existed in the "...\share\RhapsodyApps\apps" directory with the name "SynchronousScriptInvocation.jar". I hardcoded the RhapsodyApps.hep file, by adding the following:
#REM: This app generates a script which will invoke each app synchronously one after another. ...
name7=Apps\Generate Apps Execution Batch File
isPluginCommand7=1
command7=Apps
applicableTo7=Project,SysML,AUTOSAR_40,AUTOSAR_31,AUTOSAR_32,DDS,UPDM1_DoDAF20,UPDM2_DoDAF
isVisible7=1
I got the name (Generate Apps Execution Batch File) from the AppInfos.xml file.
Then, the plugin is displayed in the Apps menu in Rhapsody IDE, and I can generate the .bat file. Problems did not stop here. The batch file was not displaying my plugin and the reason was something with my JAVA_PATH configuration. Finally I modified the .bat file as following:
#rem This is auto generated script. Be careful on changing it manually.
#rem Build Order
set APP0=0df8829923eb43f4aab9d33ada1ddbf1
#set APPS= %APP0%
set JAVA_PATH=%JAVA_PATH%\bin\java
set JAVA_API=C:/work/User/Build.TRUNK/ProjectName/RhapsodyShare8/JavaAPI
set RhapsodyApps=C:/work/User/Build.TRUNK/ProjectName/RhapsodyShare8/RhapsodyApps
set CLASS_PATH="%RhapsodyApps%"/apps/RhapsodyAppLauncher.jar;"%RhapsodyApps%"/RhapsodyApps.jar;"%RhapsodyApps%"/apps.jar;"%JAVA_API%"/rhapsody.jar
"C:\Program Files (x86)\IBM\Rational\Rhapsody\8.0.5\jre\bin\java" -cp %CLASS_PATH% -Djava.library.path="%JAVA_API%" apps.RhapsodyLauncherApp %APPS%
Finally it works. I hope that this post will help somebody in the future.

Can I create a single exe with custom modules files and other files?

Now I'm developing a medium proj with python.
It has many modules and some of them are customize modules. And some of them are non-python files(may be config files), are need to use such as copy/paste (e.g when the client run this app and plug some the hw device, the app will config the hw device and copy the some file of app to hw device (may be ROM))
first my question is : can I create 1 single exe with all of my code, modules and non-python files?
if it is yes, how can I?
you could try changing your approach and putting all the files in the module as text.
then you could use the py2exe to create executable and it would contain all the data you need. this approach makes sense only if you have some small files.
if you want to embed more and bigger files take a look at that solution:
Py2exe: Embed static files in exe file itself and access them
open CMD
Change path to PyInstaller directory.(ex-C:\PyInstaller-2.1)
use this command
pyinstaller.py my.py --noconsole --onefile --icon=icon.ico
change my.py to your script name.
--noconsole option remove the python console while executing your program. If you need console to get an output,just remove --noconsole
--onefile option makes all the modules and files in to one executable file.
--icon=icon.ico gives your exe an icon.Remember to put your icon file in Pyinstaller directory

Qt Designer code generation issue

I am using Qt Designer. When I lauch the code generation (View code), I have the following issue:
Code Generation Failed
Unable to launch C:/Python27/Lib/site-packages/PyQt4\uic.
I tried to use the tips here
You can generate code by using the pyuic4.bat file
located under the PyQt4 install directory, on Win usually
C:/Python##/Lib/site-packages/PyQt4.
Usage from the command line is:
pyuic4.bat inputfile.ui > output.py
pyuic4.bat inputfile.ui > output.py gives me an output.py file, but launching this output.py script gives nothing. The execution is pending for a while, then stop. I don't know if code has been generated / where it should have been generated ... What I would like is the code in C++/Qt. What should I do once I have output.py ?
Could somebody explain more precisely how to proceed ? Is this tip making possible to see the rendering of the UI, or the generated code (which I want) ? Where can I find the code ? What is another working trick ?
You can do this way to generate C++ file
cmd
uic -o sample.h sample.ui
with sample.ui the .ui file first saved with Qt Designer. Code is generated in sample.h