Ejemplo n.º 1
0
def make_bitmap(lightness=1, saturation=1):
    '''Make the bitmap of the color wheel.'''
    bitmap = wx.EmptyBitmap(BIG_LENGTH, BIG_LENGTH)
    assert isinstance(bitmap, wx.Bitmap)
    dc = wx.MemoryDC(bitmap)
    
    dc.SetBrush(wx_tools.get_background_brush())
    dc.SetPen(wx.TRANSPARENT_PEN)
    dc.DrawRectangle(-5, -5, BIG_LENGTH + 10, BIG_LENGTH + 10)
    
    center_x = center_y = BIG_LENGTH // 2 
    background_color_rgb = wx_tools.wx_color_to_rgb(
        wx_tools.get_background_color()
    )
    
    for x, y in cute_iter_tools.product(xrange(BIG_LENGTH),
                                        xrange(BIG_LENGTH)):
        
        # This is a big loop so the code is optimized to keep it fast.
        
        rx, ry = (x - center_x), (y - center_y)
        distance = (rx ** 2 + ry ** 2) ** 0.5
        
        if (SMALL_RADIUS - AA_THICKNESS) <= distance <= \
           (BIG_RADIUS + AA_THICKNESS):
            
            angle = -math.atan2(rx, ry)
            hue = (angle + math.pi) / two_pi
            rgb = colorsys.hls_to_rgb(hue, lightness, saturation)
            
            if abs(distance - RADIUS) > HALF_THICKNESS:
                
                # This pixel requires some anti-aliasing.
                
                if distance < RADIUS:
                    aa_distance = SMALL_RADIUS - distance
                else: # distance > RADIUS
                    aa_distance = distance - BIG_RADIUS
                
                aa_ratio = aa_distance / AA_THICKNESS
                
                rgb = color_tools.mix_rgb(
                    aa_ratio,
                    background_color_rgb,
                    rgb
                )
                
            color = wx_tools.rgb_to_wx_color(rgb)
            pen = wx.Pen(color)
            dc.SetPen(pen)
            
            dc.DrawPoint(x, y)
        
    return bitmap
Ejemplo n.º 2
0
    def on_paint(self, event):
        '''Paint event handler.'''

        event.Skip()

        state = self.state
        dc = wx.BufferedPaintDC(self)

        dc.SetBackground(wx_tools.get_background_brush())
        dc.Clear()

        if state is None:
            return

        dc.SetBackgroundMode(wx.SOLID)
        dc.SetFont(self.font)

        ### Drawing servers: ##################################################
        #                                                                     #
        servers = state.servers

        for (i, server) in enumerate(servers):

            personality = server.personality

            name, light_color, dark_color = (personality.human_name,
                                             wx_tools.rgb_to_wx_color(
                                                 personality.light_color),
                                             wx_tools.rgb_to_wx_color(
                                                 personality.dark_color))

            x0 = 10 + 200 * i
            y0 = 10

            pen = wx.Pen(light_color, 5)
            dc.SetPen(pen)

            dc.SetBrush(wx.TRANSPARENT_BRUSH)

            dc.DrawRectanglePointSize((x0, y0), (180, 50))

            dc.SetTextBackground(light_color)
            dc.SetTextForeground(dark_color)

            dc.DrawText('Server %s' % name, x0, y0)

            client = server.current_client

            if client is None:
                dc.SetTextBackground('#d4d0c8')
                dc.SetTextForeground('#000000')
                dc.DrawText('Idle', x0 + 10, y0 + 22)

            else:

                client_personality = client.personality

                client_name, client_light_color, client_dark_color = (
                    client_personality.human_name,
                    wx_tools.rgb_to_wx_color(client_personality.light_color),
                    wx_tools.rgb_to_wx_color(client_personality.dark_color))

                dc.SetTextBackground(client_light_color)
                dc.SetTextForeground(client_dark_color)
                dc.DrawText(client_name, x0 + 10, y0 + 22)
        #                                                                     #
        ### Finished drawing servers. #########################################

        ### Drawing population: ###############################################
        #                                                                     #
        assert state.population.size == infinity

        dc.SetTextBackground('#d4d0c8')
        dc.SetTextForeground('#000000')

        dc.DrawTextList(['Population:', 'Infinite'], [(10, 70), (10, 89)])
        #                                                                     #
        ### Finished drawing population. ######################################

        ### Drawing waiting clients: ##########################################
        #                                                                     #
        dc.SetTextBackground('#d4d0c8')
        dc.SetTextForeground('#000000')

        dc.DrawText('Clients in queue:', 150, 70)

        waiting_clients = state.facility.waiting_clients

        dc.DrawTextList(
            textList=[
                client.personality.human_name for client in waiting_clients
            ],
            coords=[(150, 89 + (19 * i)) for i in range(len(waiting_clients))],
            foregrounds=[
                wx_tools.rgb_to_wx_color(client.personality.dark_color)
                for client in waiting_clients
            ],
            backgrounds=[
                wx_tools.rgb_to_wx_color(client.personality.light_color)
                for client in waiting_clients
            ])
