PySide2:Resource Compiler(avoid using file paths to use images in widgets)

Hello Guys,

When we start new, we explore a lot and land up with a technique that works for us.

But that does not mean it is one of the most efficient technique, this post is about one of those, that i got to learn from Qt forum guys.

Resource Compiler/Qt Resource System to store images

Verbose stuff

https://doc.qt.io/qtforpython/overviews/resources.html

For technical details you can read the above docs, it covers a lot of things except the approach to execute the whole process.

Why do we need this process?

This process bakes your images to a binarydata.py and you can use the binarydata.py in the ui base class (a file that one converts from ui to py using uic)instead of using a folder path to load the image. This is a very neat approach.

Requirements

  • Autodesk Maya(not necessary)
  • PySide2/PyQt5
  • Qtdesigner/designer
  • Windows

So the cool part

  • Create a new_folder in any drives
  • copy your images in the new_folder
  • open designer/qtdesigner
  • create widget
  • Create label/drag and drop label in the widget
  • in the property_editor filter pixmap
  • Select the pencil in the Resource Browser
  • right click in the right hand side
  • create a new .qrc file in the new_folder
  • in the left hand side create a new prefix
  • below in the lhs panel there are three button select the add files(middle button)
  • select the image you pasted earlier in the new_folder
  •  double click the pixmap and got to corner “…”(three dots)
  • select the resources and the image and the image will be displayed
  • avoid giving test names to any files, as the editors recognize it as a test module and creates name conflicts
  • great part 1 is done

now its time to convert the .qrc to .py

Please read carefully from here on wards, everything gets messy

  • open a terminal/command prompt/powershell
  • drag “C:\Program Files\Autodesk\<maya_version>\bin\rcc.exe” <file_path>/file.qrc -o <file_path>/file.py — there is a chance it might convert to c++ version, check the .py file that the above command line creates
  • if maya rcc.exe behaves unusual by giving you c++ output, You’ll need PySide2
  • maya is not the only one who behaves unusual python too — PySide2 Requires: Python >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.10 (it means more than 3.5 smaller or equal to 2.7)
  • so that is a trouble, please then install python 3.8(even though it tells 2.7 please avoid, its troublesome)
  • python -m pip install PySide2 (later you can uninstall it)
  • below are the alternatives in case you face any errors, always check the “–help” of the command line
  • C:\Python38\Lib\site-packages\PySide2\rcc.exe -g python2 <file_path>/file.qrc -o <file_path>/file.py
  • C:\Python38\Scripts\pyrcc5.exe
  • C:\Python27\Lib\site-packages\PyQt4\pyrcc4.exe
# Resource object code (Python 2)
# Created by: object code
# Created by: The Resource Compiler for Qt version 5.15.0
# WARNING! All changes made in this file will be lost!

from PySide2 import QtCore

qt_resource_data = "\
\x00\x00\xcf\x14\
\xff\
\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x00\x00\
\x00\x00\x00\xff\xe1\x00\x16Exif\x00\x00II*\
\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xdb\x00C\x00\
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x02\
\x01\x01\x01\x01\x01\x02\x01\x01\x01\x02\x02\x02\x02\x02\x02\x02\
\x02\x02\x03\x03\x04\x03\x03\x03\x03\x03\x02\x02\x03\x04\x03\x03\
\x04\x04\x04\x04\x04\x02\x03\x05\x05\x04\x04\x05\x04\x04\x04\x04\
\xff\xdb\x00C\x01\x01\x01\x01\x01\x01\x01\x02\x01\x01\x02\x04\
\x03\x02\x03\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\
\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\
\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\x04\
\x04\x04\x04\x04\x04\xff\xc0\x00\x11\x08\x02\x1c\x03\xc0\x03\x01\
\x22\x00\x02\x11\x01\x03\x11\x01\xff\xc4\x00\x1f\x00\x00\x01\x05\
\x01\x01\x01\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\
\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\xff\xc4\x00\xb5\x10\x00\x02\
\x01\x03\x03\x02\x04\x03\x05\x05\x04\x04\x00\x00\x01}\x01\x02\
\x03\x00\x04\x11\x05\x12!1A\x06\x13Qa\x07\x22q\
\x142\x81\x91\xa1\x08#B\xb1\xc1\x15R\xd1\xf0$3\
br\x82\x09\x0a\x16\x17\x18\x19\x1a%&'()*\

What works for me

I convert it through

C:\Python27\Lib\site-packages\PyQt4\pyrcc4.exe -py2 <file_path>\head_banner.qrc -o <file_path>\head_banner.py

and open the .py file and edit the PyQt4 to PySide2, as you can see below.

