Exemplo n.º 1
0
 def Reset(self, milliseconds):
     self.lock.acquire()
     if milliseconds is None:
         milliseconds = INFINITE
     self.timeout = milliseconds
     SetEvent(self.event)
     self.lock.release()
Exemplo n.º 2
0
 def Stop(self):
     """
     Stops the event processing of this class.
     """
     self.keepAlive = False
     SetEvent(self.stopEvent)
     if currentThread() != self:
         self.join(1.0)
Exemplo n.º 3
0
 def Call(self, func, *args, **kwargs):
     """
     Queue a function and its arguments for execution in the
     :class:`eg.ThreadWorker` thread. Doesn't wait for the completion of the
     function.
     """
     action = ThreadWorkerAction(func, args, kwargs, True)
     self.__queue.append(action)
     SetEvent(self.__wakeEvent)
     return action
Exemplo n.º 4
0
 def Wrapper(*args, **kwargs):
     action = ThreadWorkerAction(func, args, kwargs, False)
     self.__queue.append(action)
     SetEvent(self.__wakeEvent)
     action.processed.wait(timeout)
     if timeout is not None and not action.processed.isSet():
         eg.PrintStack()
         raise Exception("Timeout while calling %s" % func.__name__)
     if action.exceptionInfo is not None:
         excType, excValue, excTraceback = action.exceptionInfo
         raise excType, excValue, excTraceback
     return action.returnValue
Exemplo n.º 5
0
 def Close(self):
     """Closes  the serial port and stops all event processing."""
     self.keepAlive = False
     SetEvent(self.stopEvent)
     if currentThread() != self:
         self.join(1.0)
     if self.hFile:
         #Restore original timeout values:
         SetCommTimeouts(self.hFile, self.oldCommTimeouts)
         #Close COM-Port:
         if not self._CloseHandle(self.hFile):
             self.hFile = None
             raise SerialError()
Exemplo n.º 6
0
 def on_message(self, _, m):
     if not self.info.isStarted:
         if self.wsC:
             self.wsC.close()
     if m is None:
         return
     try:
         m = loads(m)
         if 'command' in m and m['command'] == 'configfile':
             del m['apwd']
             del m['pswd']
         self.Log(self.text.wsMssg % repr(m), 5)
         self.lastMessage = ttime()
         self.msgWait = DEFAULT_WAIT
     except:
         eg.PrintTraceback()
         self.refreshWebSocket()
         return
     if "token" in m:
         token = m['token']
         event = self.queryData[token]
         del m["token"]
         self.queryData[token] = m
         SetEvent(event)
         return
     if 'command' in m:
         cmd = m['command']
         if cmd == 'nop':
             pass
         elif cmd == 'password':
             self.wsC.send("{'command':'password','password':'******'}" % self.password)
         elif cmd == 'authorized':
             self.wsC.send("{'command':'getconf'}")
             self.TriggerEvent(self.text.config) 
         elif cmd == 'configfile':
             self.gpios = {}
             for item in m['gpios']:
                 if item[1] and item[0] != m['wled']:
                     self.gpios[item[0]] = (item[2], item[3]) # title, out
             self.wsC.send("{'command':'pinlist'}")
         elif cmd == 'pinlist':
             pass
         elif cmd == 'change':
             suffix = m['title']
             if m['id'] != 'A0':
                 suffix += ".%s" % PINSTATES[m['value']]
             self.TriggerEvent(suffix, payload=m['value'])
     else:
         eg.PrintNotice(unknmsg % (self.info.eventPrefix, repr(m)))
Exemplo n.º 7
0
 def onClose(self, evt):
     retCode = self.GetReturnCode()
     if retCode not in self.LABELS:
         return
     if self.timer:
         self.timer.Stop()
         del self.timer
     ix = 1 + self.action.RES_IDS.index(
         retCode) if retCode in self.action.RES_IDS else 1
     result = self.action.RESULTS[ix]
     self.alias = self.alias if self.alias else self.title
     if self.payload:
         eg.TriggerEvent("%s.%s" % (self.alias, result), self.payload,
                         "MessageBox")
     else:
         eg.TriggerEvent("%s.%s" % (self.alias, result),
                         prefix="MessageBox")
     if self.event is not None:
         self.action.retCode = result
         SetEvent(self.event)
     self.Destroy()
