-
Notifications
You must be signed in to change notification settings - Fork 1
/
getrandomticket.py
executable file
·69 lines (55 loc) · 1.96 KB
/
getrandomticket.py
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
#!/usr/bin/env python3
# -'''- coding: utf-8 -'''-
import sys
import subprocess
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtDeclarative import *
import PIL
import PIL.Image
import sqlite3
import random
from time import sleep
import os
os.chdir(os.path.dirname(os.path.realpath(__file__)))
class MyHandler(QObject):
def __init__(self, window, app, *args, **kwargs):
QObject.__init__(self, *args, **kwargs)
self.window = window
self.app = app
self.conn = sqlite3.connect('badges.db')
c = self.conn.cursor()
c.execute(""" CREATE TABLE IF NOT EXISTS badges (created datetime, name text, twitter text, ticket text) """)
self.conn.commit()
c = self.conn.cursor()
c.execute(""" SELECT name, ticket FROM badges ORDER BY random()""")
self.winners = c.fetchall()
@Slot()
def shuffle(self):
if len(self.winners) == 0:
name = "(Ende!)"
ticket = ""
else:
name, ticket = self.winners.pop()
window.rootContext().setContextProperty("latestWinnerName", name);
window.rootContext().setContextProperty("latestWinnerTicket", ticket);
# Our main window
class MainWindow(QDeclarativeView):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setWindowTitle("Main Window")
# Renders 'view.qml'
self.setSource(QUrl.fromLocalFile('getrandomticket.qml'))
# QML resizes to main window
self.setResizeMode(QDeclarativeView.SizeRootObjectToView)
if __name__ == '__main__':
# Create the Qt Application
app = QApplication(sys.argv)
# Create and show the main window
window = MainWindow()
window.setWindowFlags(Qt.FramelessWindowHint)
handler = MyHandler(window, app)
window.rootContext().setContextProperty("handler", handler)
window.showFullScreen()
# Run the main Qt loop
sys.exit(app.exec_())