# -*- coding: utf-8 -*-

# Resource object code
#
# Created: Fri 17. Sep 22:43:20 2021
#      by: The Resource Compiler for PyQt (Qt v4.8.4)
#
# WARNING! All changes made in this file will be lost!

from PySide2 import QtCore

The output

below code is a an example of maya. I am not using an image path as you can see it is a resource. When you use a class you can keep your rcc file in the package folder and just import that and provide your qrc file prefix and you are good to go.

from PySide2 import QtWidgets
from PySide2 import QtGui
import sys
#sys.path.append('D:\\All_Projs\\Qt_Designer_Proj\\untitled')
import head_banner#rcc
#reload(head_banner)

def label():
    win_wid = QtWidgets.QWidget()
    label = QtWidgets.QLabel()
    image_pixmap = QtGui.QPixmap(":/head/progress_01.jpg")
    label.setPixmap(image_pixmap)
    layout = QtWidgets.QVBoxLayout()
    layout.addWidget(label)
    win_wid.setLayout(layout)
    win_wid.resize(200, 50)
    
    return win_wid
    
trial = label()
trial.show()

Try it out guys.

Take care bye!!

Books Part2: Unreal for real

Hello Guys,

How are you all, Hope you guys are doing good.

Before i start the review some verbose stuff, i would not recommend you to skip

For people those who don’t believe in purchasing books, below is a community page, i only use this when i am out of money.

https://www.pdfdrive.com/

The below content is for people those who like to improve themselves!!

Table of contents

Production Pipeline Fundamentals for Film and Games
Unreal Engine 4 Game Development in 24 Hours, Sams Teach Yourself
Learning C++ by Creating Games with UE4
Introduction to C++ and Graphics

There is no substitute for hard work (Thomas Edison)

Production Pipeline Fundamentals for Film and Games :-

This Book is for people those who have interest in understanding industry workflow, anyone can start the book be it a beginner or a veteran, It makes point that you don’t feel lost or incapable of reading further. Even though the book is slightly old, it still makes relevant points, I mean it. The book is really thick and a comprehensive manual . It emphasizes on every department of the industry and person’s role managing the department, and yes there are even images in the books(lol). The book includes names of the industry veterans that explain each chapter or a paragraph, which makes it very useful, in case you want to search on internet. The book does a wonderful job of giving keywords and introducing topics which will help the upcoming TD’s and TA’s(check the book for difference) become eligible for the job. There are separate chapters for the VFX/Feature and Game dept to understand workflow in both the fields with diagrammatic representations. For someone who aspires to be a creator, go through this book, I can guarantee you it will be worth your while. My recommendation start a project and simultaneously read the book. You’ll be a force to be reckoned with. All the best.

Unreal Engine 4 Game Development in 24 Hours, Sams Teach Yourself :-

Okay Hands down the best book to learn unreal in 24hrs!!! Yes this is my review. Okay I’ll elaborate, I spoke about this book in my previous post https://digdeeperts.wordpress.com/2020/04/09/unrealengine4-finally-started/ , i was starting out with unreal and posted immediately how? Learning from this book!!

This book has capability to turn you into an unreal wizard, I swear. But as the book is slightly old there is one chapter which is obsolete, please check the link.https://docs.unrealengine.com/en-US/Engine/Sequencer/HowTo/MatineeConversionTool/index.html . None the less the book has Table of contents which gives instructions to even open a browser and download the engine, even an extreme newbie can start with this book literally, check it out. The book has tonnes of images for reference so that you don’t get lost in the unreal ui(honestly the ui is overwhelming). But just to be clear this is for starting with unreal and less about C++ and Blueprints. For example: If you have created a model and want to use unreal you can on a superficial level, like calling your animations, creating physics/fx, very basic shaders and rendering. Again this is a very comprehensive introductory book, don’t expect virtual production. Alot of departments are covered in the book, which makes it very useful. My recommendation read this book along with a specific topic that you like to explore indepth eg: shaders with https://www.youtube.com/watch?v=uQG0SWv5lbw (courtesy Ben Cloward) and C++ with Learning C++ by Creating Games with UE4, You’ll learn ui and as well the indepth concept win win. I dare you to finish it in 24hrs. All the best.

Learning C++ by Creating Games with UE4 :-

