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()
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)
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()
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' )
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()
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')
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()