# ClickingsGTKArray.py (c) Kari Laitinen # 2006-08-23 File created. # 2009-02-11 Last modification. # This program works in the same way as programs ClickingsGTK.py # and ClickingsApplet.java. # In this version of the program the Python lists are used # in the same way as, for example, Java arrays. Thus this # version may be easier to understand for those people # who are familiar with ClickingsApplet.java. import gtk class ClickingsApplication : def __init__( self ) : self.application_window = gtk.Window( gtk.WINDOW_TOPLEVEL ) self.application_window.set_title( "CLICK THIS WINDOW WITH THE MOUSE" ) self.application_window.connect( "destroy", self.exit_this_application ) self.application_window.set_size_request( 600, 400 ) self.drawing_area = gtk.DrawingArea() self.application_window.add( self.drawing_area ) self.drawing_area.connect( "expose-event", self.drawing_area_exposed ) self.drawing_area.connect( "button_press_event", self.mouse_button_pressed ) self.drawing_area.set_events(gtk.gdk.EXPOSURE_MASK | gtk.gdk.BUTTON_PRESS_MASK ) self.drawing_area.show() self.application_window.show() self.window_width, self.window_height = \ self.application_window.get_size() self.x_coordinates_of_clickings = [] self.y_coordinates_of_clickings = [] self.current_number_of_clickings = 0 def mouse_button_pressed( self, widget, event ) : self.x_coordinates_of_clickings.append( int( event.x ) ) self.y_coordinates_of_clickings.append( int( event.y ) ) self.current_number_of_clickings += 1 # print self.current_number_of_clickings self.drawing_area.queue_draw() return True def drawing_area_exposed( self, area, event ) : graphics_context = \ self.drawing_area.get_style().fg_gc[gtk.STATE_NORMAL] this_drawable = self.drawing_area.window coordinates_as_text = self.drawing_area.create_pango_layout( "" ) for clicking_index in range( self.current_number_of_clickings ) : this_drawable.draw_arc( graphics_context, True, self.x_coordinates_of_clickings[ clicking_index ] - 3, self.y_coordinates_of_clickings[ clicking_index ] - 3, 6, 6, 0, 360*64 ) coordinates_as_text.set_text( "(%d, %d)" % \ ( self.x_coordinates_of_clickings[ clicking_index ], self.y_coordinates_of_clickings[ clicking_index ] ) ) this_drawable.draw_layout( graphics_context, self.x_coordinates_of_clickings[ clicking_index ] + 7, self.y_coordinates_of_clickings[ clicking_index ] - 7, coordinates_as_text ) return True def run( self ) : gtk.main() def exit_this_application( self, widget, data=None ) : gtk.main_quit() if __name__ == "__main__": this_application = ClickingsApplication() this_application.run()