Skip to content

Commit

Permalink
Fixed KnobPy widget to work in QtDesigner
Browse files Browse the repository at this point in the history
  • Loading branch information
redtide committed Mar 25, 2024
1 parent 329c856 commit ec1d857
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ __pycache__/
*.pyc
*.qm
*.user
resources/rc_resources.py
src/ui/rc_resources.py
src/ui/ui_mainwindow.py
9 changes: 5 additions & 4 deletions scripts/registerknob.py → scripts/registerknobpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# SPDX-License-Identifier: BSD-3-Clause

import sys, importlib.util
spec = importlib.util.spec_from_file_location("AyrePy", "src/ui/AyrePy.py")
AyrePy = importlib.util.module_from_spec(spec)
sys.modules["AyrePy"] = AyrePy
spec.loader.exec_module(AyrePy)
name = 'AyrePy'
spec = importlib.util.spec_from_file_location(name, "src/ui/AyrePy.py")
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
spec.loader.exec_module(module)

from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection
from AyrePy import KnobPy
Expand Down
8 changes: 6 additions & 2 deletions scripts/update_ui_files.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
rcc -g python resources/resources.qrc > resources/rc_resources.py
#!/bin/bash

rcc -g python resources/resources.qrc > src/ui/rc_resources.py
uic -g python -o src/ui/ui_mainwindow.py src/ui/mainwindow.ui

sed -i 's/PySide2/PySide6/g' resources/rc_resources.py
sed -i 's/PySide2/PySide6/g' src/ui/rc_resources.py
sed -i 's/PySide2/PySide6/g' src/ui/ui_mainwindow.py
sed -i 's/.Knob.hpp//g' src/ui/ui_mainwindow.py
sed -i 's/AyrePy/.AyrePy/g' src/ui/ui_mainwindow.py
sed -i 's/import resources_rc/from .rc_resources import */g' src/ui/ui_mainwindow.py
4 changes: 2 additions & 2 deletions sfzbuilder.pyproject
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"files": [
"scripts/designer.sh",
"scripts/update_ui_files.sh",
"scripts/registerknob.py",
"scripts/registerknobpy.py",
".editorconfig",
".gitignore",
"resources/resources.qrc",
Expand All @@ -16,7 +17,6 @@
"src/utils/constants.py",
"src/utils/enums.py",
"src/main.py",
"designer",
"sfzbuilder"
]
}
19 changes: 18 additions & 1 deletion src/ui/AyrePy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
# SPDX-License-Identifier: BSD-3-Clause

# This Python file uses the following encoding: utf-8
from PySide6.QtCore import QPointF, QRectF, QSize, Qt, Signal
from PySide6.QtCore import Property, QPointF, QRectF, QSize, Qt, Signal
from PySide6.QtGui import QPainter, QPixmap
from PySide6.QtWidgets import QHBoxLayout, QWidget

import sys, importlib.util
name = "rc_resources"
spec = importlib.util.spec_from_file_location(name, "src/ui/rc_resources.py")
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
spec.loader.exec_module(module)
from rc_resources import *

def clamp(n, min, max):
t = min if (n < min) else n
return max if (t > max) else t
Expand Down Expand Up @@ -196,3 +204,12 @@ def setValue(self, value):

def value(self):
return self.r.value

minimum = Property(float, minimum, setMinimum)
maximum = Property(float, maximum, setMaximum)
value = Property(float, value, setValue)
frames = Property(int, frameCount, setFrameCount)
image = Property(QPixmap, pixmap, setPixmap)
inverse = Property(bool, isInverted, setInverted)
param = Property(int, param, setParam)
vdefault = Property(float, defaultValue, setDefaultValue)
10 changes: 1 addition & 9 deletions src/ui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,16 @@
from PySide6.QtWidgets import QMainWindow, QFileDialog, QMessageBox, QApplication
from .ui_mainwindow import Ui_MainWindow
from .tabpan import setupKnobs
from .rc_resources import *
import os

import sys, importlib.util
spec = importlib.util.spec_from_file_location("rc", "resources/rc_resources.py")
resources = importlib.util.module_from_spec(spec)
sys.modules["resources"] = resources
spec.loader.exec_module(resources)
import resources as rc

current_map_ls = []
current_pack_dict = {}

class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)

rc.qInitResources() # TODO: Not needed, just silence a warning about the import above.

self.ui = Ui_MainWindow()
self.ui.setupUi(self)

Expand Down
9 changes: 7 additions & 2 deletions src/ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,9 @@
<height>16777215</height>
</size>
</property>
<property name="image" stdset="0">
<pixmap resource="../../resources/resources.qrc">:/pan</pixmap>
</property>
</widget>
</item>
<item row="1" column="2">
Expand Down Expand Up @@ -4423,10 +4426,12 @@
<customwidget>
<class>KnobPy</class>
<extends>QWidget</extends>
<header location="global">.AyrePy</header>
<header>AyrePy</header>
</customwidget>
</customwidgets>
<resources/>
<resources>
<include location="../../resources/resources.qrc"/>
</resources>
<connections>
<connection>
<sender>actQuit</sender>
Expand Down

0 comments on commit ec1d857

Please sign in to comment.