Created
January 1, 2015 17:18
-
-
Save niner/435171022bb1dbff35a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
use v6; | |
use Inline::Python; | |
use Test; | |
BEGIN my $py = Inline::Python.new(); | |
BEGIN $py.run(' | |
import PyQt4 | |
import PyQt4.QtCore | |
import PyQt4.QtGui | |
'); | |
class MessageBox does Inline::Python::PythonParent[$py, 'PyQt4.QtGui', 'QWidget'] { | |
method setup() { | |
self.resize(250, 150); | |
self.setWindowTitle('message box'); | |
self.show(); | |
self.center(); | |
} | |
method closeEvent($event) { | |
my $reply = $py.invoke( | |
'PyQt4.QtGui', | |
'QMessageBox', | |
'question', | |
$.parent, | |
'Message', | |
'Are you sure to quit?', | |
0x00004000, | |
0x00010000, | |
); | |
if $reply == 0x00004000 { | |
$event.accept(); | |
} | |
else { | |
$event.ignore(); | |
} | |
} | |
method mousePressEvent($event) { | |
$event.accept; | |
} | |
method center() { | |
my $qr = self.frameGeometry(); | |
my $cp = $py.call('PyQt4.QtGui', 'QDesktopWidget').availableGeometry().center(); | |
$qr.moveCenter($cp); | |
self.move($qr.topLeft()); | |
} | |
} | |
sub SIGNAL(Str $signal) { | |
return $py.call('PyQt4.QtCore', 'SIGNAL', $signal); | |
} | |
sub SLOT(Str $slot) { | |
return $py.call('PyQt4.QtCore', 'SLOT', $slot); | |
} | |
ok(my $app = $py.call('PyQt4.QtGui', 'QApplication', ['pyqt4.t'])); | |
my $message_box = MessageBox.new(); | |
$message_box.setup(); | |
is($app.exec_, 0); | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment