Beispiel #1
0
def start(frame):
    ''' this function starts all canvas activities '''

    canvas = fc.NavCanvas(frame, backgroundColor='white', showStatusBar=True)

    # create the nodes
    node = canvas.create('Circle', 200, look=('white', 'green'), name='Circle')
    node2 = canvas.create('Text',
                          'My position, size and rotation do not change',
                          look=fc.FontLook(14),
                          position=(0, -50))
    node3 = canvas.create('Text',
                          'My position and size and do not change',
                          look=fc.FontLook(14),
                          position=(0, 0))
    node4 = canvas.create('Text',
                          'My size does not change',
                          look=fc.FontLook(14),
                          position=(0, +50),
                          parent=node)
    node5 = canvas.create('Text',
                          'My position does not change',
                          look=fc.FontLook(14),
                          position=(0, +100))

    # capture their screen space transform
    controller = fc.ScreenRelativeController(canvas.camera)
    controller.addNode(node2)
    controller.addNode(node3, ('position', 'scale'))
    controller.addNode(node4, ('scale', ))
    controller.addNode(node5, ('position', ))
    canvas.addController(controller)
def OnOpenFrame(evt):
    frame = wx.Frame(None,
                     -1,
                     'NavCanvas in wx.SplitterWindow',
                     size=(700, 500))
    splitter = wx.SplitterWindow(frame, -1, style=wx.SP_LIVE_UPDATE)
    panel_left = wx.Panel(splitter, -1)
    panel_left.SetBackgroundColour(wx.RED)

    canvas = fc.NavCanvas(splitter, backgroundColor='white')

    canvas.create('Circle',
                  150,
                  name='my first circle',
                  pos=(0, 0),
                  look=('white', 'black'))

    look = fc.LinearGradientLook('purple', (0, 0), 'white', (30, 0), 'pink')
    canvas.createRectangle((300, 300),
                           pos=(0, 0),
                           rotation=45,
                           look=look,
                           where='back')

    splitter.SplitVertically(panel_left, canvas.mainPanel, 10)
    splitter.SetMinimumPaneSize(50)

    frame.Show()
Beispiel #3
0
def start(frame):
    ''' this function starts all canvas activities '''

    canvas = fc.NavCanvas(frame, backgroundColor='white')

    canvas.create('Circle',
                  75,
                  name='my first circle',
                  pos=(0, 0),
                  look=('white', 'black'))

    look = fc.LinearGradientLook('purple', (0, 0), 'white', (30, 0), 'pink')
    canvas.createRectangle((300, 300),
                           pos=(0, 0),
                           rotation=45,
                           look=look,
                           where='back')

    # here come there camera parts
    print canvas.camera.position  # default position is (0, 0)
    print canvas.camera.rotation  # default 0
    print canvas.camera.zoom  # default 1

    print canvas.camera.transform.matrix  # a camera has a transform like any other nodee

    # you should almost never need these two properties:
    print canvas.camera.viewBox  # this is the part of the world that will be shown
    print canvas.camera.viewTransform  # the view-transform

    # now shift and rotate the camera a bit
    canvas.camera.rotation = 30
    canvas.camera.position += (100, 0)
Beispiel #4
0
def start(frame):
    ''' this function starts all canvas activities '''
    
    canvas = fc.NavCanvas( frame, backgroundColor = 'white', showStatusBar = True, max_update_delay = 0.03 )

    # create the untransformed bitmap
    RevenueDataVisualizer( getFullPath('revenue_data.txt'), getFullPath('world_map_simple.gif'), canvas, 0.03 )
    canvas.zoomToExtents()
    canvas.camera.zoom *= ( 0.8, 0.8 )
Beispiel #5
0
def start(frame):
    ''' this function starts all canvas activities '''

    canvas = fc.NavCanvas(frame, backgroundColor='white')
    canvas.create('Text',
                  'Simply left-click and drag to create lines',
                  look=fc.FontLook(size=15, faceName='Arial', colour='black'))
    canvas.zoomToExtents()
    lineDrawer = LineDrawer(canvas)
Beispiel #6
0
def start(frame):
    ''' this function starts all canvas activities '''
        
    # Let's create a canvas, in this case a NavCanvas
    #from wx.lib.floatcanvas.floatcanvas2.floatcanvas.canvas.renderPolicies import DefaultRenderPolicy
    #canvas = fc.NavCanvas( frame, backgroundColor = 'white', renderPolicy = DefaultRenderPolicy() )
    canvas = fc.NavCanvas( frame, backgroundColor = 'white' )
    
    f = file('lion.svg', 'r')
    importer = SimpleSVGImporter( f.read(), canvas )
    canvas.zoomToExtents()
