Пример #1
0
 def initUI(self):
     '''
     Init main window UI
     
     '''
     
     central = QtGui.QWidget(self)
     grid = QtGui.QGridLayout(central)
     
     # Setup System Tray Icon
     self.tray = Tray(self)
     self.tray.display(False)
     
     # Set App Icon
     self.initIcon()
     
     # Menubar
     menuBar = self.createAppMenuBar()
     self.setMenuBar(menuBar)
     
     # Connected List
     connectLabel = QtGui.QLabel("Connected Devices:")
     grid.addWidget(connectLabel, 0, 0)
     
     self.connectList = ConnectList()
     grid.addWidget(self.connectList, 1, 0, 2, 1)
     
     # Pairing Helper Button
     pairHelper = QtGui.QPushButton()
     pairHelper.setText("Pair")
     pairHelper.clicked.connect(self.loadPairing)
     grid.addWidget(pairHelper, 4, 0)
     
     central.setLayout(grid)
     
     self.setCentralWidget(central)
     self.setGeometry(300, 300, 250, 100)
     self.setWindowTitle("Droid Navi")
     
     
     self.notifyHandler = NotifyHandler()
     self.show()
     self.raise_()
     self.activateWindow()
Пример #2
0
from components.ball import Ball
from components.game_bar import GameBar, EndGameBar
from components.tray import Tray

# points to win
max_points = 10

game_window = turtle.Screen()
game_window.title('PONG GAME')
game_window.bgcolor(0, 0, 0)
game_window.setup(width=800, height=600)
game_window.tracer(0)

# tray
tray_left = Tray('yellow', -350)
tray_right = Tray('blue', 350)

# ball
ball = Ball()

# status bar
bar = GameBar()

# keyboard moves tracking
game_window.listen()
game_window.onkeypress(tray_left.move_up, 'w')
game_window.onkeypress(tray_left.move_down, 's')
game_window.onkeypress(tray_right.move_up, 'Up')
game_window.onkeypress(tray_right.move_down, 'Down')
Пример #3
0
class MainWindow(QtGui.QMainWindow):
    
    receiveEvent = QtCore.pyqtSignal(object)
    
    def __init__(self, gateway):
        '''
        Constructor
        '''

        super(MainWindow,self).__init__();
        
        self.__gateway = gateway
        
        self.initUI()        
        self.initCallback(self.onEvent)
        self.initEventType()
        
    def initUI(self):
        '''
        Init main window UI
        
        '''
        
        central = QtGui.QWidget(self)
        grid = QtGui.QGridLayout(central)
        
        # Setup System Tray Icon
        self.tray = Tray(self)
        self.tray.display(False)
        
        # Set App Icon
        self.initIcon()
        
        # Menubar
        menuBar = self.createAppMenuBar()
        self.setMenuBar(menuBar)
        
        # Connected List
        connectLabel = QtGui.QLabel("Connected Devices:")
        grid.addWidget(connectLabel, 0, 0)
        
        self.connectList = ConnectList()
        grid.addWidget(self.connectList, 1, 0, 2, 1)
        
        # Pairing Helper Button
        pairHelper = QtGui.QPushButton()
        pairHelper.setText("Pair")
        pairHelper.clicked.connect(self.loadPairing)
        grid.addWidget(pairHelper, 4, 0)
        
        central.setLayout(grid)
        
        self.setCentralWidget(central)
        self.setGeometry(300, 300, 250, 100)
        self.setWindowTitle("Droid Navi")
        
        
        self.notifyHandler = NotifyHandler()
        self.show()
        self.raise_()
        self.activateWindow()
    
    def createAppMenuBar(self):
        '''
        Build the main window's Menu bar and return it
        
        '''
        
        menuBar = self.menuBar()
        fileMenu = menuBar.addMenu("&File")
        
        settingsAction = QtGui.QAction("&Options", self)
        settingsAction.setToolTip('Open program options')
        settingsAction.triggered.connect(lambda: self.openSettings(self))
        fileMenu.addAction(settingsAction)
        
        quitAction = QtGui.QAction("&Quit", self)
        quitAction.setToolTip("Quit program")
        quitAction.triggered.connect(self.close)
        fileMenu.addAction(quitAction)
        
        helpMenu = menuBar.addMenu("&Help")
        
        aboutActions = QtGui.QAction("&About", self)
        aboutActions.setToolTip("Show About dialog")
        aboutActions.triggered.connect(self.openAbout)
        helpMenu.addAction(aboutActions)
        
        return menuBar
        
    
    def initCallback(self, func):
        '''
        Setup the callback with the Java side
        
        '''
        
        # Hookup Signal
        self.receiveEvent.connect(self.handleEvent)
        
        self.callback = EventListener()
        self.callback.onEvent = self.onEvent
        try:
            self.__gateway.entry_point.addEventListener(self.callback)
        except:
            # Attempt 2
            QtCore.QThread.sleep(1)
            try:
                self.__gateway.entry_point.addEventListener(self.callback)
            except:
                info = QtGui.QMessageBox()
                info.setText("Error setting up event callback. Exiting.")
                info.exec_()
                self.callback = None
                self.close()
    
    def initIcon(self):
        icon = AppIcon.getAppIcon()
        if icon:
            self.setWindowIcon(icon)
    
    def openAbout(self):
        '''
        Show the About dialog
        
        '''
        
        aboutDialog = AboutDialog()
        aboutDialog.exec_()
    
    @QtCore.pyqtSlot()
    def openSettings(self, parent=None):
        '''
        Show the Settings Dialog
        
        '''
        settingsDialog = SettingsDialog(parent)
        if parent:
            settingsDialog.exec_()
        else:
            self.settingsDialog = settingsDialog
            self.settingsDialog.show()
        pass
    
    def loadPairing(self):
        '''
        Show the pairing helper dialog
        
        '''
        
        pairingDialog = PairingDialog(self)
        pairingDialog.exec_()
        pass
    
    def initEventType(self):
        '''
        Setup a mock Enum style EventType for this instance.
        
        This is needed for interpreting events received from the Java server.
        
        '''
        
        self.EventType = EventType(self.__gateway)
    
    def displayEvent(self, event):
        self.editArea.append(event.toString())
    
    def onEvent(self, event):
        event.EventType = self.EventType
        
        self.receiveEvent.emit(event)
        
    def handleEvent(self, event):
      
        # Add/Remove on [Diss]Connect events
        if event.getEventType() == event.EventType.CLIENT_CONNECT:
            device = event.getDevice()
            if device:
                self.connectList.addDevice(device)
            pass
        elif event.getEventType() == event.EventType.SHUTDOWN:
            device = event.getDevice()
            if device:
                self.connectList.removeDevice(device) 
            pass
        
        # Check whether to display notification
        settingsData = SettingsData.fromPickle()
        if settingsData.shouldDisplayEvent(event):
            self.notifyHandler.queueEvent(event)
        
    
    def changeEvent(self, event):
        super(MainWindow, self).changeEvent(event)
        if type(event) is QtGui.QWindowStateChangeEvent:
            if self.isMinimized():
                QtCore.QTimer.singleShot(0, partial(self.minimizeToTray))
                event.ignore()
    
    def maximizeFromTray(self):
        self.show()
        self.raise_()
        self.activateWindow()
    
    def minimizeToTray(self):
        self.hide()
        self.tray.display(True)
        
    def closeEvent(self, event):
        if self.callback:
            self.__gateway.entry_point.removeEventListener(self.callback)
        if type(event) is bool:
            pass
        else:
            event.accept()