Ejemplo n.º 1
0
class LeapCrispyCursor:
    CURSOR_CHOICES = {
        'path': CrispyPathCursor,
        'pitch': CrispyPitchCursor,
    }

    def __init__(self, parsed_args, *args, **kwargs):
        self.parsed_args = parsed_args

        # Create a Leap controller and a listener
        self.controller = Controller()
        self.listener = self.CURSOR_CHOICES[self.parsed_args.mode]()

        self.listener.click_timeout = self.parsed_args.click
        self.listener.press_timeout = self.parsed_args.press

    def run(self):
        self.controller.add_listener(self.listener)

        try:
            while True:
                time.sleep(1000)
        except KeyboardInterrupt:
            pass
        finally:
            self.controller.remove_listener(self.listener)
            showmessage("Removing listener", Status.SUCCESS, Colors.GREEN)
            print ""
Ejemplo n.º 2
0
    def __init__(self, parsed_args, *args, **kwargs):
        self.parsed_args = parsed_args

        # Create a Leap controller and a listener
        self.controller = Controller()
        self.listener = self.CURSOR_CHOICES[self.parsed_args.mode]()

        self.listener.click_timeout = self.parsed_args.click
        self.listener.press_timeout = self.parsed_args.press
Ejemplo n.º 3
0
class Bounces(Application):
    def __init__(self, parser, rate):
        Application.__init__(self, parser)
        self.balls = []
        self.rate = Rate(rate)

        def rand():
            return choice([-1, 1]) * uniform(1. / rate, 10. / rate)

        for ball in range(4):
            self.balls.append(
                Ball(ball, randint(0, self.height - 1),
                     randint(0, self.width - 1), self.height, self.width,
                     Ball.colors[ball % len(Ball.colors)], rand(), rand()))

        # Motion control via Leap Motion
        self.swipe = [None]
        self.swipe_lock = RLock()

        if leapmotion:
            self.leap_listener = SampleListener(self.swipe, self.swipe_lock)
            self.controller = Controller()
            self.controller.add_listener(self.leap_listener)

    def close(self, reason='unknown'):
        Application.close(self, reason)
        if leapmotion:
            self.controller.remove_listener(self.leap_listener)

    def render(self):
        with self.model:
            self.model.set_all('black')
            with self.swipe_lock:
                for ball in self.balls:
                    self.model.set_pixel(ball.x, ball.y, ball.color)
                    if self.swipe[0] is not None:
                        # mapping axes (height, width) of Arbalet on axes (x, z) of Leap Motion
                        x_speed_boost = self.swipe[0].direction[
                            0] * self.swipe[0].speed / 500.
                        y_speed_boost = self.swipe[0].direction[
                            2] * self.swipe[0].speed / 500.
                        ball.x_speed += x_speed_boost
                        ball.y_speed += y_speed_boost
                self.swipe[0] = None

    def run(self):
        while True:
            for ball in self.balls:
                ball.step_forward()
            self.render()
            self.rate.sleep()
Ejemplo n.º 4
0
	def __init__ (self):
		QMainWindow.__init__ (self)

		self.controller = Controller ()
		self.listener = LeapListener (self)
		self.controller.add_listener (self.listener)

		self.mode = "gallery"
		self.scroll = False
		self.direction = ""
		self.direction_x = 0
		self.scroll_velocity = 0
		self.current_index = 0

		# List containing images for the gallery
		self.list_view = QListWidget ()
		self.list_view.setFlow (0)
		self.list_view.setHorizontalScrollMode (1)
		self.list_view.setMouseTracking (True)
		self.list_view.itemClicked.connect (self.show_image)

		# Setting the style of the ListView, background, item selected, etc
		self.list_view.setStyleSheet ("""
				QListWidget::item:hover {background: transparent;}
				QListWidget::item:disabled:hover {background: transparent;}
				QListWidget::item:hover:!active {background: transparent;}
				QListWidget::item:selected:active {background: transparent;}
	            QListWidget::item:selected:!active {background: transparent;}
	            QListWidget::item:selected:disabled {background: transparent;}
	            QListWidget::item:selected:!disabled {background: transparent;}
	            QListWidget {background: #2C3539}
			""")

		# Image viewer
		self.scene = QGraphicsScene ()
		self.viewer = QGraphicsView (self.scene)

		self.stackedWidget = QStackedWidget ()
		self.stackedWidget.addWidget (self.list_view)
		self.stackedWidget.addWidget (self.viewer)

		self.setCentralWidget (self.stackedWidget)
		self.resize (500, 400)
		self.showMaximized ()

		scan = ScanLibrary ("/home/chris/Example")
		threads.append (scan)
		self.connect (scan, SIGNAL (scan.signal), self.add_images_to_list)
		scan.start ()

		self.connect (self, SIGNAL ("scrollChanged(bool)"), self.scroll_view)