Beispiel #7
0
def start(frame):
    ''' this function starts all canvas activities '''

    # Let's create a canvas, in this case a NavCanvas
    canvas = fc.NavCanvas(frame, backgroundColor='white')

    circle = canvas.create('Circle',
                           75,
                           name='my first circle',
                           pos=(2, 0),
                           scale=(5, 3),
                           rotation=30,
                           look=('white', 'pink'))

    # show how to access the different transform properties

    print circle.pos
    print circle.position
    print circle.translation
    print circle.rotation
    print circle.scale
    print circle.transform
    print circle.transform.matrix

    circle.pos = (4, 5)
    circle.position = (9, 7)
    circle.translation = (1, 2)
    circle.rotation = 12
    circle.scale = (2, 2)

    print circle.pos
    print circle.position
    print circle.translation
    print circle.rotation
    print circle.scale
    print circle.transform
    print circle.transform.matrix

    pi = 3.14
    half_pi = pi / 2.0
    lines = canvas.create('Lines', [(0, -half_pi), (-half_pi, 0), (0, half_pi),
                                    (half_pi, 0), (0, -half_pi)],
                          name='mercator test',
                          transform='MercatorTransform',
                          look=('black', None),
                          where='front')
    print lines.transform
    lines.scale = (1, 0.2)

    canvas.zoomToExtents()
Beispiel #8
0
def start(frame):
    ''' this function starts all canvas activities '''

    canvas = fc.NavCanvas(frame, backgroundColor='white')

    group = canvas.create('Group', name='Parent of the group')

    look = fc.LinearGradientLook('purple', (-50, 0), 'black', (50, 0), 'green')
    rect = canvas.createRectangle((50, 50),
                                  pos=(0, 0),
                                  rotation=45,
                                  look=look,
                                  parent=group)
    circle1 = canvas.createCircle(50,
                                  pos=(0, 0),
                                  rotation=45,
                                  look=fc.OutlineLook('blue',
                                                      style='long_dash'),
                                  parent=group)

    # rectangle and circle are in the group now. let's scale the group parent
    # which will scale circle and rectangle
    group.scale = (3, 0.5)
    print rect.localTransform.scale
    print rect.worldTransform.scale

    # instead of the "Group" node, any other kind of node can serve as a group
    # as well
    circle2 = canvas.createCircle(5,
                                  pos=(30, 0),
                                  scale=(2, 1),
                                  look=look,
                                  parent=circle1)

    # now the hierarchy looks like:
    #
    # canvas
    #  |__group
    #       |____rect
    #       |____circle 1
    #                |_____circle2

    print circle2.worldTransform.pos

    # check some of the tree-related functionality of the circle node2
    print circle2.root is canvas
    print circle1.children == [circle2]
    print circle2.parent == circle1

    canvas.zoomToExtents()
Beispiel #9
0
def start(frame):
    ''' this function starts all canvas activities '''

    # Let's create a canvas, in this case a NavCanvas
    canvas = fc.NavCanvas(frame, backgroundColor='white')

    # setup the canvas
    look = fc.RadialGradientLook('red', (0, 0), (255, 0, 0, 128), (0, 0), 150,
                                 (255, 255, 0, 128))
    look2 = fc.RadialGradientLook(None, (0, 0), (0, 255, 255, 128), (0, 0),
                                  250, (255, 255, 255, 0))

    circle = canvas.create('Circle',
                           75,
                           name='circle',
                           pos=(200, 40),
                           look=look)
    rect = canvas.createRectangle((200, 200),
                                  name='rectangle',
                                  pos=(0, 0),
                                  rotation=0,
                                  look=('brown', (0, 255, 0, 128)))
    poly = canvas.create('Polygon', [(0, 0), (137, 12), (42, 123), (50, 70),
                                     (54, 52)],
                         name='polygon',
                         pos=(-40, -250),
                         look=look2)

    canvas.zoomToExtents()

    # render hereso we get something on screen
    canvas.Render()

    # save the canvas to the native format
    # The save to /load from disk calls are commented here, because the demo
    # should not write unconditionally to your disk. If you want to save
    # something, use the save button of the navCanvas. It uses the same
    # mechanisms as shown here internally.

    fcsf_data = canvas.serialize('fcsf')
    svg_data = canvas.serialize('svg')
    jpg_data = canvas.getScreenshot('jpg')
    #canvas.serializeToFile( 'saved_canvas.fcsf' )
    #canvas.serializeToFile( 'example.svg' )
    #canvas.saveScreenshot( 'screenshot.png' )

    # the two loading function
    canvas.unserialize(fcsf_data, 'fcsf')
