Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

321 lines
17KB

  1. #!/usr/bin/env python3
  2. # SPDX-FileCopyrightText: 2011-2025 Filipe Coelho <falktx@falktx.com>
  3. # SPDX-License-Identifier: GPL-2.0-or-later
  4. # ------------------------------------------------------------------------------------------------------------
  5. # Imports (Global)
  6. import os
  7. import sys
  8. # ------------------------------------------------------------------------------------------------------------
  9. # Imports (ctypes)
  10. from ctypes import CDLL, RTLD_GLOBAL
  11. # ------------------------------------------------------------------------------------------------------------
  12. # Imports (PyQt)
  13. from qt_compat import qt_config
  14. # pylint: disable=import-error
  15. if qt_config == 5:
  16. from PyQt5.QtCore import QT_VERSION, Qt, QCoreApplication, QLibraryInfo, QLocale, QTranslator
  17. from PyQt5.QtGui import QColor, QIcon, QPalette
  18. from PyQt5.QtWidgets import QApplication
  19. elif qt_config == 6:
  20. from PyQt6.QtCore import QT_VERSION, Qt, QCoreApplication, QLibraryInfo, QLocale, QTranslator
  21. from PyQt6.QtGui import QColor, QIcon, QPalette
  22. from PyQt6.QtWidgets import QApplication
  23. # pylint: enable=import-error
  24. # pylint: disable=possibly-used-before-assignment
  25. # ------------------------------------------------------------------------------------------------------------
  26. # Imports (Custom)
  27. from carla_backend import (
  28. CARLA_OS_64BIT,
  29. CARLA_OS_LINUX,
  30. CARLA_OS_MAC,
  31. CARLA_OS_WIN,
  32. CARLA_VERSION_STRING,
  33. )
  34. from carla_shared import (
  35. CARLA_KEY_MAIN_USE_PRO_THEME,
  36. CARLA_KEY_MAIN_PRO_THEME_COLOR,
  37. CARLA_DEFAULT_MAIN_USE_PRO_THEME,
  38. CARLA_DEFAULT_MAIN_PRO_THEME_COLOR,
  39. CWD,
  40. getPaths,
  41. gCarla
  42. )
  43. from utils import QSafeSettings
  44. # ------------------------------------------------------------------------------------------------------------
  45. class CarlaApplication():
  46. def __init__(self, appName = "Carla2", libPrefix = None):
  47. pathBinaries, pathResources = getPaths(libPrefix)
  48. # Needed for macOS and Windows
  49. if os.path.exists(CWD) and (CARLA_OS_MAC or CARLA_OS_WIN):
  50. QApplication.addLibraryPath(CWD)
  51. # Needed for local wine build
  52. if CARLA_OS_WIN and CWD.endswith(("frontend", "resources")) and os.getenv("CXFREEZE") is None:
  53. if CARLA_OS_64BIT:
  54. path = "H:\\PawPawBuilds\\targets\\win64\\lib\\qt5\\plugins"
  55. else:
  56. path = "H:\\PawPawBuilds\\targets\\win32\\lib\\qt5\\plugins"
  57. QApplication.addLibraryPath(path)
  58. # Try resource dir as library path first
  59. if os.path.exists(os.path.join(pathResources, "styles", "carlastyle.json")):
  60. QApplication.addLibraryPath(pathResources)
  61. stylesDir = pathResources
  62. # Use binary dir as library path
  63. elif os.path.exists(pathBinaries):
  64. QApplication.addLibraryPath(pathBinaries)
  65. stylesDir = pathBinaries
  66. # If style is not available we can still fake it
  67. else:
  68. stylesDir = ""
  69. # Set up translations
  70. currentLocale = QLocale()
  71. appTranslator = QTranslator()
  72. sysTranslator = None
  73. pathTranslations = os.path.join(pathResources, "translations")
  74. if appTranslator.load(currentLocale, "carla", "_", pathTranslations):
  75. sysTranslator = QTranslator()
  76. pathSysTranslations = pathTranslations
  77. if not sysTranslator.load(currentLocale, "qt", "_", pathSysTranslations):
  78. pathSysTranslations = QLibraryInfo.location(QLibraryInfo.TranslationsPath)
  79. sysTranslator.load(currentLocale, "qt", "_", pathSysTranslations)
  80. else:
  81. appTranslator = None
  82. self.fAppTranslator = appTranslator
  83. self.fSysTranslator = sysTranslator
  84. # base settings
  85. settings = QSafeSettings("falkTX", appName)
  86. useProTheme = CARLA_OS_MAC or settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, CARLA_DEFAULT_MAIN_USE_PRO_THEME, bool)
  87. if not useProTheme:
  88. self.createApp(appName)
  89. return
  90. # set style
  91. QApplication.setStyle("carla" if stylesDir else "fusion")
  92. # create app
  93. self.createApp(appName)
  94. if gCarla.nogui:
  95. return
  96. self.fApp.setStyle("carla" if stylesDir else "fusion")
  97. if CARLA_OS_WIN:
  98. carlastyle1 = os.path.join(pathBinaries, "styles", "carlastyle.dll")
  99. carlastyle2 = os.path.join(pathResources, "styles", "carlastyle.dll")
  100. carlastyle = carlastyle2 if os.path.exists(carlastyle2) else carlastyle1
  101. self._stylelib = CDLL(carlastyle, RTLD_GLOBAL)
  102. self._stylelib.set_qt_app_style.argtypes = None
  103. self._stylelib.set_qt_app_style.restype = None
  104. self._stylelib.set_qt_app_style()
  105. # set palette
  106. proThemeColor = settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, CARLA_DEFAULT_MAIN_PRO_THEME_COLOR, str).lower()
  107. if CARLA_OS_MAC or proThemeColor == "black":
  108. self.createPaletteBlack()
  109. elif proThemeColor == "blue":
  110. self.createPaletteBlue()
  111. def createApp(self, appName):
  112. if qt_config == 5 and CARLA_OS_LINUX:
  113. # AA_X11InitThreads is not available on old PyQt versions
  114. try:
  115. attr = Qt.AA_X11InitThreads
  116. except:
  117. attr = 10
  118. QApplication.setAttribute(attr)
  119. if QT_VERSION >= 0x50600:
  120. QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
  121. QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
  122. if CARLA_OS_MAC:
  123. QApplication.setAttribute(Qt.AA_DontShowIconsInMenus)
  124. args = sys.argv[:]
  125. if CARLA_OS_WIN:
  126. args += ["-platform", "windows:fontengine=freetype"]
  127. self.fApp = QCoreApplication(args) if gCarla.nogui else QApplication(args)
  128. self.fApp.setApplicationName(appName)
  129. self.fApp.setApplicationVersion(CARLA_VERSION_STRING)
  130. self.fApp.setOrganizationName("falkTX")
  131. if self.fAppTranslator is not None:
  132. self.fApp.installTranslator(self.fAppTranslator)
  133. self.fApp.installTranslator(self.fSysTranslator)
  134. if gCarla.nogui:
  135. return
  136. if appName == "Carla2-Control":
  137. if QT_VERSION >= 0x50700:
  138. self.fApp.setDesktopFileName("carla-control")
  139. self.fApp.setWindowIcon(QIcon(":/scalable/carla-control.svg"))
  140. else:
  141. if QT_VERSION >= 0x50700:
  142. self.fApp.setDesktopFileName("carla")
  143. self.fApp.setWindowIcon(QIcon(":/scalable/carla.svg"))
  144. def createPaletteBlack(self):
  145. self.fPalBlack = QPalette()
  146. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Window, QColor(14, 14, 14))
  147. self.fPalBlack.setColor(QPalette.Active, QPalette.Window, QColor(17, 17, 17))
  148. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Window, QColor(17, 17, 17))
  149. self.fPalBlack.setColor(QPalette.Disabled, QPalette.WindowText, QColor(83, 83, 83))
  150. self.fPalBlack.setColor(QPalette.Active, QPalette.WindowText, QColor(240, 240, 240))
  151. self.fPalBlack.setColor(QPalette.Inactive, QPalette.WindowText, QColor(240, 240, 240))
  152. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Base, QColor(6, 6, 6))
  153. self.fPalBlack.setColor(QPalette.Active, QPalette.Base, QColor(7, 7, 7))
  154. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Base, QColor(7, 7, 7))
  155. self.fPalBlack.setColor(QPalette.Disabled, QPalette.AlternateBase, QColor(12, 12, 12))
  156. self.fPalBlack.setColor(QPalette.Active, QPalette.AlternateBase, QColor(14, 14, 14))
  157. self.fPalBlack.setColor(QPalette.Inactive, QPalette.AlternateBase, QColor(14, 14, 14))
  158. self.fPalBlack.setColor(QPalette.Disabled, QPalette.ToolTipBase, QColor(4, 4, 4))
  159. self.fPalBlack.setColor(QPalette.Active, QPalette.ToolTipBase, QColor(4, 4, 4))
  160. self.fPalBlack.setColor(QPalette.Inactive, QPalette.ToolTipBase, QColor(4, 4, 4))
  161. self.fPalBlack.setColor(QPalette.Disabled, QPalette.ToolTipText, QColor(230, 230, 230))
  162. self.fPalBlack.setColor(QPalette.Active, QPalette.ToolTipText, QColor(230, 230, 230))
  163. self.fPalBlack.setColor(QPalette.Inactive, QPalette.ToolTipText, QColor(230, 230, 230))
  164. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Text, QColor(74, 74, 74))
  165. self.fPalBlack.setColor(QPalette.Active, QPalette.Text, QColor(230, 230, 230))
  166. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Text, QColor(230, 230, 230))
  167. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Button, QColor(24, 24, 24))
  168. self.fPalBlack.setColor(QPalette.Active, QPalette.Button, QColor(28, 28, 28))
  169. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Button, QColor(28, 28, 28))
  170. self.fPalBlack.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(90, 90, 90))
  171. self.fPalBlack.setColor(QPalette.Active, QPalette.ButtonText, QColor(240, 240, 240))
  172. self.fPalBlack.setColor(QPalette.Inactive, QPalette.ButtonText, QColor(240, 240, 240))
  173. self.fPalBlack.setColor(QPalette.Disabled, QPalette.BrightText, QColor(255, 255, 255))
  174. self.fPalBlack.setColor(QPalette.Active, QPalette.BrightText, QColor(255, 255, 255))
  175. self.fPalBlack.setColor(QPalette.Inactive, QPalette.BrightText, QColor(255, 255, 255))
  176. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Light, QColor(191, 191, 191))
  177. self.fPalBlack.setColor(QPalette.Active, QPalette.Light, QColor(191, 191, 191))
  178. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Light, QColor(191, 191, 191))
  179. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Midlight, QColor(155, 155, 155))
  180. self.fPalBlack.setColor(QPalette.Active, QPalette.Midlight, QColor(155, 155, 155))
  181. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Midlight, QColor(155, 155, 155))
  182. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Dark, QColor(129, 129, 129))
  183. self.fPalBlack.setColor(QPalette.Active, QPalette.Dark, QColor(129, 129, 129))
  184. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Dark, QColor(129, 129, 129))
  185. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Mid, QColor(94, 94, 94))
  186. self.fPalBlack.setColor(QPalette.Active, QPalette.Mid, QColor(94, 94, 94))
  187. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Mid, QColor(94, 94, 94))
  188. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Shadow, QColor(155, 155, 155))
  189. self.fPalBlack.setColor(QPalette.Active, QPalette.Shadow, QColor(155, 155, 155))
  190. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Shadow, QColor(155, 155, 155))
  191. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Highlight, QColor(14, 14, 14))
  192. self.fPalBlack.setColor(QPalette.Active, QPalette.Highlight, QColor(60, 60, 60))
  193. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Highlight, QColor(34, 34, 34))
  194. self.fPalBlack.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(83, 83, 83))
  195. self.fPalBlack.setColor(QPalette.Active, QPalette.HighlightedText, QColor(255, 255, 255))
  196. self.fPalBlack.setColor(QPalette.Inactive, QPalette.HighlightedText, QColor(240, 240, 240))
  197. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Link, QColor(34, 34, 74))
  198. self.fPalBlack.setColor(QPalette.Active, QPalette.Link, QColor(100, 100, 230))
  199. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Link, QColor(100, 100, 230))
  200. self.fPalBlack.setColor(QPalette.Disabled, QPalette.LinkVisited, QColor(74, 34, 74))
  201. self.fPalBlack.setColor(QPalette.Active, QPalette.LinkVisited, QColor(230, 100, 230))
  202. self.fPalBlack.setColor(QPalette.Inactive, QPalette.LinkVisited, QColor(230, 100, 230))
  203. self.fApp.setPalette(self.fPalBlack)
  204. def createPaletteBlue(self):
  205. self.fPalBlue = QPalette()
  206. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Window, QColor(32, 35, 39))
  207. self.fPalBlue.setColor(QPalette.Active, QPalette.Window, QColor(37, 40, 45))
  208. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Window, QColor(37, 40, 45))
  209. self.fPalBlue.setColor(QPalette.Disabled, QPalette.WindowText, QColor(89, 95, 104))
  210. self.fPalBlue.setColor(QPalette.Active, QPalette.WindowText, QColor(223, 237, 255))
  211. self.fPalBlue.setColor(QPalette.Inactive, QPalette.WindowText, QColor(223, 237, 255))
  212. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Base, QColor(48, 53, 60))
  213. self.fPalBlue.setColor(QPalette.Active, QPalette.Base, QColor(55, 61, 69))
  214. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Base, QColor(55, 61, 69))
  215. self.fPalBlue.setColor(QPalette.Disabled, QPalette.AlternateBase, QColor(60, 64, 67))
  216. self.fPalBlue.setColor(QPalette.Active, QPalette.AlternateBase, QColor(69, 73, 77))
  217. self.fPalBlue.setColor(QPalette.Inactive, QPalette.AlternateBase, QColor(69, 73, 77))
  218. self.fPalBlue.setColor(QPalette.Disabled, QPalette.ToolTipBase, QColor(182, 193, 208))
  219. self.fPalBlue.setColor(QPalette.Active, QPalette.ToolTipBase, QColor(182, 193, 208))
  220. self.fPalBlue.setColor(QPalette.Inactive, QPalette.ToolTipBase, QColor(182, 193, 208))
  221. self.fPalBlue.setColor(QPalette.Disabled, QPalette.ToolTipText, QColor(42, 44, 48))
  222. self.fPalBlue.setColor(QPalette.Active, QPalette.ToolTipText, QColor(42, 44, 48))
  223. self.fPalBlue.setColor(QPalette.Inactive, QPalette.ToolTipText, QColor(42, 44, 48))
  224. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Text, QColor(96, 103, 113))
  225. self.fPalBlue.setColor(QPalette.Active, QPalette.Text, QColor(210, 222, 240))
  226. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Text, QColor(210, 222, 240))
  227. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Button, QColor(51, 55, 62))
  228. self.fPalBlue.setColor(QPalette.Active, QPalette.Button, QColor(59, 63, 71))
  229. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Button, QColor(59, 63, 71))
  230. self.fPalBlue.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(98, 104, 114))
  231. self.fPalBlue.setColor(QPalette.Active, QPalette.ButtonText, QColor(210, 222, 240))
  232. self.fPalBlue.setColor(QPalette.Inactive, QPalette.ButtonText, QColor(210, 222, 240))
  233. self.fPalBlue.setColor(QPalette.Disabled, QPalette.BrightText, QColor(255, 255, 255))
  234. self.fPalBlue.setColor(QPalette.Active, QPalette.BrightText, QColor(255, 255, 255))
  235. self.fPalBlue.setColor(QPalette.Inactive, QPalette.BrightText, QColor(255, 255, 255))
  236. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Light, QColor(59, 64, 72))
  237. self.fPalBlue.setColor(QPalette.Active, QPalette.Light, QColor(63, 68, 76))
  238. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Light, QColor(63, 68, 76))
  239. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Midlight, QColor(48, 52, 59))
  240. self.fPalBlue.setColor(QPalette.Active, QPalette.Midlight, QColor(51, 56, 63))
  241. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Midlight, QColor(51, 56, 63))
  242. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Dark, QColor(18, 19, 22))
  243. self.fPalBlue.setColor(QPalette.Active, QPalette.Dark, QColor(20, 22, 25))
  244. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Dark, QColor(20, 22, 25))
  245. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Mid, QColor(28, 30, 34))
  246. self.fPalBlue.setColor(QPalette.Active, QPalette.Mid, QColor(32, 35, 39))
  247. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Mid, QColor(32, 35, 39))
  248. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Shadow, QColor(13, 14, 16))
  249. self.fPalBlue.setColor(QPalette.Active, QPalette.Shadow, QColor(15, 16, 18))
  250. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Shadow, QColor(15, 16, 18))
  251. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Highlight, QColor(32, 35, 39))
  252. self.fPalBlue.setColor(QPalette.Active, QPalette.Highlight, QColor(14, 14, 17))
  253. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Highlight, QColor(27, 28, 33))
  254. self.fPalBlue.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(89, 95, 104))
  255. self.fPalBlue.setColor(QPalette.Active, QPalette.HighlightedText, QColor(217, 234, 253))
  256. self.fPalBlue.setColor(QPalette.Inactive, QPalette.HighlightedText, QColor(223, 237, 255))
  257. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Link, QColor(79, 100, 118))
  258. self.fPalBlue.setColor(QPalette.Active, QPalette.Link, QColor(156, 212, 255))
  259. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Link, QColor(156, 212, 255))
  260. self.fPalBlue.setColor(QPalette.Disabled, QPalette.LinkVisited, QColor(51, 74, 118))
  261. self.fPalBlue.setColor(QPalette.Active, QPalette.LinkVisited, QColor(64, 128, 255))
  262. self.fPalBlue.setColor(QPalette.Inactive, QPalette.LinkVisited, QColor(64, 128, 255))
  263. self.fApp.setPalette(self.fPalBlue)
  264. def exec_(self):
  265. return self.fApp.exec_()
  266. def exit_exec(self):
  267. return sys.exit(self.fApp.exec_())
  268. def getApp(self):
  269. return self.fApp
  270. def quit(self):
  271. self.fApp.quit()
  272. # ------------------------------------------------------------------------------------------------------------
  273. # pylint: enable=possibly-used-before-assignment