Beispiel #1
0
    def on_paint(self, event):
        '''Refresh the tree browser.'''

        event.Skip()

        # todo: optimize so it groks the tree only when needed.

        self.tree_remapping_flag = False
        self.recalculation_flag = False
        # todo: now we just lower these flags retardedly, in future there will
        # be __recalculate

        if self.gui_project is None or \
           self.gui_project.project.tree is None or \
           len(self.gui_project.project.tree.roots) == 0:

            return

        dc = NiftyPaintDC(self, self.gui_project,
                          self.CalcScrolledPosition((0, 0)), self)

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

        (self.clickable_map, (width, height)) = \
            dc.draw_tree(self.gui_project.project.tree)

        dc.Destroy()  # This weird dc requires destroying

        self.SetVirtualSize((width, height))
Beispiel #2
0
    def on_paint(self, event):
        '''Refresh the tree browser.'''

        event.Skip()
        
        # todo: optimize so it groks the tree only when needed.
        
        self.tree_remapping_flag = False
        self.recalculation_flag = False
        # todo: now we just lower these flags retardedly, in future there will
        # be __recalculate
        
        if self.gui_project is None or \
           self.gui_project.project.tree is None or \
           len(self.gui_project.project.tree.roots) == 0:
            
            return

        dc = NiftyPaintDC(self, self.gui_project,
                          self.CalcScrolledPosition((0, 0)), self)
        
        dc.SetBackground(wx_tools.get_background_brush())
        dc.Clear()
        
        (self.clickable_map, (width, height)) = \
            dc.draw_tree(self.gui_project.project.tree)
        
        dc.Destroy() # This weird dc requires destroying
        
        self.SetVirtualSize((width,height))
Beispiel #3
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
Beispiel #4
0
 def on_paint(self, event):
     '''Paint event handler.'''
     event.Skip()
     dc = wx.BufferedPaintDC(self)
             
     dc.SetBackground(wx_tools.get_background_brush())
     dc.Clear()
     
     dc.SetBrush(wx.Brush("white", wx.TRANSPARENT))
     for [side, pos] in [[self.left, (100, 100)], [self.right, (300, 100)]]:
         
         dc.SetPen(wx.Pen("black", 2))
         dc.DrawCirclePoint(pos, self.radius)
         
         if side is not None:
             point = (pos[0] + math.cos(side) * self.radius,
                      pos[1] + math.sin(side) * self.radius)
             dc.SetPen(wx.Pen("red", 20))
             dc.DrawLinePoint(point, point)
Beispiel #5
0
 def on_paint(self, event):
     '''Paint event handler.'''
     
     event.Skip()
     
     (w, h) = self._get_size_from_board()
     self.SetVirtualSize((w, h))
     
     if self.redraw_needed_flag is True:
         self._draw_buffer_bitmap()
         self.redraw_needed_flag = False
             
     dc = wx.BufferedPaintDC(self)
     
     dc.SetBackground(wx_tools.get_background_brush())
     dc.Clear()
     
     dc.DrawBitmapPoint(self._buffer_bitmap,
                        self.CalcScrolledPosition((0, 0)))
Beispiel #6
0
    def on_paint(self, event):
        '''Paint event handler.'''
        event.Skip()
        dc = wx.BufferedPaintDC(self)

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

        dc.SetBrush(wx.Brush("white", wx.TRANSPARENT))
        for [side, pos] in [[self.left, (100, 100)], [self.right, (300, 100)]]:

            dc.SetPen(wx.Pen("black", 2))
            dc.DrawCirclePoint(pos, self.radius)

            if side is not None:
                point = (pos[0] + math.cos(side) * self.radius,
                         pos[1] + math.sin(side) * self.radius)
                dc.SetPen(wx.Pen("red", 20))
                dc.DrawLinePoint(point, point)
Beispiel #7
0
    def on_paint(self, event):
        '''Paint event handler.'''

        event.Skip()

        (w, h) = self._get_size_from_board()
        self.SetVirtualSize((w, h))

        if self.redraw_needed_flag is True:
            self._draw_buffer_bitmap()
            self.redraw_needed_flag = False

        dc = wx.BufferedPaintDC(self)

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

        dc.DrawBitmapPoint(self._buffer_bitmap,
                           self.CalcScrolledPosition((0, 0)))
Beispiel #8
0
    def on_paint(self, event):
        """EVT_PAINT handler."""

        # Not checking for recalculation flag, this widget is not real-time
        # enough to care about the delay.

        dc = wx.BufferedPaintDC(self)

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

        w, h = self.GetClientSize()

        gc = wx.GraphicsContext.Create(dc)

        gc.SetPen(wx.TRANSPARENT_PEN)
        gc.SetBrush(self._knob_house_brush)

        assert isinstance(gc, wx.GraphicsContext)
        gc.Translate(w / 2, h / 2)
        gc.Rotate(self.current_angle)
        gc.DrawEllipse(-13.5, -13.5, 27, 27)
        gc.DrawBitmap(self.original_bitmap, -13, -13, 26, 26)
Beispiel #9
0
    def on_paint(self, event):
        '''EVT_PAINT handler.'''

        # Not checking for recalculation flag, this widget is not real-time
        # enough to care about the delay.

        dc = wx.BufferedPaintDC(self)

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

        w, h = self.GetClientSize()

        gc = wx.GraphicsContext.Create(dc)

        gc.SetPen(wx.TRANSPARENT_PEN)
        gc.SetBrush(self._knob_house_brush)

        assert isinstance(gc, wx.GraphicsContext)
        gc.Translate(w / 2, h / 2)
        gc.Rotate(self.current_angle)
        gc.DrawEllipse(-13.5, -13.5, 27, 27)
        gc.DrawBitmap(self.original_bitmap, -13, -13, 26, 26)