Ejemplo n.º 5
0
class Bounces(Application):

    def __init__(self, parser, rate):
        Application.__init__(self, parser)
        self.balls = []
        self.rate = Rate(rate)

        def rand():
            return choice([-1, 1])*uniform(1./rate, 10./rate)

        for ball in range(4):
            self.balls.append(Ball(ball, randint(0, self.height-1), randint(0, self.width-1),
                                   self.height, self.width,
                                   Ball.colors[ball%len(Ball.colors)],
                                   rand(), rand()))

        # Motion control via Leap Motion
        self.swipe = [None]
        self.swipe_lock = RLock()

        if leapmotion:
            self.leap_listener = SampleListener(self.swipe, self.swipe_lock)
            self.controller = Controller()
            self.controller.add_listener(self.leap_listener)

    def close(self, reason='unknown'):
        Application.close(self, reason)
        if leapmotion:
            self.controller.remove_listener(self.leap_listener)

    def render(self):
        with self.model:
            self.model.set_all('black')
            with self.swipe_lock:
                for ball in self.balls:
                    self.model.set_pixel(ball.x, ball.y, ball.color)
                    if self.swipe[0] is not None:
                        # mapping axes (height, width) of Arbalet on axes (x, z) of Leap Motion
                        x_speed_boost = self.swipe[0].direction[0] * self.swipe[0].speed / 500.
                        y_speed_boost = self.swipe[0].direction[2] * self.swipe[0].speed / 500.
                        ball.x_speed += x_speed_boost
                        ball.y_speed += y_speed_boost
                self.swipe[0] = None

    def run(self):
        while True:
            for ball in self.balls:
                ball.step_forward()
            self.render()
            self.rate.sleep()
Ejemplo n.º 6
0
    def __init__(self):
        QMainWindow.__init__(self)

        self.controller = Controller()
        self.listener = LeapListener(self)
        self.controller.add_listener(self.listener)

        self.mode = "gallery"
        self.scroll = False
        self.direction = ""
        self.direction_x = 0
        self.scroll_velocity = 0
        self.current_index = 0

        # List containing images for the gallery
        self.list_view = QListWidget()
        self.list_view.setFlow(0)
        self.list_view.setHorizontalScrollMode(1)
        self.list_view.setMouseTracking(True)
        self.list_view.itemClicked.connect(self.show_image)

        # Setting the style of the ListView, background, item selected, etc
        self.list_view.setStyleSheet(
            """
				QListWidget::item:hover {background: transparent;}
				QListWidget::item:disabled:hover {background: transparent;}
				QListWidget::item:hover:!active {background: transparent;}
				QListWidget::item:selected:active {background: transparent;}
	            QListWidget::item:selected:!active {background: transparent;}
	            QListWidget::item:selected:disabled {background: transparent;}
	            QListWidget::item:selected:!disabled {background: transparent;}
	            QListWidget {background: #2C3539}
			"""
        )

        # Image viewer
        self.scene = QGraphicsScene()
        self.viewer = QGraphicsView(self.scene)

        self.stackedWidget = QStackedWidget()
        self.stackedWidget.addWidget(self.list_view)
        self.stackedWidget.addWidget(self.viewer)

        self.setCentralWidget(self.stackedWidget)
        self.resize(500, 400)
        self.showMaximized()

        scan = ScanLibrary("/home/chris/Example")
        threads.append(scan)
        self.connect(scan, SIGNAL(scan.signal), self.add_images_to_list)
        scan.start()

        self.connect(self, SIGNAL("scrollChanged(bool)"), self.scroll_view)