Exemplo n.º 8
0
 def Run(self):
     while self.run:
         if self.lcd is not None:
             if self.free:
                 item = self.queue.get()
                 event = item[1]
                 item = item[0]
                 test = self.flush()
                 if test != "No Data":
                     self.lcd = None
                     self.Init()
                 if item != "STOP":
                     self.free = False
                     self.udprint(*item)
                     if event is not None:
                         SetEvent(event)
                     self.free = True
                 else:
                     break
             else:
                 sleep(2.0)
         else:
             self.Init()
Exemplo n.º 9
0
    def ShowOSD(
            self,
            osdText="",
            fontInfo=None,
            textColour=(255, 255, 255),
            outlineColour=(0, 0, 0),
            alignment=0,
            offset=(0, 0),
            displayNumber=0,
            timeout=3.0,
            event=None,
            skin=None,
    ):
        self.timer.cancel()
        if osdText.strip() == "":
            self.bitmap = wx.EmptyBitmap(0, 0)
            SetWindowPos(self.hwnd, 0, 0, 0, 0, 0, HWND_FLAGS | SWP_HIDEWINDOW)
            SetEvent(event)
            return

        #self.Freeze()
        memoryDC = wx.MemoryDC()

        # make sure the mask colour is not used by foreground or
        # background colour
        forbiddenColours = (textColour, outlineColour)
        maskColour = (255, 0, 255)
        if maskColour in forbiddenColours:
            maskColour = (0, 0, 2)
            if maskColour in forbiddenColours:
                maskColour = (0, 0, 3)
        maskBrush = wx.Brush(maskColour, wx.SOLID)
        memoryDC.SetBackground(maskBrush)

        if fontInfo is None:
            fontInfo = DEFAULT_FONT_INFO
        font = wx.FontFromNativeInfoString(fontInfo)
        memoryDC.SetFont(font)

        textLines = osdText.splitlines()
        sizes = [memoryDC.GetTextExtent(line or " ") for line in textLines]
        textWidths, textHeights = zip(*sizes)
        textWidth = max(textWidths)
        textHeight = sum(textHeights)

        if skin:
            bitmap = self.GetSkinnedBitmap(textLines, textWidths, textHeights,
                                           textWidth, textHeight, memoryDC,
                                           textColour, "Default")
            width, height = bitmap.GetSize()
        elif outlineColour is None:
            width, height = textWidth, textHeight
            bitmap = wx.EmptyBitmap(width, height)
            memoryDC.SelectObject(bitmap)

            # fill the DC background with the maskColour
            memoryDC.Clear()

            # draw the text with the foreground colour
            memoryDC.SetTextForeground(textColour)
            DrawTextLines(memoryDC, textLines, textHeights)

            # mask the bitmap, so we can use it to get the needed
            # region of the window
            memoryDC.SelectObject(wx.NullBitmap)
            bitmap.SetMask(wx.Mask(bitmap, maskColour))

            # fill the anti-aliased pixels of the text with the foreground
            # colour, because the region of the window will add these
            # half filled pixels also. Otherwise we would get an ugly
            # border with mask-coloured pixels.
            memoryDC.SetBackground(wx.Brush(textColour, wx.SOLID))
            memoryDC.SelectObject(bitmap)
            memoryDC.Clear()
            memoryDC.SelectObject(wx.NullBitmap)
        else:
            width, height = textWidth + 5, textHeight + 5
            outlineBitmap = wx.EmptyBitmap(width, height, 1)
            outlineDC = wx.MemoryDC()
            outlineDC.SetFont(font)
            outlineDC.SelectObject(outlineBitmap)
            outlineDC.Clear()
            outlineDC.SetBackgroundMode(wx.SOLID)
            DrawTextLines(outlineDC, textLines, textHeights)
            outlineDC.SelectObject(wx.NullBitmap)
            outlineBitmap.SetMask(wx.Mask(outlineBitmap))
            outlineDC.SelectObject(outlineBitmap)

            bitmap = wx.EmptyBitmap(width, height)
            memoryDC.SetTextForeground(outlineColour)
            memoryDC.SelectObject(bitmap)
            memoryDC.Clear()

            Blit = memoryDC.Blit
            logicalFunc = wx.COPY
            for x in xrange(5):
                for y in xrange(5):
                    Blit(x, y, width, height, outlineDC, 0, 0, logicalFunc,
                         True)
            outlineDC.SelectObject(wx.NullBitmap)
            memoryDC.SetTextForeground(textColour)
            DrawTextLines(memoryDC, textLines, textHeights, 2, 2)
            memoryDC.SelectObject(wx.NullBitmap)
            bitmap.SetMask(wx.Mask(bitmap, maskColour))

        region = wx.RegionFromBitmap(bitmap)
        self.SetShape(region)
        self.bitmap = bitmap
        monitorDimensions = GetMonitorDimensions()
        try:
            displayRect = monitorDimensions[displayNumber]
        except IndexError:
            displayRect = monitorDimensions[0]
        xOffset, yOffset = offset
        xFunc, yFunc = ALIGNMENT_FUNCS[alignment]
        x = displayRect.x + xFunc((displayRect.width - width), xOffset)
        y = displayRect.y + yFunc((displayRect.height - height), yOffset)
        deviceContext = wx.ClientDC(self)
        deviceContext.DrawBitmap(self.bitmap, 0, 0, False)
        SetWindowPos(self.hwnd, 0, x, y, width, height,
                     HWND_FLAGS | SWP_SHOWWINDOW)

        if timeout > 0.0:
            self.timer = threading.Timer(timeout, self.OnTimeout)
            self.timer.start()
        eg.app.Yield(True)
        SetEvent(event)
