--- 01-gui.py 2006-01-03 03:56:43.000000000 -0200 +++ 02-line.py 2006-01-03 04:01:15.000000000 -0200 @@ -2,6 +2,50 @@ from eagle import * +class Tool( object ): + """Interface to be implemented by tools.""" + + + def mouse( self, app, canvas, buttons, x, y ): + """This tool have a user feedback using mouse on canvas.""" + pass + # mouse() +# Tool + + +class Line( Tool ): + def __init__( self ): + self.first_point = None + # __init__() + + + def mouse( self, app, canvas, buttons, x, y ): + if buttons & Canvas.MOUSE_BUTTON_1: + if self.first_point is None: + self.first_point = ( x, y ) + else: + color = app[ "fg" ] + size = app[ "size" ] + x0, y0 = self.first_point + canvas.draw_line( x0, y0, x, y, color, size ) + self.first_point = None + # mouse() +# Line + + +tools = { + "Line": Line(), + } +def_tool="Line" + + +def canvas_action( app, canvas, buttons, x, y ): + tool = app[ "tool" ] + tools[ tool ].mouse( app, canvas, buttons, x, y ) +# canvas_action() + + + app = App( title="Paint", id="paint", statusbar=True, @@ -15,6 +59,8 @@ ), Selection( id="tool", label="Tool:", + options=tools.keys(), + active=def_tool, ), UIntSpin( id="size", label="Line Size:", @@ -57,6 +103,7 @@ width=400, height=400, bgcolor="white", + callback=canvas_action, ), ) )