Ejemplo n.º 7
0
    def __init__(self, parser, rate):
        Application.__init__(self, parser)
        self.balls = []
        self.rate = Rate(rate)

        def rand():
            return choice([-1, 1]) * uniform(1. / rate, 10. / rate)

        for ball in range(4):
            self.balls.append(
                Ball(ball, randint(0, self.height - 1),
                     randint(0, self.width - 1), self.height, self.width,
                     Ball.colors[ball % len(Ball.colors)], rand(), rand()))

        # Motion control via Leap Motion
        self.swipe = [None]
        self.swipe_lock = RLock()

        if leapmotion:
            self.leap_listener = SampleListener(self.swipe, self.swipe_lock)
            self.controller = Controller()
            self.controller.add_listener(self.leap_listener)
Ejemplo n.º 8
0
    def __init__(self, parser, rate):
        Application.__init__(self, parser)
        self.balls = []
        self.rate = Rate(rate)

        def rand():
            return choice([-1, 1])*uniform(1./rate, 10./rate)

        for ball in range(4):
            self.balls.append(Ball(ball, randint(0, self.height-1), randint(0, self.width-1),
                                   self.height, self.width,
                                   Ball.colors[ball%len(Ball.colors)],
                                   rand(), rand()))

        # Motion control via Leap Motion
        self.swipe = [None]
        self.swipe_lock = RLock()

        if leapmotion:
            self.leap_listener = SampleListener(self.swipe, self.swipe_lock)
            self.controller = Controller()
            self.controller.add_listener(self.leap_listener)
Ejemplo n.º 9
0
class LeapFlow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.controller = Controller()
        self.listener = LeapListener(self)
        self.controller.add_listener(self.listener)

        self.mode = "gallery"
        self.scroll = False
        self.direction = ""
        self.direction_x = 0
        self.scroll_velocity = 0
        self.current_index = 0

        # List containing images for the gallery
        self.list_view = QListWidget()
        self.list_view.setFlow(0)
        self.list_view.setHorizontalScrollMode(1)
        self.list_view.setMouseTracking(True)
        self.list_view.itemClicked.connect(self.show_image)

        # Setting the style of the ListView, background, item selected, etc
        self.list_view.setStyleSheet(
            """
				QListWidget::item:hover {background: transparent;}
				QListWidget::item:disabled:hover {background: transparent;}
				QListWidget::item:hover:!active {background: transparent;}
				QListWidget::item:selected:active {background: transparent;}
	            QListWidget::item:selected:!active {background: transparent;}
	            QListWidget::item:selected:disabled {background: transparent;}
	            QListWidget::item:selected:!disabled {background: transparent;}
	            QListWidget {background: #2C3539}
			"""
        )

        # Image viewer
        self.scene = QGraphicsScene()
        self.viewer = QGraphicsView(self.scene)

        self.stackedWidget = QStackedWidget()
        self.stackedWidget.addWidget(self.list_view)
        self.stackedWidget.addWidget(self.viewer)

        self.setCentralWidget(self.stackedWidget)
        self.resize(500, 400)
        self.showMaximized()

        scan = ScanLibrary("/home/chris/Example")
        threads.append(scan)
        self.connect(scan, SIGNAL(scan.signal), self.add_images_to_list)
        scan.start()

        self.connect(self, SIGNAL("scrollChanged(bool)"), self.scroll_view)

    def setScroll(self, scroll):
        """Emit signal to scroll the view"""
        if self.scroll != scroll:
            self.scroll = scroll
            self.emit(SIGNAL("scrollChanged(bool)"), scroll)

    def scroll_view(self):
        """Scroll the view based on scroll velocity and direction"""

        x = self.direction_x * self.scroll_velocity / 100
        bar_x = self.list_view.horizontalScrollBar().value()
        self.list_view.horizontalScrollBar().setValue(bar_x + x)

    def add_images_to_list(self):
        """To add a widget to the listview you must add a QListWidgetItem
		and replace with your widget"""

        for image in library:
            item = QListWidgetItem()
            pixmap = QPixmap.fromImage(QImage(library[image]))
            label = QLabel()
            label.setPixmap(pixmap.scaled(600, 400))
            item.setSizeHint(label.sizeHint())
            item.setData(0, library[image])
            self.list_view.addItem(item)
            self.list_view.setItemWidget(item, label)

    def show_image(self, item):
        """"Display the selected image"""

        self.current_index = self.list_view.indexFromItem(item).row()
        self.scene.addPixmap((QPixmap.fromImage(QImage(item.text()))).scaled(self.viewer.size()))

        self.stackedWidget.setCurrentIndex(1)
        self.mode = "viewer"

    def previous_image(self):
        """Load previous image"""

        if self.current_index - 1 >= 0:
            self.current_index -= 1
            self.load_image()

    def next_image(self):
        """Load next image"""

        if self.current_index + 1 <= len(library.keys()) - 1:
            self.current_index += 1
            self.load_image()

    def load_image(self):
        """Load the image in self.current_index"""

        self.scene.addPixmap(QPixmap.fromImage(QImage(library[library.keys()[self.current_index]])))
