coding utf-8 from PyQt4 import QtGui from PaintWindow import PaintWind

  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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# coding: utf-8
from PyQt4 import QtGui
from PaintWindow import PaintWindow
from tetris import Board
from PyQt4.QtCore import Qt
import icons_rc
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setGeometry(0,0,800,600)
self.createActions()
self.createMenus()
self.createToolBars()
self.createStatusBar()
self.paintWindow = PaintWindow(self)
self.setCentralWidget(self.paintWindow)
self.tetrisBoard = Board(self)
self.tetris = QtGui.QDockWidget(self.tr("Tetris"))
self.tetris.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
self.tetris.setWidget(self.tetrisBoard)
self.addDockWidget(Qt.RightDockWidgetArea, self.tetris)
self.tetrisBoard.start()
self.center()
def center(self):
screen = QtGui.QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width() - size.width()) / 2,
(screen.height() - size.height()) / 2)
def startTetris(self):
self.tetris.close()
def createActions(self):
self.penAct = QtGui.QAction(QtGui.QIcon(":/rc/icons/pencil_48.png"), self.tr("Pen"), self)
self.penAct.setStatusTip(self.tr("Pen"))
self.penAct.setCheckable(True)
self.newAct = QtGui.QAction(QtGui.QIcon(":/images/new.png"),
self.tr("&New"), self)
self.newAct.setShortcut(QtGui.QKeySequence.New)
self.newAct.setStatusTip(self.tr("Create a new file"))
# self.newAct.triggered.connect(self.newFile)
self.newAct.triggered.connect(self.startTetris)
self.openAct = QtGui.QAction(QtGui.QIcon(":/images/open.png"),
self.tr("&Open..."), self)
self.openAct.setShortcut(QtGui.QKeySequence.Open)
self.openAct.setStatusTip(self.tr("Open an existing file"))
# self.openAct.triggered.connect(self.open)
self.saveAct = QtGui.QAction(QtGui.QIcon(":/images/save.png"),
self.tr("&Save"), self)
self.saveAct.setShortcut(QtGui.QKeySequence.Save)
self.saveAct.setStatusTip(self.tr("Save the document to disk"))
# self.saveAct.triggered.connect(self.save)
self.saveAsAct = QtGui.QAction(self.tr("Save &As..."), self)
self.saveAsAct.setShortcut(QtGui.QKeySequence.SaveAs)
self.saveAsAct.setStatusTip(self.tr("Save the document under a new name"))
# self.saveAsAct.triggered.connect(self.saveAs)
self.exitAct = QtGui.QAction(self.tr("E&xit"), self)
self.exitAct.setShortcut(self.tr("Ctrl+Q"))
self.exitAct.setStatusTip(self.tr("Exit the application"))
self.exitAct.triggered.connect(self.close)
self.cutAct = QtGui.QAction(QtGui.QIcon(":/images/cut.png"),
self.tr("Cu&t"), self)
self.cutAct.setShortcut(QtGui.QKeySequence.Cut)
self.cutAct.setStatusTip(self.tr("Cut the current selection's "
"contents to the clipboard"))
# self.cutAct.triggered.connect(self.textEdit.cut)
self.copyAct = QtGui.QAction(QtGui.QIcon(":/images/copy.png"),
self.tr("&Copy"), self)
self.copyAct.setShortcut(QtGui.QKeySequence.Copy)
self.copyAct.setStatusTip(self.tr("Copy the current selection's "
"contents to the clipboard"))
# self.copyAct.triggered.connect(self.textEdit.copy)
self.pasteAct = QtGui.QAction(QtGui.QIcon(":/images/paste.png"),
self.tr("&Paste"), self)
self.pasteAct.setShortcut(QtGui.QKeySequence.Paste)
self.pasteAct.setStatusTip(self.tr("Paste the clipboard's contents "
"into the current selection"))
# self.pasteAct.triggered.connect(self.textEdit.paste)
self.aboutAct = QtGui.QAction(self.tr("&About"), self)
self.aboutAct.setStatusTip(self.tr("Show the application's About box"))
# self.aboutAct.triggered.connect(self.about)
self.aboutQtAct = QtGui.QAction(self.tr("About &Qt"), self)
self.aboutQtAct.setStatusTip(self.tr("Show the Qt library's About box"))
# self.aboutQtAct.triggered.connect(QtGui.qApp.aboutQt)
self.cutAct.setEnabled(False)
self.copyAct.setEnabled(False)
# self.textEdit.copyAvailable.connect(self.cutAct.setEnabled)
# self.textEdit.copyAvailable.connect(self.copyAct.setEnabled)
def createStatusBar(self):
self.statusBar().showMessage(self.tr("Ready"))
def createToolBars(self):
self.fileToolBar = self.addToolBar(self.tr("File"))
self.fileToolBar.addAction(self.newAct)
self.fileToolBar.addAction(self.openAct)
self.fileToolBar.addAction(self.saveAct)
self.editToolBar = self.addToolBar(self.tr("Edit"))
self.editToolBar.addAction(self.cutAct)
self.editToolBar.addAction(self.copyAct)
self.editToolBar.addAction(self.pasteAct)
def createMenus(self):
self.fileMenu = self.menuBar().addMenu(self.tr("&File"))
self.fileMenu.addAction(self.newAct)
self.fileMenu.addAction(self.openAct)
self.fileMenu.addAction(self.saveAct)
self.fileMenu.addAction(self.saveAsAct)
self.fileMenu.addSeparator();
self.fileMenu.addAction(self.exitAct)
self.editMenu = self.menuBar().addMenu(self.tr("&Edit"))
self.editMenu.addAction(self.cutAct)
self.editMenu.addAction(self.copyAct)
self.editMenu.addAction(self.pasteAct)
self.menuBar().addSeparator()
self.helpMenu = self.menuBar().addMenu(self.tr("&Help"))
self.helpMenu.addAction(self.aboutAct)
self.helpMenu.addAction(self.aboutQtAct)