Exemplo n.º 10
0
 def AppendAction(self, action):
     self.__queue.append(action)
     SetEvent(self.__wakeEvent)
Exemplo n.º 11
0
 def HandleMsg(self, dummyHWnd, mesg, wParam, lParam):
     if self.controlPanel:
         fwsPanel = self.controlPanel
     else:
         fwsPanel = dummyFwsPanel()
     rooms = (None, fwsPanel.p1, fwsPanel.p2, fwsPanel.p3, fwsPanel.p4)
     if wParam & 0xFF0000 == 0x40000 or wParam & 0xFF0000 == 0x80000:
         state = [int(wParam & 0x1)]
         fwsPanel.SetUnit((CEL_SYM, FAR_SYM)[wParam & 0x1])
         self.minMax = ((10, 30), (50, 86))[wParam & 0x1]
         if ConfigData.minMax != self.minMax:
             ConfigData.minMax = self.minMax
         room_1 = lParam & 0x000000FF
         state.append((int(room_1 & 0x80) / 0x80, int(room_1 & 0x7f)))
         room_2 = (lParam & 0x0000FF00) >> 8
         state.append((int(room_2 & 0x80) / 0x80, int(room_2 & 0x7f)))
         room_3 = (lParam & 0x00FF0000) >> 16
         state.append((int(room_3 & 0x80) / 0x80, int(room_3 & 0x7f)))
         room_4 = (lParam & 0xFF000000) >> 24
         state.append((int(room_4 & 0x80) / 0x80, int(room_4 & 0x7f)))
         self.state = state
         fwsPanel.p1.SetValue(room_1)
         fwsPanel.p2.SetValue(room_2)
         fwsPanel.p3.SetValue(room_3)
         fwsPanel.p4.SetValue(room_4)
     elif wParam & 0xFF0000 == 0xC0000:
         rooms[wParam & 0xF].SetLight(lParam)
     elif wParam & 0xFF0000 == 0x200000:
         rooms[wParam & 0xF].SetTemperature(lParam)
     elif wParam & 0xFF0000 == 0x500000:
         fwsPanel.SetAllLights(lParam)
     elif wParam & 0xFF0000 == 0x800000:
         if not lParam:
             for room in rooms[1:]:
                 room.Reset()
     value = wParam & 0xFF0000
     if value in EVENTS:
         event = EVENTS[value]
         suffix = event[0]
         if not event[1]:
             payload = (lParam & event[2], (lParam & 0x100) >> 8)
         else:
             payload = (int(wParam & event[1]), lParam & event[2],
                        (lParam & 0x100) >> 8)
         if self.event:
             if self.event[0] in RESULTS:
                 if value == RESULTS[self.event[0]]:
                     if value == 0x080000:
                         self.result = state
                     else:
                         self.result = payload
                     wx.Yield()
                     SetEvent(self.event[1])
                     if value == 0x080000:  #No event
                         self.event = None
                         return
         #else:
         payload = state if (value == 0x040000
                             or value == 0x080000) else payload
         self.TriggerEvent(suffix, payload=payload)
     self.event = None