Package car_sim :: Module car_map :: Class CarMap
[hide private]
[frames] | no frames]

Class CarMap

object --+
         |
        CarMap

A "car map" is the map shown in a CarSim application window. It may contain any number of cars which are drawn onto the map. A car map listens for mouse commands that signal the creation of cars or execution of car methods. A yellow line on the car map shows the most recent movement of a car.

Instance Methods [hide private]
 
__init__(self, parent, width, height, grid_row, grid_column)
Creates the main window and places the components
 
update_status_text(self, event)
Changes the text in the status label when the pointer is over a car or a car is dragged.
 
save_location(self, event)
When button 1 is pressed, its location is saved and if it happens above a car image, the image item is saved.
car object
get_closest_car(self, location)
Goes through all the car objects and selects the closest one to the given location.
 
drive_selected_car(self, event)
When a car is dragged to its new position, releasing the mouse button activates this method.
 
create_menu(self, event)
Shows a fueling menu for a car nearest to the right clicking point
 
fuel(self)
Shows the fueling menu and does the fueling
 
fill_up(self)
Fills up the tank of the selected car
 
create_new_car(self, event)
Left double click saves the location of the click and shows menus that ask information for a new car.
 
show_text(self, event)
Selects the closest car of the events(mouse goes over an image) and shows its status text
 
hide_text(self, event)
Hides the status text when the mouse leaves the image
 
get_message_text(self, car)
Formats a car for string output.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, parent, width, height, grid_row, grid_column)
(Constructor)

 

Creates the main window and places the components

Overrides: object.__init__

update_status_text(self, event)

 

Changes the text in the status label when the pointer is over a car or a car is dragged.

Parameters:
  • event (event object) - object that hold information about the action. Includes, for example, mouse location

save_location(self, event)

 

When button 1 is pressed, its location is saved and if it happens above a car image, the image item is saved. The actual car object to be driven is selected by finding the closest car object to the clicking point.

Parameters:
  • event - event object that brings with it clicking coordinates among others

get_closest_car(self, location)

 

Goes through all the car objects and selects the closest one to the given location.

Parameters:
  • location (location object) - where the mouse button was pressed
Returns: car object
nearest car to the mouse press point

drive_selected_car(self, event)

 

When a car is dragged to its new position, releasing the mouse button activates this method. Moves the car image under the mouse to the point where the mouse was released (event parameter). Deletes the previous line and draws a new one that represents this driving. Checks whether there is enough gas for the desired driving.

Parameters:
  • event - event object holding coordinates of the releasing point

create_new_car(self, event)

 

Left double click saves the location of the click and shows menus that ask information for a new car. Creates a new car object and attaches a random image to it.

Parameters:
  • event - event object

show_text(self, event)

 

Selects the closest car of the events(mouse goes over an image) and shows its status text

Parameters:
  • event - item object

hide_text(self, event)

 

Hides the status text when the mouse leaves the image

Parameters:
  • event - event object

get_message_text(self, car)

 

Formats a car for string output.

Parameters:
  • car (car object) - a car
Returns:
a string representation of the car