aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/pyqt.rb
blob: bc4888e9a5d38e41eaadf17d381e5c472a3a99c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'formula'

# Note: this project doesn't save old releases, so it breaks often as
# downloads disappear.

class Pyqt < Formula
  homepage 'http://www.riverbankcomputing.co.uk/software/pyqt'
  url 'http://www.riverbankcomputing.co.uk/static/Downloads/PyQt4/PyQt-mac-gpl-4.9.4.tar.gz'
  sha1 '3fe827fed91ec710746fa980f433313dfec2d5fd'

  depends_on 'sip'
  depends_on 'qt'

  def install
    ENV.prepend 'PYTHONPATH', "#{HOMEBREW_PREFIX}/lib/#{which_python}/site-packages", ':'

    system "python", "./configure.py", "--confirm-license",
                                       "--bindir=#{bin}",
                                       "--destdir=#{lib}/#{which_python}/site-packages",
                                       "--sipdir=#{share}/sip"
    system "make"
    system "make install"
  end

  def caveats; <<-EOS.undent
    For non-homebrew Python, you need to amend your PYTHONPATH like so:
      export PYTHONPATH=#{HOMEBREW_PREFIX}/lib/#{which_python}/site-packages:$PYTHONPATH
    EOS
  end

  def which_python
    "python" + `python -c 'import sys;print(sys.version[:3])'`.strip
  end

  def test
    # Reference: http://zetcode.com/tutorials/pyqt4/firstprograms/
    mktemp do
      ENV.prepend 'PYTHONPATH', "#{HOMEBREW_PREFIX}/lib/#{which_python}/site-packages", ':'

      (Pathname.pwd/'test.py').write <<-EOS.undent
        #!/usr/bin/env python

        import sys
        from PyQt4 import QtGui, QtCore

        class QuitButton(QtGui.QWidget):
            def __init__(self, parent=None):
                QtGui.QWidget.__init__(self, parent)

                self.setGeometry(300, 300, 250, 150)
                self.setWindowTitle('Quit button')

                quit = QtGui.QPushButton('Close', self)
                quit.setGeometry(10, 10, 60, 35)

                self.connect(quit, QtCore.SIGNAL('clicked()'),
                    QtGui.qApp, QtCore.SLOT('quit()'))

        app = QtGui.QApplication(sys.argv)
        qb = QuitButton()
        qb.show()
        app.exec_()
        sys.exit(0)
        EOS

      system "python", "test.py"
    end
  end
end