Beispiel #1
0
class DragPlane(wx.Panel):
    """
    An instance of this class represents a temporary "drag plane" for a portable draggable
    """
    def __init__(self, parent, draggableControl):
        super().__init__(parent,
                         name=draggableControl.GetName() + "_dragplane",
                         size=parent.GetSize(),
                         style=wx.TRANSPARENT_WINDOW)
        self.__parent__ = parent
        self.__dp__ = draggableControl
        draggableControl.Reparent(self)
        self.Bind(wx.EVT_PAINT, self.onPaint)
        self.paintStyler = PaintStyler()

    def Destroy(self):
        self.__dp__.Reparent(self.__parent__)
        super().Destroy()

    def onPaint(self, event):
        event.Skip()
        self.draw(wx.PaintDC(self))

    def draw(self, dc):
        self.paintStyler.select("DragPlane:normal", dc)
        w, h = self.GetClientSize()
        dc.DrawRectangle(0, 0, w, h)
Beispiel #2
0
 def __init__(self, parent, draggableControl):
     super().__init__(parent,
                      name=draggableControl.GetName() + "_dragplane",
                      size=parent.GetSize(),
                      style=wx.TRANSPARENT_WINDOW)
     self.__parent__ = parent
     self.__dp__ = draggableControl
     draggableControl.Reparent(self)
     self.Bind(wx.EVT_PAINT, self.onPaint)
     self.paintStyler = PaintStyler()
Beispiel #3
0
 def __init__(self,
              parent,
              draggable=False,
              portable=False,
              *args,
              **kwargs):
     super().__init__(parent, draggable, portable, *args, **kwargs)
     self.parent = parent
     self.__draggableOver__ = False
     self.__mouseOver__ = False
     self.Bind(wx.EVT_PAINT, self.onPaint)
     self.Bind(wx.EVT_ENTER_WINDOW, self.onMouseEnter)
     self.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave)
     self.paintStyler = PaintStyler()
Beispiel #4
0
    def __init__(self, parent, player):
        super().__init__(parent,
                         size=PlayerWidget.DEFAULTSIZE,
                         style=wx.CLIP_CHILDREN)
        self.player = None

        if not PlayerWidget.yummyIcon:
            PlayerWidget.yummyIcon = wx.Bitmap(RESOURCES +
                                               "/yummy-icon-28-white.png")

        self.paintStyler = PaintStyler()
        self.Bind(wx.EVT_PAINT, self.onPaint)

        self.reset(player)
Beispiel #5
0
    def __init__(self, parent, tile):
        DraggableControl.__init__(self,
                                  parent,
                                  name=tile.toString(),
                                  size=TileWidget.DEFAULTSIZE,
                                  style=wx.CLIP_CHILDREN)

        if not TileWidget.yummyIcon:
            TileWidget.yummyIcon = wx.Bitmap(RESOURCES +
                                             "/yummy-icon-28-white.png")

        self.paintStyler = PaintStyler()
        self.tile = tile
        self.color = self.tile.getColor()
        self.valueStr = str(self.tile.getValue())
        self.Bind(wx.EVT_PAINT, self.onPaint)
Beispiel #6
0
class TileWidget(DraggableControl):
    yummyIcon = None
    DEFAULTSIZE = (36, 50)

    def __init__(self, parent, tile):
        DraggableControl.__init__(self,
                                  parent,
                                  name=tile.toString(),
                                  size=TileWidget.DEFAULTSIZE,
                                  style=wx.CLIP_CHILDREN)

        if not TileWidget.yummyIcon:
            TileWidget.yummyIcon = wx.Bitmap(RESOURCES +
                                             "/yummy-icon-28-white.png")

        self.paintStyler = PaintStyler()
        self.tile = tile
        self.color = self.tile.getColor()
        self.valueStr = str(self.tile.getValue())
        self.Bind(wx.EVT_PAINT, self.onPaint)

    def getZoomFactor(self):
        try:
            return self.GetParent().getZoomFactor()
        finally:
            return 1

    def adjustSize(self, size, zf):
        return (size[0] * zf, size[1] * zf)

    def onPaint(self, event):
        event.Skip()
        dc = wx.PaintDC(self)
        zf = self.getZoomFactor()
        self.drawBackground(dc, zf)
        self.drawFace(dc, zf)

    def drawBackground(self, dc, zf):
        self.paintStyler.select(STYLES[self.color], dc)
        w, h = self.adjustSize(self.GetClientSize(), zf)
        gc = wx.GraphicsContext.Create(dc)
        if gc:
            brushColor = dc.GetBrush().GetColour()

            gbrush = gc.CreateLinearGradientBrush(
                0, h, 0, 0, brushColor.ChangeLightness(90),
                brushColor.ChangeLightness(120))
            gc.SetBrush(gbrush)
            path = gc.CreatePath()
            path.AddRoundedRectangle(1, 1, w - 1, h - 1, 3)
            gc.DrawPath(path)

            gbrush = gc.CreateLinearGradientBrush(
                0, 0, 0, h, brushColor.ChangeLightness(90),
                brushColor.ChangeLightness(120))
            gc.SetBrush(gbrush)
            path = gc.CreatePath()
            path.AddRoundedRectangle(4, 6, w - 8, h - 14, 6)
            gc.DrawPath(path)

    def drawFace(self, dc, zf):
        self.paintStyler.select(STYLES[self.color], dc)
        w, h = self.adjustSize(self.GetClientSize(), zf)
        if isinstance(self.tile, model.Joker):
            iw, ih = self.adjustSize(TileWidget.yummyIcon.GetSize(), zf)
            dc.DrawBitmap(TileWidget.yummyIcon, int(0.5 * (w - iw)),
                          int(0.5 * (h - ih)))
        else:
            tw, th = self.adjustSize(dc.GetTextExtent(self.valueStr), zf)
            tx, ty = (0.5 * (w - tw), 0.5 * (h - th))
            dc.DrawText(self.valueStr, tx, ty)
