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.

262 lines
16KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Carla application
  4. # Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from PyQt5.QtCore import QT_VERSION, Qt, QCoreApplication, QSettings
  20. from PyQt5.QtGui import QColor, QPalette
  21. from PyQt5.QtWidgets import QApplication
  22. # ------------------------------------------------------------------------------------------------------------
  23. # Imports (Custom)
  24. from carla_shared import *
  25. # ------------------------------------------------------------------------------------------------------------
  26. class CarlaApplication(object):
  27. def __init__(self, appName = "Carla2", libPrefix = None):
  28. object.__init__(self)
  29. pathBinaries, pathResources = getPaths(libPrefix)
  30. # Needed for MacOS and Windows
  31. if os.path.exists(CWD) and (MACOS or WINDOWS):
  32. QApplication.addLibraryPath(CWD)
  33. # Needed for local wine build
  34. if WINDOWS and CWD.endswith(("frontend", "resources")) and os.getenv("CXFREEZE") is None:
  35. if kIs64bit:
  36. path = "H:\\builds\\msys2-x86_64\\mingw64\\share\\qt5\\plugins"
  37. else:
  38. path = "H:\\builds\\msys2-i686\\mingw32\\share\\qt5\\plugins"
  39. QApplication.addLibraryPath(path)
  40. # Use binary dir as library path
  41. if os.path.exists(pathBinaries):
  42. QApplication.addLibraryPath(pathBinaries)
  43. stylesDir = pathBinaries
  44. # If style is not available we can still fake it
  45. else:
  46. stylesDir = ""
  47. # base settings
  48. settings = QSettings("falkTX", appName)
  49. useProTheme = MACOS or settings.value(CARLA_KEY_MAIN_USE_PRO_THEME, CARLA_DEFAULT_MAIN_USE_PRO_THEME, type=bool)
  50. if not useProTheme:
  51. self.createApp(appName)
  52. return
  53. # set style
  54. QApplication.setStyle("carla" if stylesDir else "fusion")
  55. # create app
  56. self.createApp(appName)
  57. if gCarla.nogui:
  58. return
  59. self.fApp.setStyle("carla" if stylesDir else "fusion")
  60. if WINDOWS:
  61. carlastyle = os.path.join(pathBinaries, "styles", "carlastyle.dll")
  62. self._stylelib = CDLL(carlastyle, RTLD_GLOBAL)
  63. self._stylelib.set_qt_app_style.argtypes = None
  64. self._stylelib.set_qt_app_style.restype = None
  65. self._stylelib.set_qt_app_style()
  66. # set palette
  67. proThemeColor = settings.value(CARLA_KEY_MAIN_PRO_THEME_COLOR, CARLA_DEFAULT_MAIN_PRO_THEME_COLOR, type=str).lower()
  68. if MACOS or proThemeColor == "black":
  69. self.fPalBlack = QPalette()
  70. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Window, QColor(14, 14, 14))
  71. self.fPalBlack.setColor(QPalette.Active, QPalette.Window, QColor(17, 17, 17))
  72. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Window, QColor(17, 17, 17))
  73. self.fPalBlack.setColor(QPalette.Disabled, QPalette.WindowText, QColor(83, 83, 83))
  74. self.fPalBlack.setColor(QPalette.Active, QPalette.WindowText, QColor(240, 240, 240))
  75. self.fPalBlack.setColor(QPalette.Inactive, QPalette.WindowText, QColor(240, 240, 240))
  76. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Base, QColor(6, 6, 6))
  77. self.fPalBlack.setColor(QPalette.Active, QPalette.Base, QColor(7, 7, 7))
  78. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Base, QColor(7, 7, 7))
  79. self.fPalBlack.setColor(QPalette.Disabled, QPalette.AlternateBase, QColor(12, 12, 12))
  80. self.fPalBlack.setColor(QPalette.Active, QPalette.AlternateBase, QColor(14, 14, 14))
  81. self.fPalBlack.setColor(QPalette.Inactive, QPalette.AlternateBase, QColor(14, 14, 14))
  82. self.fPalBlack.setColor(QPalette.Disabled, QPalette.ToolTipBase, QColor(4, 4, 4))
  83. self.fPalBlack.setColor(QPalette.Active, QPalette.ToolTipBase, QColor(4, 4, 4))
  84. self.fPalBlack.setColor(QPalette.Inactive, QPalette.ToolTipBase, QColor(4, 4, 4))
  85. self.fPalBlack.setColor(QPalette.Disabled, QPalette.ToolTipText, QColor(230, 230, 230))
  86. self.fPalBlack.setColor(QPalette.Active, QPalette.ToolTipText, QColor(230, 230, 230))
  87. self.fPalBlack.setColor(QPalette.Inactive, QPalette.ToolTipText, QColor(230, 230, 230))
  88. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Text, QColor(74, 74, 74))
  89. self.fPalBlack.setColor(QPalette.Active, QPalette.Text, QColor(230, 230, 230))
  90. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Text, QColor(230, 230, 230))
  91. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Button, QColor(24, 24, 24))
  92. self.fPalBlack.setColor(QPalette.Active, QPalette.Button, QColor(28, 28, 28))
  93. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Button, QColor(28, 28, 28))
  94. self.fPalBlack.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(90, 90, 90))
  95. self.fPalBlack.setColor(QPalette.Active, QPalette.ButtonText, QColor(240, 240, 240))
  96. self.fPalBlack.setColor(QPalette.Inactive, QPalette.ButtonText, QColor(240, 240, 240))
  97. self.fPalBlack.setColor(QPalette.Disabled, QPalette.BrightText, QColor(255, 255, 255))
  98. self.fPalBlack.setColor(QPalette.Active, QPalette.BrightText, QColor(255, 255, 255))
  99. self.fPalBlack.setColor(QPalette.Inactive, QPalette.BrightText, QColor(255, 255, 255))
  100. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Light, QColor(191, 191, 191))
  101. self.fPalBlack.setColor(QPalette.Active, QPalette.Light, QColor(191, 191, 191))
  102. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Light, QColor(191, 191, 191))
  103. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Midlight, QColor(155, 155, 155))
  104. self.fPalBlack.setColor(QPalette.Active, QPalette.Midlight, QColor(155, 155, 155))
  105. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Midlight, QColor(155, 155, 155))
  106. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Dark, QColor(129, 129, 129))
  107. self.fPalBlack.setColor(QPalette.Active, QPalette.Dark, QColor(129, 129, 129))
  108. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Dark, QColor(129, 129, 129))
  109. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Mid, QColor(94, 94, 94))
  110. self.fPalBlack.setColor(QPalette.Active, QPalette.Mid, QColor(94, 94, 94))
  111. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Mid, QColor(94, 94, 94))
  112. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Shadow, QColor(155, 155, 155))
  113. self.fPalBlack.setColor(QPalette.Active, QPalette.Shadow, QColor(155, 155, 155))
  114. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Shadow, QColor(155, 155, 155))
  115. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Highlight, QColor(14, 14, 14))
  116. self.fPalBlack.setColor(QPalette.Active, QPalette.Highlight, QColor(60, 60, 60))
  117. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Highlight, QColor(34, 34, 34))
  118. self.fPalBlack.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(83, 83, 83))
  119. self.fPalBlack.setColor(QPalette.Active, QPalette.HighlightedText, QColor(255, 255, 255))
  120. self.fPalBlack.setColor(QPalette.Inactive, QPalette.HighlightedText, QColor(240, 240, 240))
  121. self.fPalBlack.setColor(QPalette.Disabled, QPalette.Link, QColor(34, 34, 74))
  122. self.fPalBlack.setColor(QPalette.Active, QPalette.Link, QColor(100, 100, 230))
  123. self.fPalBlack.setColor(QPalette.Inactive, QPalette.Link, QColor(100, 100, 230))
  124. self.fPalBlack.setColor(QPalette.Disabled, QPalette.LinkVisited, QColor(74, 34, 74))
  125. self.fPalBlack.setColor(QPalette.Active, QPalette.LinkVisited, QColor(230, 100, 230))
  126. self.fPalBlack.setColor(QPalette.Inactive, QPalette.LinkVisited, QColor(230, 100, 230))
  127. self.fApp.setPalette(self.fPalBlack)
  128. elif proThemeColor == "blue":
  129. self.fPalBlue = QPalette()
  130. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Window, QColor(32, 35, 39))
  131. self.fPalBlue.setColor(QPalette.Active, QPalette.Window, QColor(37, 40, 45))
  132. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Window, QColor(37, 40, 45))
  133. self.fPalBlue.setColor(QPalette.Disabled, QPalette.WindowText, QColor(89, 95, 104))
  134. self.fPalBlue.setColor(QPalette.Active, QPalette.WindowText, QColor(223, 237, 255))
  135. self.fPalBlue.setColor(QPalette.Inactive, QPalette.WindowText, QColor(223, 237, 255))
  136. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Base, QColor(48, 53, 60))
  137. self.fPalBlue.setColor(QPalette.Active, QPalette.Base, QColor(55, 61, 69))
  138. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Base, QColor(55, 61, 69))
  139. self.fPalBlue.setColor(QPalette.Disabled, QPalette.AlternateBase, QColor(60, 64, 67))
  140. self.fPalBlue.setColor(QPalette.Active, QPalette.AlternateBase, QColor(69, 73, 77))
  141. self.fPalBlue.setColor(QPalette.Inactive, QPalette.AlternateBase, QColor(69, 73, 77))
  142. self.fPalBlue.setColor(QPalette.Disabled, QPalette.ToolTipBase, QColor(182, 193, 208))
  143. self.fPalBlue.setColor(QPalette.Active, QPalette.ToolTipBase, QColor(182, 193, 208))
  144. self.fPalBlue.setColor(QPalette.Inactive, QPalette.ToolTipBase, QColor(182, 193, 208))
  145. self.fPalBlue.setColor(QPalette.Disabled, QPalette.ToolTipText, QColor(42, 44, 48))
  146. self.fPalBlue.setColor(QPalette.Active, QPalette.ToolTipText, QColor(42, 44, 48))
  147. self.fPalBlue.setColor(QPalette.Inactive, QPalette.ToolTipText, QColor(42, 44, 48))
  148. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Text, QColor(96, 103, 113))
  149. self.fPalBlue.setColor(QPalette.Active, QPalette.Text, QColor(210, 222, 240))
  150. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Text, QColor(210, 222, 240))
  151. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Button, QColor(51, 55, 62))
  152. self.fPalBlue.setColor(QPalette.Active, QPalette.Button, QColor(59, 63, 71))
  153. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Button, QColor(59, 63, 71))
  154. self.fPalBlue.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(98, 104, 114))
  155. self.fPalBlue.setColor(QPalette.Active, QPalette.ButtonText, QColor(210, 222, 240))
  156. self.fPalBlue.setColor(QPalette.Inactive, QPalette.ButtonText, QColor(210, 222, 240))
  157. self.fPalBlue.setColor(QPalette.Disabled, QPalette.BrightText, QColor(255, 255, 255))
  158. self.fPalBlue.setColor(QPalette.Active, QPalette.BrightText, QColor(255, 255, 255))
  159. self.fPalBlue.setColor(QPalette.Inactive, QPalette.BrightText, QColor(255, 255, 255))
  160. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Light, QColor(59, 64, 72))
  161. self.fPalBlue.setColor(QPalette.Active, QPalette.Light, QColor(63, 68, 76))
  162. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Light, QColor(63, 68, 76))
  163. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Midlight, QColor(48, 52, 59))
  164. self.fPalBlue.setColor(QPalette.Active, QPalette.Midlight, QColor(51, 56, 63))
  165. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Midlight, QColor(51, 56, 63))
  166. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Dark, QColor(18, 19, 22))
  167. self.fPalBlue.setColor(QPalette.Active, QPalette.Dark, QColor(20, 22, 25))
  168. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Dark, QColor(20, 22, 25))
  169. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Mid, QColor(28, 30, 34))
  170. self.fPalBlue.setColor(QPalette.Active, QPalette.Mid, QColor(32, 35, 39))
  171. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Mid, QColor(32, 35, 39))
  172. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Shadow, QColor(13, 14, 16))
  173. self.fPalBlue.setColor(QPalette.Active, QPalette.Shadow, QColor(15, 16, 18))
  174. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Shadow, QColor(15, 16, 18))
  175. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Highlight, QColor(32, 35, 39))
  176. self.fPalBlue.setColor(QPalette.Active, QPalette.Highlight, QColor(14, 14, 17))
  177. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Highlight, QColor(27, 28, 33))
  178. self.fPalBlue.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(89, 95, 104))
  179. self.fPalBlue.setColor(QPalette.Active, QPalette.HighlightedText, QColor(217, 234, 253))
  180. self.fPalBlue.setColor(QPalette.Inactive, QPalette.HighlightedText, QColor(223, 237, 255))
  181. self.fPalBlue.setColor(QPalette.Disabled, QPalette.Link, QColor(79, 100, 118))
  182. self.fPalBlue.setColor(QPalette.Active, QPalette.Link, QColor(156, 212, 255))
  183. self.fPalBlue.setColor(QPalette.Inactive, QPalette.Link, QColor(156, 212, 255))
  184. self.fPalBlue.setColor(QPalette.Disabled, QPalette.LinkVisited, QColor(51, 74, 118))
  185. self.fPalBlue.setColor(QPalette.Active, QPalette.LinkVisited, QColor(64, 128, 255))
  186. self.fPalBlue.setColor(QPalette.Inactive, QPalette.LinkVisited, QColor(64, 128, 255))
  187. self.fApp.setPalette(self.fPalBlue)
  188. def createApp(self, appName):
  189. if LINUX:
  190. # AA_X11InitThreads is not available on old PyQt versions
  191. try:
  192. attr = Qt.AA_X11InitThreads
  193. except:
  194. attr = 10
  195. QApplication.setAttribute(attr)
  196. if MACOS:
  197. QApplication.setAttribute(Qt.AA_DontShowIconsInMenus)
  198. if QT_VERSION >= 0x50600:
  199. QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
  200. QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
  201. args = sys.argv[:]
  202. if WINDOWS:
  203. args += ["-platform", "windows:fontengine=freetype"]
  204. self.fApp = QCoreApplication(args) if gCarla.nogui else QApplication(args)
  205. self.fApp.setApplicationName(appName)
  206. self.fApp.setApplicationVersion(VERSION)
  207. self.fApp.setOrganizationName("falkTX")
  208. if gCarla.nogui:
  209. return
  210. if appName.lower() == "carla-control":
  211. if QT_VERSION >= 0x50700:
  212. self.fApp.setDesktopFileName("carla-control")
  213. self.fApp.setWindowIcon(QIcon(":/scalable/carla-control.svg"))
  214. else:
  215. if QT_VERSION >= 0x50700:
  216. self.fApp.setDesktopFileName("carla")
  217. self.fApp.setWindowIcon(QIcon(":/scalable/carla.svg"))
  218. def exec_(self):
  219. return self.fApp.exec_()
  220. def exit_exec(self):
  221. return sys.exit(self.fApp.exec_())
  222. def getApp(self):
  223. return self.fApp
  224. def quit(self):
  225. self.fApp.quit()
  226. # ------------------------------------------------------------------------------------------------------------