Ejemplo n.º 3
0
    def on_paint(self, event):
        '''Paint event handler.'''
        
        event.Skip()
        
        state = self.state
        dc = wx.BufferedPaintDC(self)
        
        dc.SetBackground(wx_tools.get_background_brush())
        dc.Clear()
        
        if state is None:
            return
        
        dc.SetBackgroundMode(wx.SOLID)
        dc.SetFont(self.font)
        
        
        ### Drawing servers: ##################################################
        #                                                                     #
        servers = state.servers
        
        for (i, server) in enumerate(servers):

            personality = server.personality
            
            name, light_color, dark_color = (
                personality.human_name,
                wx_tools.rgb_to_wx_color(personality.light_color),
                wx_tools.rgb_to_wx_color(personality.dark_color)
            )
            
            x0 = 10 + 200 * i
            y0 = 10
            
            pen = wx.Pen(light_color, 5)
            dc.SetPen(pen)
            
            dc.SetBrush(wx.TRANSPARENT_BRUSH)
            
            dc.DrawRectanglePointSize((x0, y0), (180, 50))
            
            dc.SetTextBackground(light_color)
            dc.SetTextForeground(dark_color)
                        
            dc.DrawText('Server %s' % name, x0, y0)
            
            client = server.current_client
            
            if client is None:
                dc.SetTextBackground('#d4d0c8')
                dc.SetTextForeground('#000000')
                dc.DrawText('Idle', x0 + 10, y0 + 22)
            
            else:
                
                client_personality = client.personality
                
                client_name, client_light_color, client_dark_color = (
                    client_personality.human_name,
                    wx_tools.rgb_to_wx_color(client_personality.light_color),
                    wx_tools.rgb_to_wx_color(client_personality.dark_color)
                )
                
                dc.SetTextBackground(client_light_color)
                dc.SetTextForeground(client_dark_color)
                dc.DrawText(client_name, x0 + 10, y0 + 22)
        #                                                                     #
        ### Finished drawing servers. #########################################
                
        
        ### Drawing population: ###############################################
        #                                                                     #
        assert state.population.size == infinity
        
        dc.SetTextBackground('#d4d0c8')
        dc.SetTextForeground('#000000')
        
        dc.DrawTextList(['Population:', 'Infinite'], [(10, 70), (10, 89)])
        #                                                                     #
        ### Finished drawing population. ######################################
        
        
        ### Drawing waiting clients: ##########################################
        #                                                                     #
        dc.SetTextBackground('#d4d0c8')
        dc.SetTextForeground('#000000')
        
        dc.DrawText('Clients in queue:', 150, 70)
        
        waiting_clients = state.facility.waiting_clients
        
        dc.DrawTextList(
            textList=
                [client.personality.human_name for client in waiting_clients],
            coords=
                [(150, 89 + (19 * i)) for i in range(len(waiting_clients))],
            foregrounds=
                [wx_tools.rgb_to_wx_color(client.personality.dark_color) for
                 client in waiting_clients],
            backgrounds=
                [wx_tools.rgb_to_wx_color(client.personality.light_color) for
                 client in waiting_clients]
        )