Beispiel #10
0
def start(frame):
    ''' this function starts all canvas activities '''
        
    # Let's create a canvas, in this case a NavCanvas
    canvas = fc.NavCanvas( frame, backgroundColor = 'white' )
    
    # Add a circle with radius 75 to the canvas, give it a name and set its
    # position to (0,0). Then make the outline white and the inner part black.
    canvas.create( 'Circle', 75, name = 'my first circle', pos = (0, 0), look = ('white', 'black') )

    # Create a look to make our next shape a bit prettier.
    # Don't worry if you don't understand the parameters here. The "Looks" part
    # of the tutorial will explain this in detail.
    look =  fc.LinearGradientLook( 'purple', (0,0), 'white', (30, 0), 'pink' )

    # Now we'll add a rectangle of size (250, 250). That's actually a square.
    # The center of the rectangle will be placed at (0,0).
    # Additionally the rectangle will be rotated by 45 degrees and the look
    # we've created in the line above will be assigned.
    canvas.createRectangle( (250, 250), pos = (0, 0), rotation = 45, look = look, where = 'back' )
Beispiel #11
0
def start(frame):
    ''' this function starts all canvas activities '''

    # Let's create a canvas, in this case a NavCanvas
    canvas = fc.NavCanvas(frame, backgroundColor='white')

    # create our custom transform
    transform = SwirlTransform((100, 100), 0.003)

    # now create two grids, one untransformed and one with our swirl transform applied
    totalSize = (200, 200)
    noRectangles = (10, 10)

    grid1 = createRectangleGrid('Untransformed', canvas, totalSize,
                                noRectangles, ('black', None))
    grid2 = createRectangleGrid('Custom swirl transform', canvas, totalSize,
                                noRectangles, ('red', None), transform)
    grid2.position = (totalSize[0] * 1.5, 0)

    canvas.zoomToExtents()
Beispiel #12
0
def start(frame):
    ''' this function starts all canvas activities '''
    
    canvas = fc.NavCanvas( frame, backgroundColor = 'white', showStatusBar = True )

    # setup the canvas
    look = fc.RadialGradientLook( 'red', (0,0), (255,0,0,128), (0,0), 150, (255,255,0,128) )
    look2 = fc.RadialGradientLook( None, (0,0), (0,255,255,128), (0,0), 250, (255,255,255,0) )
    
    poly = canvas.create( 'Polygon', [ (0,0), (137,12), (42,123), (50,70), (54,52) ], name = 'polygon', pos = (-40, -250), look = look2 )
    circle = canvas.create( 'Circle', 75, name = 'circle', pos = (100, 80), look = look )
    rect = canvas.createRectangle( (200, 200), name = 'rectangle', pos = (0, 0), rotation = 0, look = ('brown', (0,255,0,128)) )
    text = canvas.create( 'Text', "I can't be moved!", name = 'text', pos = (0, 0), look = fc.TextLook(14, colour = ( 0, 0, 0, 100 ), background_fill_look = fc.SolidColourLook(None, None)), parent = rect )
    rect.moveable = False

    canvas.zoomToExtents()

    # replace default move tool with our own
    for mode_description in canvas.mode_descriptions:
        if mode_description.name == 'Move':
            mode_description.guiMode = MyMoveNodeMode( [text] )
