Skip to content

Instantly share code, notes, and snippets.

@promto-c
promto-c / get_nuke_main_window.py
Created March 15, 2024 10:24
PySide2 Script to Find Nuke's Main Window: This script iterates through top-level widgets to locate the main window, enabling further customization or interaction through Python.
from PySide2 import QtWidgets
def GetNukeMainWindow():
"""Finds and returns the main Nuke window.
Iterates through all top-level widgets, checking for the Nuke main window
based on its class name.
Returns:
import sys
import os
from PyQt5 import QtWidgets, QtCore
def restart_app_with_new_scale_factor(scale_factor: float):
"""Restarts the application with a new scale factor by setting the QT_SCALE_FACTOR environment variable.
Args:
scale_factor (float): The new scale factor to apply to the application's UI.
"""
@promto-c
promto-c / pyqt5_graphical_effects_demo.py
Created March 9, 2024 21:16
A comprehensive demonstration of applying various graphical effects to widgets in PyQt5.
from PyQt5 import QtCore, QtGui, QtWidgets
class EffectsDemo(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 240, 200)
self.setWindowTitle('PyQt5 Button Graphics Effects Demo')
@promto-c
promto-c / levenshtein_distance_fuzzy_search.py
Created March 7, 2024 06:28
Python Implementation of Levenshtein Distance for Fuzzy String Matching.
"""
Copyright (C) 2024 promto-c
Permission Notice:
- You are free to use, copy, modify, and distribute this software for any purpose.
- No restrictions are imposed on the use of this software.
- You do not need to give credit or include this notice in your work.
- Use at your own risk.
- This software is provided "AS IS" without any warranty, either expressed or implied.
Note: This code is intended primarily as an example. While you can use it freely as described above, be aware that it utilizes PyQt5, which is licensed under GPL v3. Ensure you adhere to PyQt5's licensing terms when using or distributing this code.
"""
@promto-c
promto-c / repo_structure_printer.py
Last active March 6, 2024 20:52
A Python script to print the structure of a repository, supporting .gitignore patterns and an option to display only directories.
"""
Copyright (C) 2024 promto-c
Permission Notice:
- You are free to use, copy, modify, and distribute this software for any purpose.
- No restrictions are imposed on the use of this software.
- You do not need to give credit or include this notice in your work.
- Use at your own risk.
- This software is provided "AS IS" without any warranty, either expressed or implied.
import nuke
import csv
# Constant for the number of columns per track in Tracker4 node
COLUMNS_PER_TRACK = 31
CSV_HEADERS = ['Track Name', 'Frame', 'X', 'Y']
def get_total_tracks_count(tracks_knob):
"""Calculate the number of tracks based on the tracks knob.
@promto-c
promto-c / uv_map_preview_from_obj.py
Last active March 4, 2024 06:27
Python script to parse UV coordinates from an OBJ file and preview the UV map. This utility reads the UV texture coordinates ('vt') from a specified OBJ file and visualizes the UV map using Matplotlib, providing a quick and simple way to preview the UV unwrapping of 3D models.
"""
Copyright (C) 2024 promto-c
Permission Notice:
- You are free to use, copy, modify, and distribute this software for any purpose.
- No restrictions are imposed on the use of this software.
- You do not need to give credit or include this notice in your work.
- Use at your own risk.
- This software is provided "AS IS" without any warranty, either expressed or implied.
"""
@promto-c
promto-c / extract_file_sequence_details.py
Created February 29, 2024 13:21
Python Script to Extract File Sequence Details
import re
from typing import Dict
def extract_file_details(input_string: str) -> Dict[str, str]:
"""Extracts directory name, file name, frame start, frame end, and extension from the input string.
Args:
input_string: A string in the format 'path/to/plates/plates_name.[1001-1017].ext'
Returns:
@promto-c
promto-c / PyQt5_LoginWidget_with_Credentials_Saving.py
Created February 21, 2024 15:56
Secure PyQt5 Login Widget with Credential Saving Feature using Keyring
import sys
from PyQt5 import QtWidgets, QtCore
import keyring
class LoginWidget(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.load_credentials()
import sys
from pathlib import Path
from PyQt5 import QtCore, QtWidgets
class StreamLogger:
"""A logger for streaming output to both the terminal and a log file.
Attributes:
terminal: A file object representing the standard output.
log: A file object for the log file where output is also written.