Skip to content

Instantly share code, notes, and snippets.

@niner
Created January 1, 2015 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niner/e5a2f324824fcd453ef0 to your computer and use it in GitHub Desktop.
Save niner/e5a2f324824fcd453ef0 to your computer and use it in GitHub Desktop.
#!/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