Beispiel #10
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
            ])
Beispiel #11
0
    def on_paint(self, event):
        '''Refresh the seek-bar.'''
        event.Skip()
        

        self.view_changed_flag = False
        self.active_node_changed_or_modified_flag = False
        self.path_contents_changed_flag = False
        # todo: now we just lower these flags retardedly, in future there will
        # be __recalculate
        
        occupied_region = wx.Region()

        if (self.gui_project is None) or (self.gui_project.path is None):
            return
        
        (w, h) = self.GetSize()
        start = self.start
        end = self.start + (w / self.zoom)
        dc = wx.BufferedPaintDC(self)

        dc.SetBackground(wx_tools.get_background_brush())
        dc.Clear()
        
        #dc.DrawRectangle(3,3,50,90)
        if self.gui_project.path is not None: # Draw rect for renedered segment
            seg = self.gui_project.path.get_existing_time_segment(start, end)
            if seg is not None:
                dc.SetPen(wx.Pen('#000000'))
                dc.SetBrush(wx.Brush('#FFFFB8'))
                sseg = [self.screenify(thing) for thing in seg]
                dc.DrawRectangle(sseg[0], 0, sseg[1]-sseg[0], h-4)
                occupied_region = wx.Region(sseg[0] + 1, 1,
                                            sseg[1] - sseg[0] - 2,
                                            h - 6)

        active = self.gui_project.active_node
        if active is not None:
            active_start = active.state.clock
            try:
                after_active = self.gui_project.path.next_node(active)
                active_end = after_active.state.clock
            except garlicsim.data_structures.path.PathOutOfRangeError:
                after_active = None
                active_end = active_start
            active_inside = False
            screen_active_start = start
            screen_active_end = end

            if start <= active_start <= end:
                active_inside = True
                screen_active_start = self.screenify(active_start)

            if start <= active_end <= end:
                active_inside = True
                screen_active_end = self.screenify(active_end)


            dc.SetBrush(wx.Brush('#FF9933'))
            dc.SetPen(wx.Pen('#000000', 1, wx.TRANSPARENT))
            if active_inside is True:
                dc.DrawRectangle(
                    math.floor(screen_active_start),
                    1,
                    math.ceil(screen_active_end-screen_active_start),
                    h-6)
                triangle_half_width = \
                    math.ceil(self.active_triangle_width / 2.0)
                dc.SetClippingRegionAsRegion(occupied_region)
                dc.DrawPolygon(
                        ((screen_active_start - triangle_half_width, h - 5),
                        (screen_active_start + triangle_half_width, h - 5),
                        (screen_active_start, h - 5 - triangle_half_width))
                    )
                dc.DestroyClippingRegion()




        # Draw ruler
        min = 15
        temp = math.ceil(math.log10(min / self.zoom))
        bigliners = get_lines(start, end, temp+1)
        presmallliners = get_lines(start, end, temp)
        smallliners = []
        for thing in presmallliners:
            if bigliners.count(thing) == 0:
                smallliners.append(thing)

        self.draw_small_numbers(dc, smallliners)
        self.draw_big_numbers(dc, bigliners)
Beispiel #12
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:
            dc.Destroy()
            return
        
        dc.SetBackgroundMode(wx.SOLID)
        dc.SetFont(self.font)
        

        
        
        #######################################################################
        ############  Draw servers:
        #######################################################################

        servers = state.servers
        
        for (i, server) in enumerate(servers):

            personality = server.identity.personality
            
            name, light_color, dark_color = (
                personality.human_name,
                make_wx_color(personality.light_color),
                make_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 ' + 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.identity.personality
                
                client_name, client_light_color, client_dark_color = (
                    client_personality.human_name,
                    make_wx_color(client_personality.light_color),
                    make_wx_color(client_personality.dark_color)
                )
                
                dc.SetTextBackground(client_light_color)
                dc.SetTextForeground(client_dark_color)
                dc.DrawText(client_name, x0 + 10, y0 + 22)
                
        
        
        
        #######################################################################
        ############  Draw population:
        #######################################################################

        assert state.population.size == Infinity
        
        dc.SetTextBackground('#d4d0c8')
        dc.SetTextForeground('#000000')
        
        dc.DrawTextList(['Population:', 'Infinite'], [(10, 70), (10, 89)])
        
        
        
        #######################################################################
        ############  Draw clients:
        #######################################################################
        
        dc.SetTextBackground('#d4d0c8')
        dc.SetTextForeground('#000000')
        
        dc.DrawText('Clients in queue:', 150, 70)
        
        personalities = [client.identity.personality for client in
                         state.facility.waiting_clients]
        
        names = []; background_colors = []; foreground_colors = []
        
        for personality in personalities:
            names.append(personality.human_name)
            background_colors.append(make_wx_color(personality.light_color))
            foreground_colors.append(make_wx_color(personality.dark_color))
        
        coords = [(150, 89 + (19 * i)) for i in range(len(personalities))]
        
        dc.DrawTextList(names, coords, foreground_colors, background_colors)
        

        
        dc.Destroy()
        """
Beispiel #13
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]
        )