Ejemplo n.º 1
0
Archivo: gui.py Proyecto: mSok/snake
 def __init__(self):
     super(Snake, self).__init__()
     self.initUI()
     self.snakeArray = list(START_POS)
     self.snakeSize = 12
     self.timer = QtCore.QBasicTimer()
     self.newGame()
Ejemplo n.º 2
0
    def __init__(self):
        super().__init__()
        self.setStyleSheet("QWidget { background-color: black }")
        self.setFixedSize(Snake.BOARD_WIDTH, Snake.BOARD_HEIGHT)
        self.game_active = True
        self.timer = QtCore.QBasicTimer()
        self.direction = Snake.RIGHT
        # each tuple (x, y) corresponds to the top left corner of the block (circle)
        self.snake_coords = deque()
        self.snake_coords.append((Snake.BLOCK_SIZE * Snake.NUM_BLOCKS_X // 2,
                                  Snake.BLOCK_SIZE * Snake.NUM_BLOCKS_Y // 2))
        self.food = None
        self.new_food()

        self.score_sound = QtMultimedia.QSound("score.wav")

        self.start_button = QtWidgets.QPushButton("Start", self)
        self.start_button.setStyleSheet("QWidget { background-color: white }")
        self.start_button.move(self.geometry().center() - self.start_button.geometry().center())
        self.start_button.clicked.connect(self.start_game)
        self.game_over_label = QtWidgets.QLabel("Game Over...", self)
        self.game_over_label.setStyleSheet("QLabel {color: yellow; font: 36pt}")
        self.game_over_label.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        self.game_over_label.adjustSize()
        self.game_over_label.move((self.width() - self.game_over_label.width()) // 2, 0)
        self.game_over_label.hide()

        self.setWindowTitle("Snake game")
        self.show()
Ejemplo n.º 3
0
    def __init__(self, global_config, connection):
        super(PiHud, self).__init__()

        self.global_config = global_config
        self.connection = connection

        # ================= Color Palette =================

        palette = self.palette()
        palette.setColor(self.backgroundRole(), QtCore.Qt.black)
        self.setPalette(palette)

        # ================== Init Pages ===================

        self.stack = QtWidgets.QStackedWidget(self)
        self.setCentralWidget(self.stack)

        # read the config and make pages
        for configs in global_config["pages"]:
            self.__add_existing_page(configs)

        # ===================== Start =====================

        self.timer = QtCore.QBasicTimer()
        self.setWindowTitle("PiHud")
        self.showFullScreen()

        self.start()
Ejemplo n.º 4
0
 def __init__(self, parent=None):
     super(TetrixBoard, self).__init__(parent)
     Board.__init__(self)
     self.isPaused = False
     self.curPiece = None
     self.timer = QtCore.QBasicTimer()
     self.setFrameStyle(QtWidgets.QFrame.Panel | QtWidgets.QFrame.Sunken)
     self.setFocusPolicy(QtCore.Qt.StrongFocus)
     self.isWaitingNextPiece = True
Ejemplo n.º 5
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.empty = True
        self.emptying = False
        self.shapes = []
        self.timer = QtCore.QBasicTimer()

        self.enableUpdates()

        self.setBackgroundRole(QtGui.QPalette.Base)
        self.setMouseTracking(True)
Ejemplo n.º 6
0
 def __init__(self, image_files, parent=None):
     QWidget.__init__(self, parent)
     self.image_files = image_files
     s = '<>'*300
     self.label = QtGui.QLabel(s, self)
     self.label.setGeometry(10, 30, 640, 480)
     self.button = QtGui.QPushButton("Start Slide Show",self)
     self.button.setGeometry(10, 10, 140, 30)
     self.button.clicked.connect(self.timerEvent)
     self.timer = QtCore.QBasicTimer()
     self.step = 0
     self.delay = 5000  # milliseconds
     sf = "Slides are shown {} seconds apart"
     self.setWindowTitle(sf.format(self.delay/1000.0))
Ejemplo n.º 7
0
    def initUI(self):      

        self.pbar = QtWidgets.QProgressBar(self)
        self.pbar.setGeometry(30, 40, 200, 25)

        self.btn = QtWidgets.QPushButton('Start', self)
        self.btn.move(40, 80)
        self.btn.clicked.connect(self.doAction)

        self.timer = QtCore.QBasicTimer()
        self.step = 0
        
        self.setGeometry(300, 300, 280, 170)
        self.setWindowTitle('QtWidgets.QProgressBar')
        self.show()
Ejemplo n.º 8
0
    def __init__(self, parent=None):
        super(WigglyWidget, self).__init__(parent)

        self.setBackgroundRole(QtGui.QPalette.Midlight)
        self.setAutoFillBackground(True)

        newFont = self.font()
        newFont.setPointSize(newFont.pointSize() + 20)
        self.setFont(newFont)

        self.timer = QtCore.QBasicTimer()
        self.text = ''

        self.step = 0;
        self.timer.start(60, self)   
Ejemplo n.º 9
0
    def __init__(self, parent):
        super(Board, self).__init__(parent)
        self.setFixedSize(Board.width * Board.block_size,
                          Board.height * Board.block_size)
        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        self.timer = QtCore.QBasicTimer()
        self.paint_event = 0
        self.timer_event = 0

        self.x = 0
        self.y = 0
        self.current_piece = Piece()
        # self.next_piece = Piece()

        self.msg = Communicate()
Ejemplo n.º 10
0
    def __init__(self, parent=None):
        super(MultiCacheMonitor, self).__init__(parent, QtCore.Qt.Window)
        self.setWindowTitle(WINDOW_TITLE)
        self.comparators = []
        self.contact_sheet = []
        self.tab_widget = QtWidgets.QTabWidget()
        self.tab_widget.setTabsClosable(True)
        self.tab_widget.tabCloseRequested.connect(self.tab_closed)
        self.job_panels = []

        self.layout = QtWidgets.QHBoxLayout(self)
        self.layout.setContentsMargins(2, 2, 2, 2)
        self.layout.addWidget(self.tab_widget)

        self.timer = QtCore.QBasicTimer()
        self.updater = wooden_legged_centipede(24)
Ejemplo n.º 11
0
    def __init__(self, names=None, pixmap_lists=None, parent=None):
        super(ContactSheetImagesReader, self).__init__(parent, QtCore.Qt.Tool)
        self.setWindowTitle(CONTACTSHEET_TITLE)
        self.isplaying = False
        self.names = names
        self.pixmap_lists = pixmap_lists
        self.imageviewers = [ImageViewer(name=name) for name in self.names]

        self.timer = QtCore.QBasicTimer()

        self.slider = Slider()
        self.slider.minimum = 0
        self.slider.maximum = len(self.pixmap_lists[0])
        self.slider.maximum_settable_value = self.slider.maximum
        self.slider.value = self.slider.minimum
        self.slider.valueChanged.connect(self._call_slider_value_changed)
        self.playstop = QtWidgets.QPushButton("Play")
        self.playstop.released.connect(self._call_playstop)
        self.export = QtWidgets.QPushButton("Export")
        self.export.released.connect(self._call_export)

        self.buttons_layout = QtWidgets.QHBoxLayout()
        self.buttons_layout.setContentsMargins(0, 0, 0, 0)
        self.buttons_layout.setSpacing(0)
        self.buttons_layout.addWidget(self.playstop)
        self.buttons_layout.addWidget(self.export)
        # set the grid dlayout under a dummy widget to allow widget.grabWindow
        # to export a video
        self.grid_widget = QtWidgets.QWidget()
        self.grid_layout = QtWidgets.QGridLayout(self.grid_widget)
        row = 0
        column = 0
        column_lenght = ceil(sqrt(len(self.imageviewers)))
        for imageviewer in self.imageviewers:
            self.grid_layout.addWidget(imageviewer, row, column)
            column += 1
            if column >= column_lenght:
                column = 0
                row += 1

        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(0)
        self.layout.addWidget(self.grid_widget)
        self.layout.addSpacing(4)
        self.layout.addWidget(self.slider)
        self.layout.addLayout(self.buttons_layout)
Ejemplo n.º 12
0
    def __init__(self, parent):
        super(WelcomeScreen1, self).__init__(parent)
        self.size_factor = 1
        self.high_contrast = False
        self.alignment = 'cr'
        self.color_index = 0
        self.in_focus = True

        # mainwindow.setWindowIcon(QtGui.QIcon('PhotoIcon.png'))

        vbox = QtWidgets.QVBoxLayout()

        hbox = QtWidgets.QHBoxLayout()

        self.loading_clock = OldClockWidget('a', self)
        self.loading_clock.highlighted = True
        self.loading_clock.setMinimumSize(200, 200)

        self.timer = QtCore.QBasicTimer()
        self.timer.start(15, self)
        self.step = 0

        self.sub_label_1 = QtWidgets.QLabel(
            "To select an option, find the adjacent clock and press when the moving hand "
            "is near Noon.")
        self.sub_label_2 = QtWidgets.QLabel("<i>(press to continue)</i>")

        self.sub_label_1.setWordWrap(True)
        loading_label = QtWidgets.QLabel(
            "<b>Welcome to the Nomon SimulatedUser!</b>")
        loading_label.setFont(config.welcome_main_font[1])

        self.sub_label_1.setFont(config.welcome_sub_font[1])
        self.sub_label_2.setFont(config.welcome_sub_font[1])

        hbox.addStretch(1)
        hbox.addWidget(self.loading_clock, 2)
        hbox.addStretch(1)
        vbox.addWidget(loading_label)
        vbox.addLayout(hbox)
        vbox.addStretch(1)
        vbox.addWidget(self.sub_label_1, 1)
        vbox.addWidget(self.sub_label_2, 1, QtCore.Qt.AlignRight)

        self.setLayout(vbox)
Ejemplo n.º 13
0
    def __init__(self, pixmaps1, pixmaps2, frames, names=None, parent=None):
        super(SequenceStackedImagesReader,
              self).__init__(parent, QtCore.Qt.Tool)
        self.setWindowTitle(COMPARATOR_TITLE)
        self.isplaying = False
        self.pixmaps1 = pixmaps1
        self.pixmaps2 = pixmaps2
        self.names = [n for n in map(str, frames)]

        self.timer = QtCore.QBasicTimer()

        self.stacked_imagesview = StackedImagesViewer(names, self)
        pixmap1, pixmap2 = self.pixmaps1[0], self.pixmaps2[0]
        self.stacked_imagesview.set_pixmaps(pixmap1, pixmap2)
        self.stacked_imagesview.name = self.names[0]
        # find the first pixmap which is not None and use is as reference size
        for pixmap in pixmaps1 + pixmaps2:
            if pixmap:
                self.stacked_imagesview.setFixedSize(pixmap.size())
        self.stacked_imagesview.update_geometries()
        self.slider = Slider()
        self.slider.minimum = 0
        self.slider.maximum = len(self.pixmaps1)
        self.slider.maximum_settable_value = self.slider.maximum
        self.slider.value = self.slider.minimum
        self.slider.valueChanged.connect(self._call_slider_value_changed)

        self.blender = QtWidgets.QSlider(QtCore.Qt.Horizontal)
        self.blender.setMinimum(0)
        self.blender.setMaximum(100)
        self.blender.setTickInterval(1)
        self.blender.setSliderPosition(100)
        self.blender.valueChanged.connect(self._call_blender_value_changed)

        self.playstop = QtWidgets.QPushButton("Play")
        self.playstop.released.connect(self._call_playstop)

        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(0)
        self.layout.addWidget(self.stacked_imagesview)
        self.layout.addWidget(self.slider)
        self.layout.addWidget(self.blender)
        self.layout.addWidget(self.playstop)
Ejemplo n.º 14
0
    def newGame(self):
        self.score = 0
        self.x = self.tileWidth
        self.y = self.tileHeight * 3
        self.timer = QtCore.QBasicTimer()
        self.snakeArray = [
            [self.x, self.y],
            [self.x - self.tileWidth, self.y],
            [self.x - self.tileHeight, self.y],
        ]
        self.foodx = 0
        self.foody = 0

        self.isPaused = False
        self.isOver = False
        self.FoodPlaced = False
        if self.human:
            self.speed = 100
        else:
            self.speed = 1
        self.start()
Ejemplo n.º 15
0
    def __init__(self, parent=None):
        super(TetrixBoard, self).__init__(parent)

        self.timer = QtCore.QBasicTimer()
        self.nextPieceLabel = None
        self.isWaitingAfterLine = False
        self.curPiece = TetrixPiece()
        self.nextPiece = TetrixPiece()
        self.curX = 0
        self.curY = 0
        self.numLinesRemoved = 0
        self.numPiecesDropped = 0
        self.score = 0
        self.level = 0
        self.board = None

        self.setFrameStyle(QtWidgets.QFrame.Panel | QtWidgets.QFrame.Sunken)
        self.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.isStarted = False
        self.isPaused = False
        self.clearBoard()

        self.nextPiece.setRandomShape()
Ejemplo n.º 16
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self.camera_port = 0
     self.camera = cv.VideoCapture(self.camera_port)
     self.timer = QtCore.QBasicTimer()