Beispiel #13
0
def start(frame):
    ''' this function starts all canvas activities '''

    # set background to None, so the background will not be cleared as we draw it ourselves
    canvas = fc.NavCanvas( frame, backgroundColor = None, showStatusBar = True )

    # create the bitmap and enlarge it to whole screen
    background = canvas.create( 'Bitmap', wx.Image('../../../../data/background.png'), look = fc.NoLook, name = 'Bitmap' )
    canvas.zoomToExtents( padding_percent = 0, maintain_aspect_ratio = False )    

    # capture screen space transforn of the bitmap
    controller = fc.ScreenRelativeController( canvas.camera )
    controller.addNode( background, rescaleOnResize = True )
    canvas.addController( controller )

    # create regular foreground objects
    canvas.create( 'Circle', 10, look = ('black', (255,128,0,196)), position = (0, 0) )
    canvas.create( 'RoundedRectangle', (15, 5), 1, look = ('black', 'white'), position = (0, 0) )
    canvas.create( 'Text', 'Try to pan and zoom', look = fc.TextLook( 14, colour = (0,0,0,128), background_fill_look = fc.SolidColourLook(None, None) ), position = (0, 40) )

    canvas.zoomToExtents()
Beispiel #14
0
def start(frame):
    ''' this function starts all canvas activities '''

    # Let's create a canvas, in this case a NavCanvas
    canvas = fc.NavCanvas(frame, backgroundColor='white')

    # Create a group with render_to_surface enabled. This means all of the group's
    # children will be rendered to a bitmap which is used in subsequent draws.
    group = canvas.create('Group',
                          name='Parent of the group',
                          render_to_surface=True,
                          surface_size=(600, 300))

    look = fc.LinearGradientLook('purple', (-50, 0), 'black', (50, 0), 'green')
    # Create 100 circles here and add them to the group
    for i in range(100):
        circle = canvas.createCircle(50,
                                     name='circle %d' % i,
                                     pos=(i * 10, i * 10),
                                     look=look,
                                     parent=group)

    canvas.zoomToExtents()
