kitstarter 0.1.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
kitstarter/__init__.py ADDED
@@ -0,0 +1,141 @@
1
+ # kitstarter/__init__.py
2
+ #
3
+ # Copyright 2025 Leon Dionne <ldionne@dridesign.sh.cn>
4
+ #
5
+ """
6
+ kitstarter is a program you can use to "sketch in" a drumkit SFZ file.
7
+ """
8
+ import sys, os, argparse, logging, json, glob
9
+ try:
10
+ from functools import cache
11
+ except ImportError:
12
+ from functools import lru_cache as cache
13
+ from PyQt5.QtCore import QSettings
14
+ from PyQt5.QtWidgets import QApplication, QWidget, QSplitter
15
+ from qt_extras import DevilBox
16
+ from conn_jack import JackConnectError
17
+
18
+ __version__ = "0.1.0"
19
+
20
+
21
+ APPLICATION_NAME = "KitStarter"
22
+ PACKAGE_DIR = os.path.dirname(__file__)
23
+ DEFAULT_STYLE = 'system'
24
+ KEY_STYLE = 'Style'
25
+ KEY_RECENT_FOLDER = 'RecentProjectFolder'
26
+ KEY_FILES_ROOT = 'FilesRoot'
27
+ KEY_FILES_CURRENT = 'FilesCurrent'
28
+
29
+ @cache
30
+ def settings():
31
+ return QSettings('ZenSoSo', 'kitstarter')
32
+
33
+
34
+ @cache
35
+ def styles():
36
+ return {
37
+ os.path.splitext(os.path.basename(path))[0] : path \
38
+ for path in glob.glob(os.path.join(PACKAGE_DIR, 'styles', '*.css'))
39
+ }
40
+
41
+ def set_application_style():
42
+ style = settings().value(KEY_STYLE, DEFAULT_STYLE)
43
+ try:
44
+ with open(styles()[style], 'r', encoding = 'utf-8') as cssfile:
45
+ QApplication.instance().setStyleSheet(cssfile.read())
46
+ except KeyError:
47
+ pass
48
+
49
+ # -------------------------------------------------------------------
50
+ # Cross-platform open any file / folder with system associated tool
51
+
52
+ def xdg_open(filename):
53
+ if system() == "Windows":
54
+ startfile(filename)
55
+ elif system() == "Darwin":
56
+ Popen(["open", filename])
57
+ else:
58
+ Popen(["xdg-open", filename])
59
+
60
+
61
+ # -------------------------------------------------------------------
62
+ # Add save / restore geometry methods to the QWidget class:
63
+
64
+ def _restore_geometry(widget):
65
+ """
66
+ Restores geometry from musecbox settings using automatically generated key.
67
+ """
68
+ if not hasattr(widget, 'restoreGeometry'):
69
+ return
70
+ geometry = settings().value(_geometry_key(widget))
71
+ if not geometry is None:
72
+ widget.restoreGeometry(geometry)
73
+ for splitter in widget.findChildren(QSplitter):
74
+ geometry = settings().value(_splitter_geometry_key(widget, splitter))
75
+ if not geometry is None:
76
+ splitter.restoreState(geometry)
77
+
78
+ def _save_geometry(widget):
79
+ """
80
+ Saves geometry to musecbox settings using automatically generated key.
81
+ """
82
+ if not hasattr(widget, 'saveGeometry'):
83
+ return
84
+ settings().setValue(_geometry_key(widget), widget.saveGeometry())
85
+ for splitter in widget.findChildren(QSplitter):
86
+ settings().setValue(_splitter_geometry_key(widget, splitter), splitter.saveState())
87
+
88
+ def _geometry_key(widget):
89
+ """
90
+ Automatic QSettings key generated from class name.
91
+ """
92
+ return f'{type(widget).__name__}/geometry'
93
+
94
+ def _splitter_geometry_key(widget, splitter):
95
+ """
96
+ Automatic QSettings key generated from class name.
97
+ """
98
+ return f'{type(widget).__name__}/{splitter.objectName()}/geometry'
99
+
100
+ QWidget.restore_geometry = _restore_geometry
101
+ QWidget.save_geometry = _save_geometry
102
+
103
+
104
+ def main():
105
+ from kitstarter.gui.main_window import MainWindow
106
+
107
+ p = argparse.ArgumentParser()
108
+ p.epilog = """
109
+ Write your help text!
110
+ """
111
+ p.add_argument('Filename', type=str, nargs='?', help='.SFZ file to import')
112
+ p.add_argument("--verbose", "-v", action="store_true", help="Show more detailed debug information")
113
+ options = p.parse_args()
114
+ log_level = logging.DEBUG if options.verbose else logging.ERROR
115
+ log_format = "[%(filename)24s:%(lineno)4d] %(levelname)-8s %(message)s"
116
+ logging.basicConfig(level = log_level, format = log_format)
117
+
118
+ #-----------------------------------------------------------------------
119
+ # Annoyance fix per:
120
+ # https://stackoverflow.com/questions/986964/qt-session-management-error
121
+ try:
122
+ del os.environ['SESSION_MANAGER']
123
+ except KeyError:
124
+ pass
125
+ #-----------------------------------------------------------------------
126
+
127
+ app = QApplication([])
128
+ try:
129
+ main_window = MainWindow(options.Filename or None)
130
+ except JackConnectError:
131
+ DevilBox('Could not connect to JACK server. Is it running?')
132
+ sys.exit(1)
133
+ main_window.show()
134
+ sys.exit(app.exec())
135
+
136
+
137
+ if __name__ == "__main__":
138
+ sys.exit(main())
139
+
140
+
141
+ # end kitstarter/__init__.py
@@ -0,0 +1,20 @@
1
+ # kitstarter/gui/__init__.py
2
+ #
3
+ # Copyright 2025 Leon Dionne <ldionne@dridesign.sh.cn>
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
+ # MA 02110-1301, USA.
19
+ #
20
+ # end kitstarter/gui/__init__.py