1. German Larrain
  2. ars

Commits

German Larrain  committed e6e9cd4

app.Program: added method 'finalize'

  • Participants
  • Parent commits f98b3a7
  • Branches dev

Comments (0)

Files changed (2)

File ars/app/__init__.py

View file
 			self.gAdapter.start_window(self.sim.on_idle, self.reset_simulation,
 				self.on_action_selection)
 
+	def finalize(self):
+		"""Finalize the program, deleting or releasing all associated resources.
+
+		Currently, the following is done:
+
+		* the graphics adapter is told to
+			:meth:`ars.graphics.Adapter.finalize_window`
+		* all attributes are set to None or False
+
+		A finalized program file cannot be used for further simulations.
+
+		.. note::
+			This method may be called more than once without error.
+
+		"""
+		if self.gAdapter is not None:
+			try:
+				self.gAdapter.finalize_window()
+			except AttributeError:
+				pass
+
+		self.do_create_window = False
+		self.key_press_functions = None
+		self.sim = None
+		self._screenshot_recorder = None
+		self.gAdapter = None
+
 	def reset_simulation(self):
 		"""Resets the simulation by resetting the graphics adapter and creating
 		a new simulation.

File demo_runner.py

View file
 			sim_program.print_final_data()
 		except AttributeError:
 			pass
-
-		sim_program.gAdapter.finalize_window()
-		# Previously, to close the simulation window after it ends we needed
-		# to exit the script. Otherwise windows are not closed and accumulate!
-		# TODO: craft a :meth:`ars.app.Program.stop`
+		sim_program.finalize()
 
 if __name__ == '__main__':
 	exit_value = main()