Beispiel #15
0
def start(frame):
    ''' this function starts all canvas activities '''

    canvas = fc.NavCanvas(frame, backgroundColor='white')

    toucanImg = wx.Image('toucan.png')
    toucanData = fc.arrayFromImage(toucanImg)
    toucanBitmap = wx.BitmapFromImage(toucanImg.AdjustChannels(0, 2, 0, 1))

    # draw a 5x5 grid with the primitives

    canvas.create('Rectangle', (100, 100), pos=(0, 0), look=('red', 'blue'))
    canvas.create('Circle', 25, pos=(100, 0), look=('red', 'blue'))
    canvas.create('Ellipse', (50, 25), pos=(200, 0), look=('red', 'blue'))
    canvas.create('RoundedRectangle', (100, 100),
                  30,
                  pos=(300, 0),
                  look=('red', 'blue'))
    canvas.create('Text',
                  'FloatCanvas',
                  pos=(400, 0),
                  look=fc.FontLook(size=15, faceName='Arial', colour='red'))

    canvas.create('Line', (0, 0), (50, 50), pos=(0, 100), look=('red', 'blue'))
    canvas.create('LineLength', 50, pos=(100, 100), look=('red', 'blue'))
    canvas.create('Lines', [(0, 0), (20, 30), (90, 70), (10, -20)],
                  pos=(200, 100),
                  look=('red', 'blue'))
    canvas.create('LinesList',
                  [[(146, 399), (163, 403), (170, 393), (169, 391), (166, 386),
                    (170, 381), (170, 371), (170, 355), (169, 346), (167, 335),
                    (170, 329), (170, 320), (170, 310), (171, 301), (173, 290),
                    (178, 289), (182, 287), (188, 286), (190, 286), (192, 291),
                    (194, 296), (195, 305), (194, 307), (191, 312), (190, 316),
                    (190, 321), (192, 331), (193, 338), (196, 341), (197, 346),
                    (199, 352), (198, 360), (197, 366), (197, 373), (196, 380),
                    (197, 383), (196, 387), (192, 389), (191, 392), (190, 396),
                    (189, 400), (194, 401), (201, 402), (208, 403), (213, 402),
                    (216, 401), (219, 397), (219, 393), (216, 390), (215, 385),
                    (215, 379), (213, 373), (213, 365), (212, 360), (210, 353),
                    (210, 347), (212, 338), (213, 329), (214, 319), (215, 311),
                    (215, 306), (216, 296), (218, 290), (221, 283), (225, 282),
                    (233, 284), (238, 287), (243, 290), (250, 291), (255, 294),
                    (261, 293), (265, 291), (271, 291), (273, 289), (278, 287),
                    (279, 285), (281, 280), (284, 278), (284, 276), (287, 277),
                    (289, 283), (291, 286), (294, 291), (296, 295), (299, 300),
                    (301, 304), (304, 320), (305, 327), (306, 332), (307, 341),
                    (306, 349), (303, 354), (301, 364), (301, 371), (297, 375),
                    (292, 384), (291, 386), (302, 393), (324, 391), (333, 387),
                    (328, 375), (329, 367), (329, 353), (330, 341), (331, 328),
                    (336, 319), (338, 310), (341, 304), (341, 285), (341, 278),
                    (343, 269), (344, 262), (346, 259), (346, 251), (349, 259),
                    (349, 264), (349, 273), (349, 280), (349, 288), (349, 295),
                    (349, 298), (354, 293), (356, 286), (354, 279), (352, 268),
                    (352, 257), (351, 249), (350, 234), (351, 211), (352, 197),
                    (354, 185), (353, 171), (351, 154), (348, 147), (342, 137),
                    (339, 132), (330, 122), (327, 120), (314, 116), (304, 117),
                    (293, 118), (284, 118), (281, 122), (275, 128), (265, 129),
                    (257, 131), (244, 133), (239, 134), (228, 136), (221, 137),
                    (214, 138), (209, 135), (201, 132), (192, 130), (184, 131),
                    (175, 129), (170, 131), (159, 134), (157, 134), (160, 130),
                    (170, 125), (176, 114), (176, 102), (173, 103), (172, 108),
                    (171, 111), (163, 115), (156, 116), (149, 117), (142, 116),
                    (136, 115), (129, 115), (124, 115), (120, 115), (115, 117),
                    (113, 120), (109, 122), (102, 122), (100, 121), (95, 121),
                    (89, 115), (87, 110), (82, 109), (84, 118), (89, 123),
                    (93, 129), (100, 130), (108, 132), (110, 133), (110, 136),
                    (107, 138), (105, 140), (95, 138), (86, 141), (79, 149),
                    (77, 155), (81, 162), (90, 165), (97, 167), (99, 171),
                    (109, 171), (107, 161), (111, 156), (113, 170), (115, 185),
                    (118, 208), (117, 223), (121, 239), (128, 251), (133, 259),
                    (136, 266), (139, 276), (143, 290), (148, 310), (151, 332),
                    (155, 348), (156, 353), (153, 366), (149, 379), (147, 394),
                    (146, 399)],
                   [(156, 141), (165, 135), (169, 131), (176, 130), (187, 134),
                    (191, 140), (191, 146), (186, 150), (179, 155), (175, 157),
                    (168, 157), (163, 157), (159, 157), (158, 164), (159, 175),
                    (159, 181), (157, 191), (154, 197), (153, 205), (153, 210),
                    (152, 212), (147, 215), (146, 218), (143, 220), (132, 220),
                    (125, 217), (119, 209), (116, 196), (115, 185), (114, 172),
                    (114, 167), (112, 161), (109, 165), (107, 170), (99, 171),
                    (97, 167), (89, 164), (81, 162), (77, 155), (81, 148),
                    (87, 140), (96, 138), (105, 141), (110, 136), (111, 126),
                    (113, 129), (118, 117), (128, 114), (137, 115), (146, 114),
                    (155, 115), (158, 121), (157, 128), (156, 134), (157, 136),
                    (156, 136)]],
                  pos=(200, 400),
                  look=('red', 'blue'))
    canvas.create('LineSegments', [(0, 0), (20, 90), (40, 30), (90, 35)],
                  pos=(400, 100),
                  look=('red', 'blue'))

    canvas.create('LineSegmentsSeparate', [(0, 0), (40, 30)], [(20, 90),
                                                               (90, 35)],
                  pos=(0, 200),
                  look=('red', 'blue'))
    canvas.create('Bitmap', toucanData, pos=(100, 200), look=('red', 'blue'))
    canvas.create('Bitmap', toucanBitmap, pos=(200, 200), look=('red', 'blue'))
    canvas.create('Bitmap',
                  toucanData,
                  False,
                  pos=(300, 200),
                  scale=(50, 50),
                  look=('red', 'blue'))
    canvas.create('Arc',
                  75,
                  4.5,
                  1.5,
                  False,
                  pos=(400, 200),
                  look=('red', 'blue'))

    canvas.create('CubicSpline', [(0, 0), (90, 70), (90, 20), (0, 50)],
                  pos=(0, 300),
                  look=('red', 'blue'))
    canvas.create('QuadraticSpline', [(0, 0), (20, 50), (80, 0)],
                  pos=(100, 300),
                  look=('red', 'blue'))
    canvas.create('Arrow', (0, 0), (40, -20), (20, 10),
                  pos=(200, 300),
                  look=('red', 'blue'))
    canvas.create('AngleArrow', (0, 0),
                  50,
                  20, (30, 10),
                  pos=(300, 300),
                  look=('red', 'blue'))
    canvas.create('Polygon', [(0, 0), (20, 30), (90, 70), (10, -20)],
                  pos=(400, 300),
                  look=('red', 'blue'))

    canvas.create('PolygonList',
                  [[(0, 5), (50, 50),
                    (5, 0)], [(0, -5), (50, -50),
                              (5, 0)], [(0, -5), (-50, -50),
                                        (-5, 0)], [(0, 5), (-50, 50),
                                                   (-5, 0)]],
                  pos=(0, 400),
                  look=('red', 'blue'))

    canvas.zoomToExtents()
