Collection of tools useful for audio production
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.

111 lines
3.2KB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Common/Shared code
  4. # Copyright (C) 2012 Filipe Coelho <falktx@gmail.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # 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 COPYING file
  17. # Imports (Global)
  18. import os, sys
  19. from PyQt4.QtCore import qWarning, SIGNAL, SLOT
  20. from PyQt4.QtGui import QIcon, QMessageBox, QFileDialog
  21. # Set Platform
  22. if ("linux" in sys.platform):
  23. LINUX = True
  24. WINDOWS = False
  25. elif ("win" in sys.platform):
  26. LINUX = False
  27. WINDOWS = True
  28. else:
  29. LINUX = False
  30. WINDOWS = False
  31. if (WINDOWS == False):
  32. from signal import signal, SIGINT, SIGTERM, SIGUSR1, SIGUSR2
  33. # Set Version
  34. VERSION = "0.5.0"
  35. # Set Debug mode
  36. DEBUG = False
  37. # Small integrity tests
  38. HOME = os.getenv("HOME")
  39. if (HOME == None):
  40. qWarning("HOME variable not set")
  41. HOME = "/tmp"
  42. elif (os.path.exists(HOME) == False):
  43. qWarning("HOME variable set but not valid")
  44. HOME = "/tmp"
  45. PATH_env = os.getenv("PATH")
  46. if (PATH_env == None):
  47. qWarning("PATH variable not set")
  48. PATH = ("/bin", "/sbin", "/usr/local/bin", "/usr/local/sbin", "/usr/bin", "/usr/sbin", "/usr/games")
  49. else:
  50. PATH = PATH_env.split(os.pathsep)
  51. del PATH_env
  52. # Get Icon from user theme, using our own as backup (Oxygen)
  53. def getIcon(icon, size=16):
  54. return QIcon.fromTheme(icon, QIcon(":/%ix%i/%s.png" % (size, size, icon)))
  55. # QLineEdit and QPushButtom combo
  56. def getAndSetPath(self, currentPath, lineEdit):
  57. newPath = QFileDialog.getExistingDirectory(self, self.tr("Set Path"), currentPath, QFileDialog.ShowDirsOnly)
  58. if (newPath):
  59. lineEdit.setText(newPath)
  60. return newPath
  61. # Custom MessageBox
  62. def CustomMessageBox(self, icon, title, text, extra_text="", buttons=QMessageBox.Yes|QMessageBox.No, defButton=QMessageBox.No):
  63. msgBox = QMessageBox(self)
  64. msgBox.setIcon(icon)
  65. msgBox.setWindowTitle(title)
  66. msgBox.setText(text)
  67. msgBox.setInformativeText(extra_text)
  68. msgBox.setStandardButtons(buttons)
  69. msgBox.setDefaultButton(defButton)
  70. return msgBox.exec_()
  71. # signal handler for unix systems
  72. def set_up_signals(_gui):
  73. if (WINDOWS == False):
  74. from signal import signal, SIGINT, SIGTERM, SIGUSR1, SIGUSR2
  75. global x_gui
  76. x_gui = _gui
  77. signal(SIGINT, signal_handler)
  78. signal(SIGTERM, signal_handler)
  79. signal(SIGUSR1, signal_handler)
  80. signal(SIGUSR2, signal_handler)
  81. x_gui.connect(x_gui, SIGNAL("SIGUSR2()"), lambda gui=x_gui: showWindow(gui))
  82. x_gui.connect(x_gui, SIGNAL("SIGTERM()"), SLOT("close()"))
  83. def signal_handler(sig=0, frame=0):
  84. global x_gui
  85. if (sig in (SIGINT, SIGTERM)):
  86. x_gui.emit(SIGNAL("SIGTERM()"))
  87. elif (sig == SIGUSR1):
  88. x_gui.emit(SIGNAL("SIGUSR1()"))
  89. elif (sig == SIGUSR2):
  90. x_gui.emit(SIGNAL("SIGUSR2()"))
  91. def showWindow(self):
  92. if (self.isMaximized()):
  93. self.showMaximized()
  94. else:
  95. self.showNormal()