View difference between Paste ID: 48y7nqc2 and d8eq19Fz
SHOW: | | - or go back to the newest paste.
1
from PySide import QtCore, QtGui
2
3
class TestWidget(QtGui.QWidget):
4
  """
5
  A simple Pie menu class. Use in a similar way to QMenu: Create a PieMenu and add QActions to it with QAction.
6
  """
7
8
  def __init__(self, parent=None):
9
    super(TestWidget, self).__init__(parent)
10
11
    # with this flag set the application does not quit properly, without it does
12-
    self.setWindowFlags(QtCore.Qt.Popup)
12+
    self.setWindowFlags(QtCore.Qt.Tool)
13
14
  def mousePressEvent(self, e):
15-
    self.close()
15+
    self.close() # this closes the widget but does not quit the application
16
    app = QtGui.QApplication.instance()
17-
  def keyPressEvent(self, event):
17+
    if True: # what logic can I use to figure out if this is a standalone app or run from a host applicatin?
18-
    if event.key() == QtCore.Qt.Key_Escape:
18+
      app.quit()
19-
      self.close()
19+
20
21
if __name__ == '__main__':
22
  import sys
23
  app = QtGui.QApplication(sys.argv)
24
  w = TestWidget()
25
  w.show()
26
  sys.exit(app.exec_())