Megascan Link Python Package¶
This package is the connection between Quixel Bridge and Substance Painter
The role of this package is to receive the JSON data from Bridge and send it over websocket to the JS counterpart that will use that data to import the needed resources and to store and manage the configuration settings (Config Module).
The plugin has been divided into two plugins Megascan Link Python Package and Megascan Link Javascript Package because of the current state of the Substance Painter API, what is possible with the JS API in not possible with the Python API and the other way around. Since this plugin makes use of some features that are not present in both API I had to split the plugin in half.
Python Subpackages¶
Python Submodules¶
Plugin Module contents¶
-
class
megascan_link_python.
Data
¶ Bases:
object
Dataclass used to store references to items so they dont get garbage collected
-
socket
= None¶
-
toolbar
= None¶
-
-
megascan_link_python.
close_plugin
()¶ Exit point of the plugin.
Here we perform the clean up before closing the plugin, stopping the socket thread and removing the toolbar action
-
megascan_link_python.
createToolBar
()¶ Creates the toolbar containing the action to open the Settings Dialog
-
megascan_link_python.
openSettingsDialog
()¶ Opens the Setings dialog for the user to change the socket port number and other import settings
-
megascan_link_python.
showErrorDialog
()¶ Opens the error dialog showing to the user that something went wrong during the installation of the needed dependencies.
And guiding the user to the manual dependecies installation guide on the documentation website
-
megascan_link_python.
start_plugin
()¶ Entry point of the plugin.
Here we set up all the needed fucntionalities like the log the socket thread and we add to the painter toolbar the user interface ation
Config Module¶
Module containing classes for managing the config settings files or related
-
class
megascan_link_python.config.
ConfigSettings
¶ Bases:
object
Class that manages a config file
-
classmethod
checkConfigState
()¶ Check if the current config file is opened if not and the file exist reads and load the content of it to the config parser
-
classmethod
checkIfOptionIsSet
(cat: str, prop: str, fallback='') → bool¶ Helper function that will check if a propriety of a section is set or not by confronting it with the following values [“true”, “yes”, “y”, “ok”]
- Parameters
cat (str) – Category name string
prop (str) – Propriety of the category to check agains
- Returns
if the propriety is set returns True, False otherwise
- Return type
bool
-
config
= <configparser.ConfigParser object>¶ Config parser class instance
-
classmethod
flush
()¶ Helper function used to write the content to file
-
classmethod
getAsDict
() → dict¶ Helper function that return the current config as a Python dictionary
- Returns
a dictionary of the current ini file
- Return type
dict
-
classmethod
getConfigCategory
(cat: str) → dict¶ Helper function to retrive an entire category of the ini file
- Parameters
cat (str) – Category name string
- Returns
the dictionary containing the proprities with their corrispective values, if the category does not exist and empty dictionary is returned
- Return type
str
-
classmethod
getConfigSetting
(cat: str, prop: str, fallback='') → str¶ Helper function to retrive a config propriety value.
- Parameters
cat (str) – Category name string
prop (str) – Propriety of the category to retrive
- Returns
the propriety value
- Return type
str
-
classmethod
getConfigSettingAsList
(cat: str, prop: str, separator=',') → List[str]¶ Helper function to retrive a config option as a list
- Parameters
cat (str) – Category name string
prop (str) – Propriety of the category to retrive as list
separator (str, optional) – the saparator character used to split values in the config string value, defaults to “,”
- Returns
the config settings as a List
- Return type
List[str]
-
opened
= False¶ Current state of the config file
-
path
= None¶ Contains the path to the ini config file (root dir of module) needs to be initialized
-
classmethod
removeConfigSettings
(cat: str, prop: str, flush=True) → bool¶ Helper function used to clear an option entry of a Section
- Parameters
cat (str) – Category name string
prop (str) – Propriety of the category to remove
flush (bool, optional) – If true it will immediatly update the file on disk, defaults to True
- Returns
return True if successfully delete False otherwise
- Return type
bool
-
classmethod
setIniFilePath
(name: str)¶ Set the filepath of the ini file
- Parameters
name (str) – the name of the config ini file (without extension)
-
classmethod
setUpInitialConfig
(config: configparser.ConfigParser)¶ Function to use a config parser instance to initialize the config file This will initialize the config file only if it does not exist
- Parameters
config (configparser.ConfigParser) – The config instance to use for populating the initial value of the config
-
classmethod
updateConfigSetting
(cat: str, prop: str, value: str, flush=True)¶ Helper function used to update a config propriety.
- Parameters
cat (str) – Category name string
prop (str) – Propriety of the category to update
value (str) – Value to associate to the propriety
flush (bool, optional) – If true it will immediatly update the file on disk, defaults to True
-
classmethod
Dialogs Module¶
Module which contains all the dialogs used by the plugin
The dialogs are generated using QtDesigner and are located under /ui/uiDesign and then converted to python code using the buildDialogs.py script
-
class
megascan_link_python.dialogs.
DependencyErrorDialog
(parent, helpLink=None)¶ Bases:
PySide2.QtWidgets.QDialog
,megascan_link_python.ui.error_dialog.Ui_Dialog
Generic Error dialog for displaying error messages
-
close
()¶ Close the dialog and updates the ini file if necessary
-
openHelp
()¶ Summon a browser with the documentation page opened
-
show
()¶ Shows the error dialog only if the users has not checked before the “don’t show again” checkbox
-
staticMetaObject
= <PySide2.QtCore.QMetaObject object>¶
-
-
class
megascan_link_python.dialogs.
SettingsDialog
(socket: megascan_link_python.sockets.SocketThread, parent=None)¶ Bases:
PySide2.QtWidgets.QDialog
,megascan_link_python.ui.settings_dialog.Ui_Dialog
Dialog displayed to the user for editing the plugin settings
-
staticMetaObject
= <PySide2.QtCore.QMetaObject object>¶
-
Log Module¶
This Module contains the logger facilities class
-
class
megascan_link_python.log.
LoggerLink
¶ Bases:
object
Class used to log messages to the log file
see:
Log()
for know how to use it to print also to the Python editor output-
classmethod
Log
(msg: str, logLevel=20)¶ Helper function used to log a massage to a file or if specified in the config file with the outputConsole propriety also to the Python Editor output of Substance Designer
- Parameters
msg (str) – the message to print
logLevel (int, optional) – the log level to print with if it is lower than the current
_logger
level it would not be printed, defaults to logging.INFO
-
classmethod
setLoggerName
(name: str)¶ Set the current session logger name do this before using the logger and once, subseguent calls to this methos will have no effect
- Parameters
name (str) – the logger name
-
classmethod
setUpLogger
()¶ Method used to setup the current logger instance
Links the handler to print to the log file (log config path: ‘./referencefixer.log’) and set up the format to print with
-
classmethod
Sockets Module¶
Module containing classes for managing the comunincation with the socket thread and the main thread (in which we can use the SDAPI)
-
class
megascan_link_python.sockets.
SocketThread
¶ Bases:
PySide2.QtCore.QThread
Core plugin class that manages a socket process for receiving TCP packets from Quixel Bridge
-
close
()¶ Set the needed flags to close the socket
Note
The close operation is performed only after the timeout duration
-
onDataReceived
= <PySide2.QtCore.Signal object>¶ Signal that is fired whenever a packet is retrived over the socket
- Type
QtCore.Signal
- Parameters
object – json dictionary containing the data
-
restart
()¶ Set the needed flags to perform a socket restart
Note
The restart is performed only after the timeout duration
-
run
()¶ This is the method that manages the socket lifetime process
To interact with the socket use the
close()
andrestart()
method insteadWhile this method is running the associated thread is kept alive closing the socket without requesting a restart will make this thread close too
The socket is listening on the port specified on the config file and it is restarted every time the timeout duration expires (also setted from the config file)
-
shouldClose
= False¶ flag that indicates that the socket should stop in the next timeout frame
see
close()
Warning
dont use this flag directly use instead the
close()
methods
-
shouldRestart
= False¶ flag that indicates that a restart is been requested, the restart is processed in the next timeout frame, it is cleared (False) when the restart happen
used for example if you want to change the listening port or the timeout duration
see
restart()
Warning
dont use this flag directly use instead the
restart()
method instead
-
started
= False¶ variables that idicates if the socket has been started
but it is not guarantee that it is listening
-
staticMetaObject
= <PySide2.QtCore.QMetaObject object>¶
-
Utilities Module¶
Contain Helper Functions used in common tasks
-
megascan_link_python.utilities.
getAbsCurrentPath
(append: str) → str¶ Simple function to get the current script path
- Parameters
append (str) – path or filename to add
- Returns
the full path plus the append param
- Return type
str
Websocket Link Module¶
Module containing classes used to send data over the JS Plugin
-
class
megascan_link_python.websocket_link.
WebsocketLink
(parent=None)¶ Bases:
PySide2.QtCore.QObject
Start up a single use websocket to send data over the JS plugin
-
sendDataToJs
(data: object)¶ send the data to the JS plugin using a websocket with port 1212
- Parameters
data (object) – the json data to send
-
staticMetaObject
= <PySide2.QtCore.QMetaObject object>¶
-