When you speak about games, Unreal, shaders etc., We have to speak about C++. So here it is. This book is one of my favourite book for C++ because unlike C++ books which are raw, overwhelming and thick has hell. This book is blessing in disguise, because over here author speaks mostly in reference to Unreal which makes the experience very exciting and fun. The book does become heavy after chapter 6, and author knows about that, he never forgets to encourage the reader(bonus). I would recommend to read Sams 24hrs book with this book after chapter 7, because the author dives deep into unreal engine, and uses the prior C++ preparations to create work. The book is superb for C++ beginners as well. This book is not a comprehensive guide for computer graphics or shader creation just a heads up, this is more about how C++ interacts with unreal. Give it a try. for chap 7 i would even recommend you to watch some videos on game mode as the book is a tad bit old in terms of unreal version(option names changes) https://www.youtube.com/watch?v=rtx4gv6OpLo , https://www.youtube.com/watch?v=a5gA7q5GD7Q

chap8-npc – https://answers.unrealengine.com/questions/500218/view.html?sort=oldest

chap8-drawtext – https://forums.unrealengine.com/t/cant-get-drawtext-to-render-to-the-screen/11044/3

Introduction to C++ and Graphics :-

This book is not a very forgiving book. If you have not started the above books and are not familiar with math, please be patient, pick up terms, read the previous academic books or search on internet about the topics or else you’ll lose motivation to study. And on top of that there are a lot of errors in the book, that is unfortunate. But if you have done the above books you’ll be able to figure out and move on. The book gives a brief history on C++ and computer graphics which is cool but really advance. In the further chapters the book even shows you how to create a geometry using math(but need to be really patient), Matlab, and some small graphic modules. This is an introduction to math in graphics. Give it a try. (update: Few of the topics are outdated eg: 7th and 8th)

Thank you Guys, Be safe.

C++ error types

Hello all, Will keep updating this page whenever i come across some error, i am not going to distinguish between big or small.(I have just started so better to gather info!!)

Wrong

#include<iostreams>

fatal error C1083: Cannot open include file: 'iostreams': No such file or directory

Correct

#include<iostream>

____________________________________________

Wrong

using namespace std; // If not declared

cout << “hello world” << endl;

error C2065: 'cout': undeclared identifier

Correct

std::cout << “Hello world” << std::endl;

____________________________________________

Wrong

int mains() or int trial()

1>MSVCRTD.lib(exe_main.obj) : error LNK2019: unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
: fatal error LNK1120: 1 unresolved externals
 -- FAILED.

Correct

int main()

____________________________________________

Wrong

#include<iostream>
#include<string>


struct Player {
	std::string name;
	int hp;
};

Player me; //create an instance of player
me.name = "Tom";
me.hp = 100;

int main() {
	std::cout << me.name << me.hp << std::endl;
}
1>------ Build started: Project: MySecondProj_book, Configuration: Debug Win32 ------
1>Source.cpp
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(11): error C3927: '->': trailing return type is not allowed after a non-function declarator
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(11): error C3484: syntax error: expected '->' before the return type
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(11): error C3613: missing return type after '->' ('int' assumed)
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(11): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(11): error C2371: 'me': redefinition; different basic types
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(9): note: see declaration of 'me'
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(11): error C2146: syntax error: missing ';' before identifier 'name'
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(12): error C3927: '->': trailing return type is not allowed after a non-function declarator
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(12): error C3484: syntax error: expected '->' before the return type
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(12): error C3613: missing return type after '->' ('int' assumed)
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(12): error C2371: 'me': redefinition; different basic types
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(9): note: see declaration of 'me'
1>d:\all_projs\c++_proj\mysecondproj_book\mysecondproj_book\source.cpp(12): error C2146: syntax error: missing ';' before identifier 'hp'
1>Done building project "MySecondProj_book.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Correct

#include<iostream>// import input output stream
#include<string>

struct Player {
	std::string name;
	int hp;
};

Player me; //create an instance of player

int main() {	
	me.name = "Tom";
	me.hp = 100;
	std::cout << me.name << me.hp << std::endl;
}
____________________________________________ 

OpenGL errors

Wrong

https://www.glfw.org/documentation.html (code used from the link)

1>------ Build started: Project: Project2, Configuration: Debug x64 ------
1>Source.cpp
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>Source.obj : error LNK2019: unresolved external symbol __imp_glClear referenced in function main
1>D:\All_Projs\c++_Proj\Project2\x64\Debug\Project2.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "Project2.vcxproj" -- FAILED.

Correct

Add the “opengl32.lib” in the properties and rebuild it should fix the issue.

https://stackoverflow.com/questions/20223198/visual-studio-11-glfw-external-symbol-error

____________________________________________

Wrong

Error: The code execution cannot proceed because glew32.dll was not found.

Fix: https://stackoverflow.com/questions/22306260/how-can-i-solve-glew32-dll-is-missing-from-your-computer-issue-of-my-opengl-pr search for “Haha TTpro”

Copying the glew32.dll file in the /project/x64/glew32.dll fixes the issue, worked for me.