Beispiel #16
0
def start(frame):
    ''' this function starts all canvas activities '''

    # Let's create a canvas, in this case a NavCanvas
    #from wx.lib.floatcanvas.floatcanvas2.floatcanvas.canvas.renderPolicies import DefaultRenderPolicy
    #canvas = fc.NavCanvas( frame, backgroundColor = 'white', renderPolicy = DefaultRenderPolicy() )
    canvas = fc.NavCanvas(frame, backgroundColor='white')

    PieChartClass = canvas.registerModel('PieChart', PieChart,
                                         ('radius', 'values'))
    ## Todo
    ## # tell the canvas about our PieChart model and viewer
    ## canvas.registerModelAndView( 'PieChart', PieChart, ('radius', 'values'), True, PieChartVisualizer )

    colors = ['red', 'green', 'blue', 'yellow', 'cyan', 'magenta']
    looks = [
        fc.RadialGradientLook((128, 128, 128, 128), (10, 0),
                              (255, 255, 255, 160), (50, 0),
                              300,
                              color,
                              line_width=0.2) for color in colors
    ]
    labelLook = fc.TextLook(8,
                            colour=(0, 0, 0, 192),
                            background_fill_look=fc.SolidColourFillLook(None))
    threedFilter = fc.ThreeDFilter(sigma=100,
                                   kernel_size=(10, 10),
                                   offset=(0, 0),
                                   scale=(0.95, 0.95),
                                   surface_size=(100, 100),
                                   shadow_colour=(0, 0, 0, 128))

    pieChart = PieChartClass(100, [1, 3, 8, 5, 24, 9])
    pieNode = canvas.createGroup(filter=threedFilter)
    visualizer = PieChartVisualizer(pieChart, pieNode, looks, labelLook)

    ## Todo
    ## pieNode = canvas.createPieChart( 100, [1,3,8,5,24,9], filter = threedFilter, piece_looks = looks, label_look = labelLook, look = 'nolook' )
    ## # you could also do:
    ## # pieChart = PieChart( 100, [1,3,8,5,24,9] )
    ## # canvas.createFromModel( pieChart, filter = threedFilter, piece_looks = looks, label_look = labelLook )

    buttonLook = fc.LinearGradientLook('black', (-50, -50), (0, 0, 255, 128),
                                       (50, 50), (128, 128, 255, 0))
    shadowFilter = fc.ShadowFilter(sigma=3,
                                   kernel_size=(8, 8),
                                   offset=(3, 3),
                                   surface_size=(100, 100),
                                   shadow_colour=(0, 0, 255, 128))
    rect = canvas.createRoundedRectangle((60, 30),
                                         15,
                                         look=buttonLook,
                                         pos=(200, 0),
                                         filter=shadowFilter)
    threedFilter = fc.ThreeDFilter(sigma=100,
                                   kernel_size=(10, 10),
                                   offset=(0, 0),
                                   scale=(0.95, 0.95),
                                   surface_size=(100, 100),
                                   shadow_colour=(0, 0, 0, 128))
    text = canvas.createText('Change!',
                             look=labelLook,
                             parent=rect,
                             filter=threedFilter)

    def changeModel(event):
        import random
        no_slices = random.randint(1, 8)
        pieChart.values = [random.randint(0, 666) for i in range(no_slices)]

    rect.subscribe(changeModel, 'left_down')

    canvas.zoomToExtents()