Beispiel #7
0
class DraggableDropTarget(DraggableControl, DraggableEventListener):
    """
    Instances of this class can respond to draggable events. Since they also derive from DraggableCOntrol, 
    these instances can be dragged and dropped themselvers too.
    """
    def __init__(self,
                 parent,
                 draggable=False,
                 portable=False,
                 *args,
                 **kwargs):
        super().__init__(parent, draggable, portable, *args, **kwargs)
        self.parent = parent
        self.__draggableOver__ = False
        self.__mouseOver__ = False
        self.Bind(wx.EVT_PAINT, self.onPaint)
        self.Bind(wx.EVT_ENTER_WINDOW, self.onMouseEnter)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave)
        self.paintStyler = PaintStyler()

    def getObjectsByType(self, type):
        """
        """
        result = []
        children = self.GetChildren()
        for c in children:
            if isinstance(c, type):
                result.append(c)
        return result

    def isMouseOver(self):
        """
        """
        return self.__mouseOver__

    def isDraggableOver(self):
        """
        """
        return self.__draggableOver__

    def onMouseEnter(self, event):
        self.__mouseOver__ = True
        self.Refresh()
        event.Skip()

    def onMouseLeave(self, event):
        self.__mouseOver__ = False
        self.Refresh()
        event.Skip()

    def onDraggableHover(self, event):
        if util.rectsOverlap(event.obj.GetScreenRect(), self.GetScreenRect()):
            self.__draggableOver__ = True
            event.obj.Refresh()
        else:
            self.__draggableOver__ = False
        self.Refresh()
        event.Skip()

    def onDraggableRelease(self, event):
        log.debug(function=self.onDraggableRelease, args=self.GetName())
        event.Skip(False)
        assert isinstance(event.obj, DraggableControl)
        if util.rectsOverlap(event.obj.GetScreenRect(), self.GetScreenRect()):
            event.obj.accept(self)
            self.__draggableOver__ = False
            self.Refresh()
        else:
            event.obj.reject()
            event.Skip(True)

    def onDraggableAccept(self, event):
        self.Refresh()

    def onPaint(self, event):
        event.Skip()
        dc = wx.PaintDC(self)
        self.draw(dc)

    def getLabel(self):
        lbl = """{name}({children})"""
        return lbl.format(name=self.GetName(),
                          children=len(self.GetChildren()))

    def draw(self, dc):
        if self.__draggableOver__:
            self.paintStyler.select("DraggableDropTarget:highlight", dc)
        else:
            if self.__mouseOver__:
                self.paintStyler.select("DraggableDropTarget:mouseOver", dc)
            else:
                self.paintStyler.select("DraggableDropTarget:normal", dc)
        w, h = self.GetClientSize()
        lbl = self.getLabel()
        tw, th = dc.GetTextExtent(lbl)
        tx, ty = (0.5 * (w - tw), (h - th - 5))
        dc.DrawText(lbl, tx, ty)
        dc.DrawRectangle(0, 0, w, h)
Beispiel #8
0
class PlayerWidget(wx.Panel):
    yummyIcon = None
    DEFAULTSIZE = (100, 12)

    def __init__(self, parent, player):
        super().__init__(parent,
                         size=PlayerWidget.DEFAULTSIZE,
                         style=wx.CLIP_CHILDREN)
        self.player = None

        if not PlayerWidget.yummyIcon:
            PlayerWidget.yummyIcon = wx.Bitmap(RESOURCES +
                                               "/yummy-icon-28-white.png")

        self.paintStyler = PaintStyler()
        self.Bind(wx.EVT_PAINT, self.onPaint)

        self.reset(player)

    def Destroy(self):
        self.set.unsubscribe("msg_object_modified", self)
        super().Destroy()

    def reset(self, player=None):
        if self.player:
            self.player.unsubscribe("msg_object_modified", self)
        self.player = player
        if self.player != None:
            self.player.subscribe(self, "msg_object_modified",
                                  self.onMsgPlayerModified)

    def playerInfo(self):
        return self.player.getName() + "(" + str(
            self.player.getPlate().getSize()) + ")"

    def onPaint(self, event):
        event.Skip()
        dc = wx.PaintDC(self)
        self.drawBackground(dc)
        self.drawFace(dc)

    def style(self):
        return "PlayerWidget:" + ("playing"
                                  if self.player.isPlayerTurn() else "waiting")

    def drawBackground(self, dc):
        self.paintStyler.select(self.style(), dc)
        w, h = self.GetClientSize()
        dc.DrawRoundedRectangle(1, 1, w - 1, h - 1, 3)

    def drawFace(self, dc):
        self.paintStyler.select(self.style(), dc)
        w, h = self.GetClientSize()
        #iw,ih = PlayerWidget.yummyIcon.GetSize()
        #dc.DrawBitmap(PlayerWidget.yummyIcon, 3, int(0.5*(h-ih)))
        txt = self.playerInfo()
        tw, th = dc.GetTextExtent(txt)
        tx, ty = (3, 0.5 * (h - th))
        dc.DrawText(txt, tx, ty)

    def onMsgPlayerModified(self, payload):
        #log.debug(function=self.onMsgPlayerModified, args=payload)
        self.Refresh()