Esempio n. 1
0
    def __init__(self, w, h, child_conn):

        super(MainWindow, self).__init__(title="RayTracingOpenCL")
        self.child_conn = child_conn
        self.w, self.h = w, h
        self.already_pressed = {
            k: False
            for k in [
                "w", "a", "s", "d", "Up", "Left", "Right", "Down", "Escape",
                "q", "e", "plus", "minus"
            ]
        }
        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)

        self.image = Gtk.Image()
        vbox.pack_start(self.image, True, True, 0)

        self.status = Gtk.Label()

        vbox.pack_start(self.status, False, True, 0)
        self.add(vbox)

        self.connect("key-press-event", self.on_key_pressed)
        self.connect("key-release-event", self.on_key_released)
        GLib.io_add_watch(GLib.IOChannel(self.child_conn.fileno()),
                          GLib.PRIORITY_DEFAULT_IDLE,
                          GLib.IOCondition(1 | 8 | 16),
                          self.on_new_frame_ready, None)

        self.start = datetime.datetime.now()
        self.fps = 0
Esempio n. 2
0
    def select_setup_new(self):
        """
        The newer implementation using GLib.Source.add_unix_fd()
        
        .. TODO::
        
            Too cutting edge right now, unfortunately. Implementation
            is not complete.
        """
        #self.source.remove()
        if self.source is not None:
            self.source.destroy()
        self.source = source = GLib.Source()

        rlist, wlist, xlist = self.select_args()
        print('select_setup', rlist, wlist, xlist)
        fds = set(rlist + wlist + xlist)

        # should use GLib.Source.add_unix_fd, but thats too cutting edge right now
        assert len(fds) == 1
        fd = next(iter(fds))

        condition = GLib.IOCondition(0)
        if fd in rlist:
            condition |= GLib.IOCondition.IN
        if fd in wlist:
            condition |= GLib.IOCondition.OUT
        if fd in xlist:
            condition |= GLib.IOCondition.ERR
        if condition.real != 0:
            source.add_unix_fd(fd, condition)

        source.set_callback(self.glib_select_callback, fd)
Esempio n. 3
0
    def register(self, fd, events):
        assert fd not in self._fd_to_tag

        condition = GLib.IOCondition(0)
        if events & selectors.EVENT_READ:
            condition |= GLib.IOCondition.IN
        if events & selectors.EVENT_WRITE:
            condition |= GLib.IOCondition.OUT
        self._fd_to_tag[fd] = self.add_unix_fd(fd, condition)
Esempio n. 4
0
 def __init__(self, mainloop, fd, read, write, desc):
     self._mainloop = mainloop
     self.description = desc
     condition = GLib.IOCondition(0)
     if read:
         condition |= GLib.IOCondition.IN | GLib.IOCondition.HUP
     if write:
         condition |= GLib.IOCondition.OUT
     self._doread = read
     self._dowrite = write
     self._handle = GLib.unix_fd_add_full(0, fd, condition, self._call,
                                          None, None)
Esempio n. 5
0
    def __init__(self):
        global tag_list
        # configuração da porta serial
        #self.tela = tela
        self.serial_port = '/dev/ttyUSB0'
        self.port_speed = 9600
        self.max_bytes = -1
        self.ser = serial.Serial(self.serial_port, self.port_speed, timeout=3)
#------------------------------------------------------------------
        self.channel = GLib.IOChannel(self.ser.fileno())
        self.channel.set_flags(GLib.IO_FLAG_NONBLOCK)

        self.cond = GLib.IOCondition(GLib.IOCondition.IN)
        self.channel.add_watch(self.cond,self.leituraRFID)
Esempio n. 6
0
    def select_setup_old(self):
        """
        The older implementation using GLib.Source.add_poll()
        """
        rlist, wlist, xlist = self.select_args()
        fds = set(rlist + wlist + xlist)
        assert len(fds) == 1
        fd = next(iter(fds))

        condition = GLib.IOCondition(0)
        if fd in rlist:
            condition |= GLib.IOCondition.IN
        if fd in wlist:
            condition |= GLib.IOCondition.OUT
        if fd in xlist:
            condition |= GLib.IOCondition.ERR
        source = GLib.unix_fd_source_new(fd, condition)
        source.set_callback(self.glib_select_callback_old,
                            (fd, rlist, wlist, xlist))
        source.attach(self.context)
        self.source = source
Esempio n. 7
0
 def _events_to_io_condition(events):
     return (GLib.IOCondition.IN if events & selectors.EVENT_READ else GLib.IOCondition(0)) | \
         (GLib.IOCondition.OUT if events & selectors.EVENT_WRITE else GLib.IOCondition(0))
Esempio n. 8
0
def to_cond(events):
    cond = GLib.IOCondition(0)
    if events & selectors.EVENT_READ: cond |= GLib.IOCondition.IN
    if events & selectors.EVENT_WRITE: cond |= GLib.IOCondition.OUT
    return cond
Esempio n. 9
0
 def test_value_nicks_names(self):
     self.assertEqual(GLib.IOCondition(3).value_nicks, ["in", "pri"])
     self.assertEqual(
         GLib.IOCondition(3).value_names, ["G_IO_IN", "G_IO_PRI"])
     self.assertEqual(GLib.IOCondition(3).first_value_nick, "in")
     self.assertEqual(GLib.IOCondition(3).first_value_name, "G_IO_IN")
Esempio n. 10
0
 def test_no_value_nick(self):
     self.assertEqual(GLib.IOCondition(0).first_value_nick, None)
     self.assertEqual(GLib.IOCondition(0).first_value_name, None)
     self.assertEqual(GLib.IOCondition(0).value_names, [])
     self.assertEqual(GLib.IOCondition(0).value_nicks, [])