Ejemplo n.º 10
0
class LeapFlow (QMainWindow):

	def __init__ (self):
		QMainWindow.__init__ (self)

		self.controller = Controller ()
		self.listener = LeapListener (self)
		self.controller.add_listener (self.listener)

		self.mode = "gallery"
		self.scroll = False
		self.direction = ""
		self.direction_x = 0
		self.scroll_velocity = 0
		self.current_index = 0

		# List containing images for the gallery
		self.list_view = QListWidget ()
		self.list_view.setFlow (0)
		self.list_view.setHorizontalScrollMode (1)
		self.list_view.setMouseTracking (True)
		self.list_view.itemClicked.connect (self.show_image)

		# Setting the style of the ListView, background, item selected, etc
		self.list_view.setStyleSheet ("""
				QListWidget::item:hover {background: transparent;}
				QListWidget::item:disabled:hover {background: transparent;}
				QListWidget::item:hover:!active {background: transparent;}
				QListWidget::item:selected:active {background: transparent;}
	            QListWidget::item:selected:!active {background: transparent;}
	            QListWidget::item:selected:disabled {background: transparent;}
	            QListWidget::item:selected:!disabled {background: transparent;}
	            QListWidget {background: #2C3539}
			""")

		# Image viewer
		self.scene = QGraphicsScene ()
		self.viewer = QGraphicsView (self.scene)

		self.stackedWidget = QStackedWidget ()
		self.stackedWidget.addWidget (self.list_view)
		self.stackedWidget.addWidget (self.viewer)

		self.setCentralWidget (self.stackedWidget)
		self.resize (500, 400)
		self.showMaximized ()

		scan = ScanLibrary ("/home/chris/Example")
		threads.append (scan)
		self.connect (scan, SIGNAL (scan.signal), self.add_images_to_list)
		scan.start ()

		self.connect (self, SIGNAL ("scrollChanged(bool)"), self.scroll_view)

	def setScroll (self, scroll):
		"""Emit signal to scroll the view"""
		if (self.scroll != scroll):
			self.scroll = scroll
			self.emit (SIGNAL("scrollChanged(bool)"), scroll)

	def scroll_view (self):
		"""Scroll the view based on scroll velocity and direction"""

		x = self.direction_x * self.scroll_velocity / 100
		bar_x = self.list_view.horizontalScrollBar ().value ()
		self.list_view.horizontalScrollBar ().setValue (bar_x + x)

	def add_images_to_list (self):
		"""To add a widget to the listview you must add a QListWidgetItem
		and replace with your widget"""

		for image in library:
			item = QListWidgetItem ()
			pixmap = QPixmap.fromImage (QImage (library[image]))
			label = QLabel ()
			label.setPixmap (pixmap.scaled (600, 400))
			item.setSizeHint (label.sizeHint ())
			item.setData (0, library[image])
			self.list_view.addItem (item)
			self.list_view.setItemWidget (item, label)

	def show_image (self, item):
		""""Display the selected image"""

		self.current_index = self.list_view.indexFromItem (item).row ()
		self.scene.addPixmap ((QPixmap.fromImage (QImage (item.text()))).scaled (self.viewer.size()))

		self.stackedWidget.setCurrentIndex (1)
		self.mode = "viewer"

	def previous_image (self):
		"""Load previous image"""

		if self.current_index - 1 >= 0:
			self.current_index -= 1
			self.load_image ()

	def next_image (self):
		"""Load next image"""

		if self.current_index + 1 <= len(library.keys ()) - 1:
			self.current_index += 1
			self.load_image ()

	def load_image (self):
		"""Load the image in self.current_index"""

		self.scene.addPixmap (QPixmap.fromImage (QImage (library[library.keys()[self.current_index]])))