Beispiel #17
0
def start(frame):
    ''' this function starts all canvas activities '''

    # Let's create a canvas, in this case a NavCanvas
    canvas = fc.NavCanvas(frame, backgroundColor='white')

    # setup the canvas
    look = fc.RadialGradientLook('red', (0, 0), (255, 0, 0, 128), (0, 0), 150,
                                 (255, 255, 0, 128))
    look2 = fc.RadialGradientLook(None, (0, 0), (0, 255, 255, 128), (0, 0),
                                  250, (255, 255, 255, 0))

    circle = canvas.create('Circle',
                           75,
                           name='circle',
                           pos=(200, 40),
                           look=look)
    rect = canvas.createRectangle((200, 200),
                                  name='rectangle',
                                  pos=(0, 0),
                                  rotation=0,
                                  look=('brown', (0, 255, 0, 128)))
    poly = canvas.create('Polygon', [(0, 0), (137, 12), (42, 123), (50, 70),
                                     (54, 52)],
                         name='polygon',
                         pos=(-40, -250),
                         look=look2)
    text = canvas.create(
        'Text',
        'Click me!',
        name='text',
        pos=(0, 0),
        look=fc.TextLook(14,
                         colour=(0, 0, 0, 128),
                         background_fill_look=fc.SolidColourLook(None, None)),
        parent=rect)

    # now we start all the event-related things

    # the event handler print some information and rotates the rectangle upon
    #  each click
    def onRectangleClicked(event):
        print event.coords, [node.name for node in event.nodes]
        print type(event.wx_event), event.wx_event.GetPosition()
        rect.rotation += 21

    # bind an event handler to the 'left_down' event of the rect shape
    rect.subscribe(onRectangleClicked, 'left_down')

    # now bind all other kinds of events to the other nodes

    # a generic event handler, printing some info
    def onEvent(event):
        print '%s event on nodes %s @ %s' % (
            event.type, [node.name
                         for node in event.nodes], event.coords.world)

    # nodes which we want to watch
    nodes = [circle, rect, poly]

    # events to bind (all except 'move')
    events = [
        'left_down',
        'left_dclick',
        'left_up',
        'middle_down',
        'middle_dclick',
        'middle_up',
        'right_down',
        'right_dclick',
        'right_up',
        'wheel',
        'key_down',
        'key_up',
    ]

    # bind all events
    for node in nodes:
        for event in events:
            node.subscribe(onEvent, event)

    # bind the motion event only to the polygon so the event output doesn't
    #  litter everything
    poly.subscribe(onEvent, 'move')

    canvas.zoomToExtents()
Beispiel #18
0
def start(frame):
    ''' this function starts all canvas activities '''

    canvas = fc.NavCanvas(frame, backgroundColor='white')

    looks = \
    [
        # some looks
        fc.RadialGradientLook( 'red', (0,0), 'red', (0,0), 50, 'yellow' ),
        fc.LinearGradientLook( 'purple', (0,0), 'white', (50,50), 'pink' ),
        fc.OutlineLook( line_colour = 'blue', width = 10, style = 'user_dash', dashes = [1,1] ),
        fc.SolidColourLook( line_colour = 'green', fill_colour = 'red' ),

        # no lines and some transparent colors
        fc.RadialGradientLook( None, (0,0), (0,255,255,128), (0,0), 50, (255,255,255,0) ),
        fc.LinearGradientLook( None, (-50,-50), (0,0,255,255), (50,50), (128,128,255,0) ),
        fc.SolidColourLook( line_colour = None, fill_colour = 'red' ),
        fc.SolidColourLook( line_colour = 'green', fill_colour = None ),

        # some more exotic lines
        fc.RadialGradientLook( 'pink', (0,0), (0,255,0,128), (0,0), 150, (255,0,255,200), line_style = 'dot', line_width = 10, line_cap = 'butt', line_join = 'bevel' ),
        fc.LinearGradientLook( 'red', (-5,-5), 'orange', (5,5), 'blue', line_style = 'long_dash', line_width = 5 ),
        fc.SolidColourLook( line_colour = 'green', fill_colour = 'red', line_style = 'solid', line_width = 13, line_cap = 'projecting', line_join = 'miter' ),
        fc.SolidColourLook( line_colour = 'black', fill_colour = 'red', line_style = 'solid', line_width = 13, line_cap = 'projecting', line_join = 'round' ),
    ]

    thingy = [(0, 50), (50, 0), (-50, 0), (0, -50)]

    # create primitives with looks on the,
    for i, look in enumerate(looks):
        r = canvas.create('Rectangle', (100, 100),
                          name='r%d' % i,
                          pos=(i * 110, 0),
                          look=look)
        rr = canvas.create('RoundedRectangle', (100, 100),
                           30,
                           name='r%d' % i,
                           pos=(i * 110, 200),
                           look=look)
        c = canvas.create('Circle',
                          50,
                          name='r%d' % i,
                          pos=(i * 110, 400),
                          look=look)
        e = canvas.create('Ellipse', (100, 75),
                          name='r%d' % i,
                          pos=(i * 110, 600),
                          look=look)
        l = canvas.create('Lines',
                          thingy,
                          name='r%d' % i,
                          pos=(i * 110, 800),
                          look=look)
        p = canvas.create('Polygon',
                          thingy,
                          name='r%d' % i,
                          pos=(i * 110, 1000),
                          look=look)

    canvas.zoomToExtents()

    svg_data = canvas.serialize('svg')
