def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas( self, ProjectionFun=None, BackgroundColor="DARK SLATE BLUE", ).Canvas Canvas.MaxScale = 20 # sets the maximum zoom level self.Canvas = Canvas FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) # create the image: image = wx.Image(ImageFile) self.width, self.height = image.GetSize() img = FloatCanvas.ScaledBitmap2(image, (0, 0), Height=image.GetHeight(), Position='tl', Quality='high') Canvas.AddObject(img) img.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.OnLeftDown) self.Canvas.Bind(wx.EVT_SIZE, self.OnSize) self.Show() Canvas.ZoomToBB(margin_adjust=1.0)
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas(self,-1, size = (500,500), ProjectionFun = None, Debug = 0, BackgroundColor = "DARK SLATE BLUE", ).Canvas Point = (45,40) Box = Canvas.AddCircle(Point, Diameter = 10, FillColor = "Black", LineColor = "Red", LineWidth = 6) # Crosses: Grid = FloatCanvas.DotGrid( Spacing=(1, .5), Size=2, Color="Cyan", Cross=True, CrossThickness=2) #Dots: #Grid = FloatCanvas.DotGrid( (0.5, 1), Size=3, Color="Red") Canvas.GridUnder = Grid #Canvas.GridOver = Grid FloatCanvas.EVT_MOTION(Canvas, self.OnMove ) self.Show() Canvas.ZoomToBB()
def __init__(self, parent, id, title, position, size): wx.Frame.__init__(self, parent, id, title, position, size) ## Set up the MenuBar MenuBar = wx.MenuBar() FileMenu = wx.Menu() OpenMenu = FileMenu.Append(wx.ID_ANY, "&Open", "Open BNA") self.Bind(wx.EVT_MENU, self.OpenBNA, OpenMenu) SaveMenu = FileMenu.Append(wx.ID_ANY, "&Save", "Save BNA") self.Bind(wx.EVT_MENU, self.SaveBNA, SaveMenu) CloseMenu = FileMenu.Append(wx.ID_ANY, "&Close", "Close Application") self.Bind(wx.EVT_MENU, self.OnQuit, CloseMenu) MenuBar.Append(FileMenu, "&File") view_menu = wx.Menu() ZoomMenu = view_menu.Append(wx.ID_ANY, "Zoom to &Fit", "Zoom to fit the window") self.Bind(wx.EVT_MENU, self.ZoomToFit, ZoomMenu) MenuBar.Append(view_menu, "&View") help_menu = wx.Menu() AboutMenu = help_menu.Append(wx.ID_ANY, "&About", "More information About this program") self.Bind(wx.EVT_MENU, self.OnAbout, AboutMenu) MenuBar.Append(help_menu, "&Help") self.SetMenuBar(MenuBar) self.CreateStatusBar() # Add the Canvas self.Canvas = NavCanvas.NavCanvas( self, -1, (500, 500), Debug=0, BackgroundColor="DARK SLATE BLUE").Canvas wx.EVT_CLOSE(self, self.OnCloseWindow) FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) FloatCanvas.EVT_LEFT_UP(self.Canvas, self.OnLeftUp) FloatCanvas.EVT_LEFT_DOWN(self.Canvas, self.OnLeftDown) try: self.FileDialog = wx.FileDialog(self, "Pick a BNA file", ".", "", "*", wx.OPEN) except wx._core.PyAssertionError: self.FileDialog = None self.ResetSelections() return None
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas( self, -1, size=(500, 500), ProjectionFun=None, Debug=0, BackgroundColor="DARK SLATE BLUE", ).Canvas Point = (45, 40) Box = Canvas.AddCircle(Point, Diameter=10, FillColor="Cyan", LineColor="Red", LineWidth=6) Canvas.GridOver = TextOverlay( "Some Text", (20, 20), Size=48, Color="Black", BackgroundColor='Pink', ) FloatCanvas.EVT_MOTION(Canvas, self.OnMove) self.Show() Canvas.ZoomToBB()
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas(self,-1, size = (500,500), ProjectionFun = YDownProjection, Debug = 0, BackgroundColor = "DARK SLATE BLUE", ).Canvas self.Canvas = Canvas Point = (0,0) Box = Canvas.AddRectangle(Point, (80,100), FillColor = "blue" ) Canvas.AddText("%s"%(Point,), Point, Position="cr") Canvas.AddPoint(Point, Diameter=3, Color = "red") Point = (0,100) Canvas.AddText("%s"%(Point,), Point, Position="cr") Canvas.AddPoint(Point, Diameter=3, Color = "red") FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove ) self.Show() Canvas.ZoomToBB()
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas( self, -1, size=(500, 500), ProjectionFun=YScaleFun, Debug=0, BackgroundColor="DARK SLATE BLUE", ).Canvas self.Canvas = Canvas Point = N.array((50e-6, 0)) Size = N.array(((2000e-6 - 5e-6), 50000)) Box = Canvas.AddRectangle(Point, Size, FillColor="blue") Canvas.AddText("%s" % (Point, ), Point, Position="cr") Canvas.AddPoint(Point, Diameter=3, Color="red") Point = Point + Size Canvas.AddText("%s" % (Point, ), Point, Position="cl") Canvas.AddPoint(Point, Diameter=3, Color="red") FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) self.Show() Canvas.ZoomToBB()
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas(self, ProjectionFun = None, BackgroundColor = "DARK SLATE BLUE", ).Canvas Canvas.MaxScale=4 self.Canvas = Canvas FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove ) # create the image: image = wx.Image(ImageFile) img = Canvas.AddScaledBitmap( image, (0,0), Height=image.GetHeight(), Position = 'tl', Quality = 'normal', ) img.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.OnLeftDown) img.Bind(FloatCanvas.EVT_FC_MOTION, self.OnMotion) self.Show() Canvas.ZoomToBB() self.move_count = 0
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas(self,-1, size = (500,500), ProjectionFun = None, Debug = 0, BackgroundColor = "DARK SLATE BLUE", ).Canvas self.Canvas = Canvas FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove ) Pts = ((45,40), (20, 15), (10, 40), (30,30)) Points = Canvas.AddPointSet(Pts, Diameter=3, Color="Red") Points.HitLineWidth = 10 Points.Bind(FloatCanvas.EVT_FC_ENTER_OBJECT, self.OnOverPoints) Points.Bind(FloatCanvas.EVT_FC_LEAVE_OBJECT, self.OnLeavePoints) Points.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.OnLeftDown) self.Show() Canvas.ZoomToBB()
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas FloatCanvas.FloatCanvas.ScaleWorldToPixel = ScaleWorldToPixel NC = NavCanvas.NavCanvas( self, -1, size=(500, 500), BackgroundColor="DARK SLATE BLUE", ProjectionFun=YScaleFun, ) self.Canvas = Canvas = NC.Canvas #self.Canvas.ScaleWorldToPixel = ScaleWorldToPixel FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) self.Values = random.randint(0, MaxValue, (NumChannels, )) self.Bars = [] self.BarWidth = 0.75 # add an X axis Canvas.AddLine(((0, 0), (NumChannels, 0)), ) for x in N.linspace(1, NumChannels, 11): Canvas.AddText("%i" % x, (x - 1 + self.BarWidth / 2, 0), Position="tc") for i, Value in enumerate(self.Values): bar = Canvas.AddRectangle( XY=(i, 0), WH=(self.BarWidth, Value), LineColor=None, LineStyle="Solid", LineWidth=1, FillColor="Red", FillStyle="Solid", ) self.Bars.append(bar) # Add a couple a button the Toolbar tb = NC.ToolBar tb.AddSeparator() ResetButton = wx.Button(tb, label="Reset") tb.AddControl(ResetButton) ResetButton.Bind(wx.EVT_BUTTON, self.ResetData) # PlayButton = wx.Button(tb, wx.ID_ANY, "Run") # tb.AddControl(PlayButton) # PlayButton.Bind(wx.EVT_BUTTON, self.RunTest) tb.Realize() self.Show() Canvas.ZoomToBB() Canvas.Draw(True)
def DrawTest(self, event=None): wx.GetApp().Yield() Canvas = self.Canvas Points = [ (0, 0), (200, 0), (200, 0), (200, 0), (200, 15), (185, 15), (119, 15), (104, 15), (104, 30), (104, 265), (104, 280), (119, 280), (185, 280), (200, 280), (200, 295), (200, 295), (200, 295), (0, 295), (0, 295), (0, 295), (0, 280), (15, 280), (81, 280), (96, 280), (96, 265), (96, 30), (96, 15), (81, 15), (15, 15), (0, 15), (0, 0), ] Canvas.ClearAll() MyLine = FC.Spline(Points, LineWidth=3, LineColor="Blue") Canvas.AddObject(MyLine) Canvas.AddPointSet( Points, Color="Red", Diameter=4, ) ## A regular old spline: Points = [ (-30, 260), (-10, 130), (70, 185), (160, 60), ] Canvas.AddSpline(Points, LineWidth=5, LineColor="Purple")
def UnBindAllMouseEvents(self): ## Here is how you catch FloatCanvas mouse events FloatCanvas.EVT_LEFT_DOWN(self.Canvas, None) FloatCanvas.EVT_LEFT_UP(self.Canvas, None) FloatCanvas.EVT_LEFT_DCLICK(self.Canvas, None) FloatCanvas.EVT_MIDDLE_DOWN(self.Canvas, None) FloatCanvas.EVT_MIDDLE_UP(self.Canvas, None) FloatCanvas.EVT_MIDDLE_DCLICK(self.Canvas, None) FloatCanvas.EVT_RIGHT_DOWN(self.Canvas, None) FloatCanvas.EVT_RIGHT_UP(self.Canvas, None) FloatCanvas.EVT_RIGHT_DCLICK(self.Canvas, None) FloatCanvas.EVT_MOUSEWHEEL(self.Canvas, None) self.EventsAreBound = False
def __init__(self, parent, id, title, position, size): wx.Frame.__init__(self, parent, id, title, position, size) ## Set up the MenuBar MenuBar = wx.MenuBar() FileMenu = wx.Menu() FileMenu.Append(wx.NewId(), "&Close", "Close Application") wx.EVT_MENU(self, FileMenu.FindItem("Close"), self.OnQuit) MenuBar.Append(FileMenu, "&File") view_menu = wx.Menu() view_menu.Append(wx.NewId(), "Zoom to &Fit", "Zoom to fit the window") wx.EVT_MENU(self, view_menu.FindItem("Zoom to &Fit"), self.ZoomToFit) MenuBar.Append(view_menu, "&View") help_menu = wx.Menu() help_menu.Append(ID_ABOUT_MENU, "&About", "More information About this program") wx.EVT_MENU(self, ID_ABOUT_MENU, self.OnAbout) MenuBar.Append(help_menu, "&Help") self.SetMenuBar(MenuBar) self.CreateStatusBar() # Add the Canvas self.Canvas = NavCanvas.NavCanvas( self, -1, (500, 500), Debug=0, BackgroundColor="DARK SLATE BLUE").Canvas wx.EVT_CLOSE(self, self.OnCloseWindow) FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) FloatCanvas.EVT_LEFT_UP(self.Canvas, self.OnLeftUp) FloatCanvas.EVT_LEFT_DOWN(self.Canvas, self.OnLeftClick) self.ResetSelections() return None
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas( self, -1, size=(500, 500), ProjectionFun=None, Debug=0, BackgroundColor="White", ).Canvas # Canvas = FloatCanvas.FloatCanvas(self,-1, # size = (500,500), # ProjectionFun = None, # Debug = 0, # BackgroundColor = "White", # ) self.Canvas = Canvas FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) FloatCanvas.EVT_LEFT_DOWN(self.Canvas, self.OnLeft) # Some default sizes: self.LineHeight = 1 self.TextWidth = 8 self.SpaceWidth = 1 self.Labels = ["SW Tasks", "Set RX Rf"] + ["A Row Label"] * 16 self.NumRows = len(self.Labels) self.BuildChartBackground() self.AddLabels() self.Show() Canvas.MinScale = 28 Canvas.MaxScale = 28 Canvas.ZoomToBB()
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = FloatCanvas.FloatCanvas( self, size=(500, 500), BackgroundColor="DARK SLATE BLUE", ) self.Canvas = Canvas FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) Point = (45, 40) Box = Canvas.AddScaledTextBox("A Two Line\nString", Point, 2, Color="Black", BackgroundColor=None, LineColor="Red", LineStyle="Solid", LineWidth=1, Width=None, PadSize=5, Family=wx.ROMAN, Style=wx.NORMAL, Weight=wx.NORMAL, Underlined=False, Position='br', Alignment="left", InForeground=False) Box.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Binding) self.Show() Canvas.ZoomToBB()
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas(self,-1, size = (500,500), Debug = 0, BackgroundColor = "DARK SLATE BLUE", ).Canvas self.Canvas = Canvas Values = (10,10,10) Colors = ('Red', 'Blue', 'Green') Pie1 = PieChart(N.array((0, 0)), 10, Values, Colors, Scaled=False) Canvas.AddObject(Pie1) Values = (10, 5, 5) Pie2 = PieChart(N.array((40, 0)), 10, Values, Colors) Canvas.AddObject(Pie2) # test default colors Values = (10, 15, 12, 24, 6, 10, 13, 11, 9, 13, 15, 12) Pie3 = PieChart(N.array((20, 20)), 10, Values, LineColor="Black") Canvas.AddObject(Pie3) # missng slice! Values = (10, 15, 12, 24) Colors = ('Red', 'Blue', 'Green', None) Pie4 = PieChart(N.array((0, -15)), 10, Values, Colors, LineColor="Black") Canvas.AddObject(Pie4) # Test the styles Values = (10, 12, 14) Styles = ("Solid", "CrossDiagHatch","CrossHatch") Colors = ('Red', 'Blue', 'Green') Pie4 = PieChart(N.array((20, -20)), 10, Values, Colors, Styles) Canvas.AddObject(Pie2) Pie1.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Pie1Hit) Pie2.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Pie2Hit) FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove ) self.Show() Canvas.ZoomToBB()
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas( self, -1, size=(500, 500), ProjectionFun=None, Debug=0, BackgroundColor="DARK SLATE BLUE", ).Canvas self.Canvas = Canvas FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) Point = (45, 40) Text = Canvas.AddScaledText("A String", Point, 20, Color="Black", BackgroundColor=None, Family=wx.ROMAN, Style=wx.NORMAL, Weight=wx.NORMAL, Underlined=False, Position='bl', InForeground=False) Text.MinFontSize = 4 # the default is 1 Text.DisappearWhenSmall = False #the default is True Rect1 = Canvas.AddRectangle((50, 20), (40, 15), FillColor="Red", LineStyle=None) Rect1.Bind(FC.EVT_FC_LEFT_DOWN, self.OnLeft) Rect1.Name = "red" Rect2 = Canvas.AddRectangle((70, 30), (40, 15), FillColor="Blue", LineStyle=None) Rect2.Bind(FC.EVT_FC_LEFT_DOWN, self.OnLeft) Rect2.Name = 'blue' self.Show() Canvas.ZoomToBB()
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.canvas = FloatCanvas.FloatCanvas( self, BackgroundColor="DARK SLATE BLUE") # Layout MainSizer = wx.BoxSizer(wx.VERTICAL) MainSizer.Add(self.canvas, 4, wx.EXPAND) self.SetSizer(MainSizer) self.canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.OnLeftDown) self.canvas.AddRectangle((10, 10), (100, 20), FillColor="red") self.canvas.SetMode(GUIMode.GUIMouse(self.canvas)) wx.CallAfter(self.canvas.ZoomToBB)
def __init__(self, parent, id, title, position, size): wx.Frame.__init__(self, parent, id, title, position, size) self.CreateStatusBar() # Add the Canvas NC = NavCanvas.NavCanvas( self, size=(500, 500), ProjectionFun=None, Debug=0, BackgroundColor="DARK SLATE BLUE", ) self.Canvas = NC.Canvas FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) # Add some buttons to the Toolbar tb = NC.ToolBar tb.AddSeparator() ClearButton = wx.Button(tb, wx.ID_ANY, "Clear") tb.AddControl(ClearButton) ClearButton.Bind(wx.EVT_BUTTON, self.Clear) DrawButton = wx.Button(tb, wx.ID_ANY, "StopDrawing") tb.AddControl(DrawButton) DrawButton.Bind(wx.EVT_BUTTON, self.SetDraw) self.DrawButton = DrawButton tb.Realize() # Initialize a few values self.Rects = [] self.RBBox = GUI.RubberBandBox(self.Canvas, self.NewRect) self.RBBox.Enable() self.Canvas.ZoomToBB() self.Show(True) return None
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas NC = NavCanvas.NavCanvas(self,-1, size = (500,500), ProjectionFun = None, Debug = 0, BackgroundColor = "White", ) self.Canvas = NC.Canvas self.LoadMap(TestFileName) FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove ) self.Show() self.Canvas.ZoomToBB()
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas( self, -1, size=(500, 500), ProjectionFun=None, Debug=0, BackgroundColor="DARK SLATE BLUE", ).Canvas self.Canvas = Canvas FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) Point = (0.0, 0.0) Circle = Canvas.AddCircle( Point, Diameter=50, LineWidth=4, ) Text = Canvas.AddScaledTextBox( "Some text that will need to be wrapped. Here is another sentence.", Point, Size=Circle.WH[0] / 10., #Width = 40, Width=Circle.WH[0] * 1.6, Position='cc', Color="Black", LineStyle=None, ) self.Show() Canvas.ZoomToBB()
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas( self, -1, size=(500, 500), ProjectionFun=None, Debug=0, BackgroundColor="DARK SLATE BLUE", ).Canvas Point = (45, 40) Box = Canvas.AddCircle(Point, Diameter=10, FillColor="Black", LineColor="Red", LineWidth=6) bmp = wx.Bitmap('NOAA.png') grids = GridGroup([ PixelBitmap(bmp, (10, 10), Position='tl'), PixelBitmap(bmp, (10, 10), Position='br'), PixelBitmap(bmp, (10, 10), Position='tr'), PixelBitmap(bmp, (10, 10), Position='bl'), PixelBitmap(bmp, (10, 10), Position='cl'), PixelBitmap(bmp, (10, 10), Position='cr'), PixelBitmap(bmp, (10, 10), Position='cc'), PixelBitmap(bmp, (10, 10), Position='tc'), PixelBitmap(bmp, (10, 10), Position='bc'), ]) Canvas.GridOver = grids FloatCanvas.EVT_MOTION(Canvas, self.OnMove) self.Show() Canvas.ZoomToBB()
def __init__(self, parent): super(MyPanel, self).__init__(parent) self.SetBackgroundColour(wx.WHITE) sizer = wx.BoxSizer(wx.VERTICAL) self.Canvas = FloatCanvas.FloatCanvas(self, BackgroundColor = "LIGHT GREY") self.Canvas.MaxScale = 2 sizer.Add(self.Canvas, 1, flag=wx.EXPAND) bmp1 = wx.BitmapFromImage(wx.Image('bmp1.png', wx.BITMAP_TYPE_PNG)) bmp2 = wx.BitmapFromImage(wx.Image('bmp2.png', wx.BITMAP_TYPE_PNG)) img1 = self.Canvas.AddScaledBitmap(bmp1, (0, 0), Height = bmp1.GetHeight(), Position = 'tl', Quality='normal') img2 = self.Canvas.AddScaledBitmap2(bmp2, (100, -100), Height = bmp2.GetHeight(), Position = 'tl', Quality='high') print img1.Quality print img2.Quality self.Canvas.ZoomToBB() #wx.CallLater(1, self.Canvas.ZoomToBB) self.Bind(wx.EVT_SIZE, self.OnSize) self.SetSizerAndFit(sizer)
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas(self,-1, size = (500,500), ProjectionFun = None, Debug = 0, BackgroundColor = "DARK SLATE BLUE", ).Canvas self.Canvas = Canvas FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove ) Points = (( 0,30), ( 0, 0), (30, 0), (30,30), ( 0,30), (10,20), (10,10), (20,10), (20,20), (10,20), ) Poly = Canvas.AddPolygon(Points, FillColor = "blue", LineColor = None, ) self.Show() Canvas.ZoomToBB()
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) # Add the Canvas Canvas = FC.FloatCanvas( self, size=(500, 500), ProjectionFun=None, Debug=0, BackgroundColor="Black", ) self.Canvas = Canvas self.Canvas.Bind(wx.EVT_SIZE, self.OnSize) # build the squares: w = 10 dx = 14 for i in range(9): for j in range(9): Rect = Canvas.AddRectangle((i * dx, j * dx), (w, w), FillColor="White", LineStyle=None) Outline = Canvas.AddRectangle((i * dx, j * dx), (w, w), FillColor=None, LineWidth=4, LineColor='Red', LineStyle=None) Rect.indexes = (i, j) Rect.outline = Outline Rect.Bind(FC.EVT_FC_LEFT_DOWN, self.SquareHitLeft) Rect.Bind(FC.EVT_FC_ENTER_OBJECT, self.SquareEnter) Rect.Bind(FC.EVT_FC_LEAVE_OBJECT, self.SquareLeave) self.Show() Canvas.ZoomToBB()
def __init__(self, parent, id, title, position, size): wx.Frame.__init__(self, parent, id, title, position, size) # Add the Canvas self.CreateStatusBar() Canvas = NavCanvas.NavCanvas( self, -1, (500, 500), ProjectionFun=None, Debug=0, BackgroundColor="DARK SLATE BLUE", ).Canvas self.Canvas = Canvas FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) Point = (45, 40) Box = Canvas.AddScaledTextBox("A Two Line\nString", Point, 2, Color="Black", BackgroundColor=None, LineColor="Red", LineStyle="Solid", LineWidth=1, Width=None, PadSize=5, Family=wx.ROMAN, Style=wx.NORMAL, Weight=wx.NORMAL, Underlined=False, Position='br', Alignment="left", InForeground=False) # All defaults Box = Canvas.AddScaledTextBox("A Two Line\nString", Point, 2) Box = Canvas.AddScaledTextBox("A Two Line\nString", Point, 2, BackgroundColor="Yellow", LineColor="Red", LineStyle="Solid", PadSize=5, Family=wx.TELETYPE, Position='bl') Box = Canvas.AddScaledTextBox("A Two Line\nString", Point, 2, BackgroundColor="Yellow", LineColor="Red", LineStyle="Solid", PadSize=5, Family=wx.TELETYPE, Position='tr') Box.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.binding2) Canvas.AddPoint(Point, Diameter=4) Point = (45, 15) Box = Canvas.AddScaledTextBox("A Two Line\nString", Point, 2, Color="Black", BackgroundColor='Red', LineColor="Blue", LineStyle="LongDash", LineWidth=2, Width=None, PadSize=5, Family=wx.TELETYPE, Style=wx.NORMAL, Weight=wx.NORMAL, Underlined=False, Position='cr', Alignment="left", InForeground=False) Box = Canvas.AddScaledTextBox("A Two Line\nString", Point, 1.5, Color="Black", BackgroundColor='Red', LineColor="Blue", LineStyle="LongDash", LineWidth=2, Width=None, PadSize=5, Family=wx.TELETYPE, Style=wx.NORMAL, Weight=wx.NORMAL, Underlined=False, Position='cl', Alignment="left", InForeground=False) Canvas.AddPoint(Point, Diameter=4) Point = (45, -10) Box = Canvas.AddScaledTextBox("A Two Line\nString", Point, 2, Color="Black", BackgroundColor='Red', LineColor="Blue", LineStyle="LongDash", LineWidth=2, Width=None, PadSize=3, Family=wx.TELETYPE, Style=wx.NORMAL, Weight=wx.NORMAL, Underlined=False, Position='tc', Alignment="left", InForeground=False) Box = Canvas.AddScaledTextBox("A three\nLine\nString", Point, 1.5, Color="Black", BackgroundColor='Red', LineColor="Blue", LineStyle="LongDash", LineWidth=2, Width=None, PadSize=0.5, Family=wx.TELETYPE, Style=wx.NORMAL, Weight=wx.NORMAL, Underlined=False, Position='bc', Alignment="left", InForeground=False) Canvas.AddPoint(Point, Diameter=4) Box = Canvas.AddScaledTextBox( "Some Auto Wrapped Text. There is enough to do.", (80, 40), 2, BackgroundColor='White', LineWidth=2, Width=20, PadSize=0.5, Family=wx.TELETYPE, ) Box = Canvas.AddScaledTextBox( "Some more auto wrapped text. Wrapped to a different width and right aligned.\n\nThis is another paragraph.", (80, 20), 2, BackgroundColor='White', LineWidth=2, Width=40, PadSize=0.5, Family=wx.ROMAN, Alignment="right") Point = N.array((100, -20), N.float_) Box = Canvas.AddScaledTextBox( "Here is even more auto wrapped text. This time the line spacing is set to 0.8. \n\nThe Padding is set to 0.", Point, Size=3, BackgroundColor='White', LineWidth=1, Width=40, PadSize=0.0, Family=wx.ROMAN, Position="cc", LineSpacing=0.8) Canvas.AddPoint(Point, "Red", 2) Point = N.array((0, -40), N.float_) # Point = N.array((0, 0), N.float_) for Position in ["tl", "bl", "tr", "br"]: # for Position in ["br"]: Box = Canvas.AddScaledTextBox( "Here is a\nfour liner\nanother line\nPosition=%s" % Position, Point, Size=4, Color="Red", BackgroundColor=None, #'LightBlue', LineWidth=1, LineColor="White", Width=None, PadSize=2, Family=wx.ROMAN, Position=Position, LineSpacing=0.8) Canvas.AddPoint(Point, "Red", 4) Point = N.array((-20, 60), N.float_) Box = Canvas.AddScaledTextBox("Here is some\ncentered\ntext", Point, Size=4, Color="Red", BackgroundColor='LightBlue', LineWidth=1, LineColor="White", Width=None, PadSize=2, Family=wx.ROMAN, Position="tl", Alignment="center", LineSpacing=0.8) Point = N.array((-20, 20), N.float_) Box = Canvas.AddScaledTextBox("Here is some\nright aligned\ntext", Point, Size=4, Color="Red", BackgroundColor='LightBlue', LineColor=None, Width=None, PadSize=2, Family=wx.ROMAN, Position="tl", Alignment="right", LineSpacing=0.8) Point = N.array((100, -60), N.float_) Box = Canvas.AddScaledTextBox( "Here is some auto wrapped text. This time it is centered, rather than right aligned.\n\nThe Padding is set to 2.", Point, Size=3, BackgroundColor='White', LineWidth=1, Width=40, PadSize=2.0, Family=wx.ROMAN, Position="cc", LineSpacing=0.8, Alignment='center', ) self.Show(True) self.Canvas.ZoomToBB() return None
def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.CreateStatusBar() # Add the Canvas NC = NavCanvas.NavCanvas( self, -1, size=(500, 500), ProjectionFun=None, Debug=0, BackgroundColor="DARK SLATE BLUE", ) Canvas = NC.Canvas self.Canvas = Canvas FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) Point = (45, 40) ## create a few Objects: C = FloatCanvas.Circle((0, 0), 10, FillColor="Red") R = FloatCanvas.Rectangle((5, 5), (15, 8), FillColor="Blue") E = FloatCanvas.Ellipse((1.5, 1.5), (12, 8), FillColor="Purple") C2 = FloatCanvas.Circle((0, 5), 10, FillColor="cyan") T = FloatCanvas.Text("Group A", (5.5, 5.5), Position="cc", Size=16, Weight=wx.BOLD, Family=wx.SWISS) self.GroupA = FloatCanvas.Group((R, C, E)) self.GroupA.AddObjects((C2, T)) Canvas.AddObject(self.GroupA) ## create another Groups of objects R = FloatCanvas.Rectangle((15, 15), (10, 18), FillColor="orange") E = FloatCanvas.Ellipse((22, 28), (12, 8), FillColor="yellow") C = FloatCanvas.Circle((25, 20), 15, FillColor="Green") C2 = FloatCanvas.Circle((12, 22), 10, FillColor="cyan") T = FloatCanvas.Text("Group B", (19, 24), Position="cc", Size=16, Weight=wx.BOLD, Family=wx.SWISS) self.GroupB = FloatCanvas.Group((R, E, C, C2, T)) Canvas.AddObject(self.GroupB) self.Groups = {"A": self.GroupA, "B": self.GroupB} # Add a couple of tools to the Canvas Toolbar tb = NC.ToolBar # tb.AddSeparator() for Group in self.Groups.keys(): Button = wx.Button(tb, wx.ID_ANY, "Remove %s" % Group) tb.AddControl(Button) Button.Bind(wx.EVT_BUTTON, lambda evt, group=Group: self.RemoveGroup(evt, group)) Button = wx.Button(tb, wx.ID_ANY, "Replace%s" % Group) tb.AddControl(Button) Button.Bind(wx.EVT_BUTTON, lambda evt, group=Group: self.ReplaceGroup(evt, group)) tb.Realize() self.Show() Canvas.ZoomToBB()
Note: you need to specify the size in the FloatCanvas Constructor. hmm -- I wonder if you'd even need the frame? """ import wx ## import the installed version #from wx.lib.floatcanvas import FloatCanvas ## import a local version import sys sys.path.append("../") from floatcanvas import NavCanvas, FloatCanvas app = wx.PySimpleApp() f = wx.Frame(None) Canvas = FloatCanvas.FloatCanvas(f, BackgroundColor="Cyan", size=(500, 500)) Canvas.AddRectangle((0, 0), (16, 20)) Canvas.AddRectangle((1, 1), (6, 8.5)) Canvas.AddRectangle((9, 1), (6, 8.5)) Canvas.AddRectangle((9, 10.5), (6, 8.5)) Canvas.AddRectangle((1, 10.5), (6, 8.5)) Canvas.ZoomToBB() print "Saving the image:", "junk.png" Canvas.SaveAsImage("junk.png")
def __init__(self, parent, id, title, position, size): wx.Frame.__init__(self, parent, id, title, position, size) self.CreateStatusBar() # Add the Canvas Canvas = NavCanvas.NavCanvas( self, -1, (500, 500), ProjectionFun=None, Debug=0, BackgroundColor="DARK SLATE BLUE", ).Canvas self.Canvas = Canvas FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove) FloatCanvas.EVT_LEFT_UP(self.Canvas, self.OnLeftUp) FloatCanvas.EVT_LEFT_DOWN(self.Canvas, self.OnLeftDown) Point = N.array((0, 0), N.float) Canvas.AddCircle( Point, Diameter=40, FillColor="Red", LineStyle=None, ) Width = 300 self.Box = Canvas.AddScaledTextBox( LongString, Point, 10, Color="Black", BackgroundColor='White', LineStyle="Solid", LineWidth=2, Width=Width, PadSize=10.0, Family=wx.ROMAN, #Family = wx.TELETYPE, Style=wx.NORMAL, Weight=wx.NORMAL, Underlined=False, Position='tl', LineSpacing=0.8, Alignment="left", #Alignment = "center", #Alignment = "right", InForeground=False) self.Handle1 = Canvas.AddBitmap(Resources.getMoveCursorBitmap(), Point, Position='cc') self.Handle2a = Canvas.AddBitmap(Resources.getMoveRLCursorBitmap(), Point, Position='cc') self.Handle2b = Canvas.AddBitmap(Resources.getMoveRLCursorBitmap(), Point, Position='cc') self.SetHandles() self.Handle1.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Handle1Hit) self.Handle2a.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Handle2Hit) self.Handle2b.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Handle2Hit) self.Show(True) self.Canvas.ZoomToBB() self.Resizing = False self.ResizeRect = None self.Moving = False return None