Ui module¶
-
class
Ui.
EnvironmentTab
(parent, window)[source]¶ Bases:
tkinter.ttk.Frame
Will have environment options like grav, air resistance, maybe scaling
-
clear_press
()[source]¶ Deletes all refs in physics Canvas Closes all hanging windows
Clears canvas of extant physics objects
Removes interacting forces
-
set_grav_for_new_physics_object
(physics_object)[source]¶ Append this function to
PhysicsCanvas.new_physics_object_plugins
- Parameters
physics_object – A new physics object
:type
Physics.PhysicsObject
-
-
class
Ui.
MainWindow
[source]¶ Bases:
object
MainWindow serves as the entry point to the application. It builds the PhysicsCanvas, the right side Notebook, and the tabs in that notebook. Many other objects contain references to MainWindow (usually simply as self.window) in order that they can access all other parts of the application.
-
additional_windows
¶ Extant instances from PhysicsWindows module
-
log
¶ Simply call window.log(message) to log directly to the log tab
-
root
¶ The Tkinter root
-
root_frame
¶ The root frame
-
-
class
Ui.
OptionsTab
(parent, window)[source]¶ Bases:
tkinter.ttk.Frame
Will have UI components for changing values such as in Options.Options
-
class
Ui.
PhysicsCanvas
(window, parent_frame)[source]¶ Bases:
object
Controls the drawing of PhysicsObjects and inheriting classes on a canvas
Sets origin to center and calculates actual pixel coordinates from object displacement vectors.
-
add_physics_object
(physics_object)[source]¶ This replaced redundant methods add_force_object, add_vector_object, etc. in the refactor. Those classes were also all merged into PhysicsObject.
Draws a rectangle to represent the physicsObject on the canvas.
Adds a reference to the new PhysicsObject in self.physicsObjects
Sets physics_object.canvas_id to the canvas id (integer) resulting from drawing a shape
Sets physics_object.physics_canvas to a reference to this PhysicsCanvas
- Parameters
physics_object (
Physics.PhysicsObject
) – A physics object to draw on the canvas
-
context_popup
(event)[source]¶ Pops a right click option menu near the user click.
If there is a ForceObject within Option[‘click radius’] of the click, the option menu is populated with entries relating to that object. Otherwise, the entry for adding a new object is in the menu.
- Parameters
event – Mouse click event
-
delete_physics_object
(physics_object)[source]¶ Deletes an object and removes its rendering from the canvas.
- Parameters
physics_object (extends
Physics.PhysicsObject
) – Object to delete- Returns
-
get_physics_object_from_id
(id)[source]¶ Returns the object with canvas id equal to id :param id: A canvas id :type id: int :return:
Physics.PhysicsObject
-
interacting_forces
¶ Instances from, e.g.
Physics.GravitationalForceGenerator
that need to be have update called
-
move_physics_object
(physics_object)[source]¶ Called by
Physics.ForceObject
when they need to move.Checks the displacement vector of the parameter object, calculates where that should appear on the canvas, then moves the rendering to the appropriate pixel x,y.
Currently, this is a little buggy and needs to be reworked. Positive and negative y are not accounted for correctly.
- Parameters
physics_object (extends
Physics.PhysicsObject
) – An object with a displacement vector that wants to move
-
new_physics_object_plugins
¶ These are functions. Each will have func(physics_object) called on it when a new object is added. You can generate a callback to go in this list to add functionality to new objects that are added
-
physics_objects
¶ Instances from e.g.,
Physics.ForceObject
that need to be have update called
-
popup_add
(event)[source]¶ Generates a callback function for use with the context menu, to popup a new window for adding a PHysics Object at the click location. :param event: MouseEvent :return: A callback function to be attached as a UI command :rtype: Function
-
popup_info
(force_object, event)[source]¶ Generates a callback function for use with the context menu, so the ForceObject is linked to the PhysicsObjectWindow when it is created.
- Parameters
force_object (
Physics.ForceObject
) – The physics object to linkevent – Mouse click event
- Returns
A callback to pass to the menu entry as the command
- Return type
Function
-
scale
¶ Not yet implemented
-
-
class
Ui.
TimeSelector
(window, parent_frame)[source]¶ Bases:
object
Handles pause, step, and play buttons at the bottom of the UI.
Calculates update time and sends it to window.physics_canvas for updating.
- Parameters
window (
Ui.Window
) – The main entry of the applicationparent_frame – The frame where these components should be located
-
run
()[source]¶ Run by the program thread(s), not called directly!
Sleeps for approximately Options.Options[‘update interval’] seconds, then calls self.update(interval) with the interval being the actual time passed since the last update was called. :return:
-
run_thread
¶ Main program time loop
-
running
¶ Set True when program is running
-
start_thread
()[source]¶ Stops the old thread in case it’s running, then sets self.run_thread to a new thread and starts it.
-
step
()[source]¶ Calls self.update(Options[‘update interval’]), ‘stepping’ the time that would pass in 1 ‘frame’
-
stop_thread
()[source]¶ Stops the current self.run_thread and joins it (if its alive)
Also sets self.running to false :return:
Bound to the Enter keyboard key to toggle whether time is running :param event: Key event, not used