Beispiel #19
0
def start(frame):
    ''' this function starts all canvas activities '''

    # Let's create a canvas, in this case a NavCanvas
    canvas = fc.NavCanvas(frame, backgroundColor='white')

    settings = [
        (5, (5, 5), (5, 5)),
        (1, (5, 5), (5, 5)),
        (5, (20, 20), (5, 5)),
        (20, (20, 20), (5, 5)),
        (5, (5, 5), (10, 10)),
        (1, (5, 5), (10, 10)),
        (5, (20, 20), (10, 10)),
    ]

    for i, setting in enumerate(settings):
        sigma, kernel_size, offset = setting

        x = i * 200

        # create the filters
        blurFilter = fc.GaussianBlurFilter(sigma=sigma,
                                           kernel_size=kernel_size,
                                           surface_size=(100, 100))
        shadowFilter = fc.ShadowFilter(sigma=sigma,
                                       kernel_size=kernel_size,
                                       offset=offset,
                                       shadow_colour=(0, 0, 0, 128),
                                       surface_size=(100, 100))
        greenShadowFilter = fc.ShadowFilter(sigma=sigma,
                                            kernel_size=kernel_size,
                                            offset=offset,
                                            shadow_colour=(0, 128, 255, 128),
                                            surface_size=(100, 100))
        glowFilter = fc.GlowFilter(sigma=100,
                                   kernel_size=(10, 10),
                                   glow_colour=(255, 255, 0, 128),
                                   scale=(1.3, 1.3),
                                   surface_size=(100, 100))
        threeDFilter = fc.ThreeDFilter(sigma=100,
                                       kernel_size=(10, 10),
                                       offset=(-3, -3),
                                       scale=(0.95, 0.95),
                                       surface_size=(100, 100),
                                       shadow_colour=(0, 0, 0, 128))
        pixelizeFilter = fc.PixelizeFilter(block_size=(5, 5),
                                           surface_size=(100, 100))

        radialLook = fc.RadialGradientLook('red', (0, 0), 'red', (0, 0), 100,
                                           'yellow')
        blue_red = fc.SolidColourLook(line_colour='blue', fill_colour='red')

        r1 = canvas.create('Rectangle', (100, 100),
                           name='r1',
                           pos=(x, 0),
                           look=blue_red,
                           filter=blurFilter)
        rr1 = canvas.create('RoundedRectangle', (100, 100),
                            30,
                            name='rr1',
                            pos=(x, 150),
                            look=blue_red,
                            filter=shadowFilter)
        e1 = canvas.create('Ellipse', (100, 70),
                           name='e1',
                           pos=(x, 300),
                           look=('black', 'black'),
                           filter=greenShadowFilter)
        c1 = canvas.create('Circle',
                           50,
                           name='c1',
                           pos=(x, 450),
                           look=radialLook,
                           filter=glowFilter)
        rr2 = canvas.create('RoundedRectangle', (100, 100),
                            30,
                            name='rr2',
                            pos=(x, 600),
                            look=(None, 'red'),
                            filter=threeDFilter)
        t1 = canvas.create('Polygon', [(-50, 50), (50, 50), (0, -50)],
                           name='t1',
                           pos=(x, 750),
                           rotation=45,
                           look=blue_red,
                           filter=pixelizeFilter)

    canvas.zoomToExtents()