Add support for instances (Issue #192)
Add support for instances (Issue #192)
This commit adds the feature requested in Issue #192.
IV_Swinger2_gui.py
- GraphicalUserInterface class changes:
- __init__:
- Add instance and main_gui creation parameters
- Add attributes:
- self.instance (string)
- Initial value from creation parameter
- Will always be None for the main GUI
- self.main_gui (object)
- Initial value from creation parameter
- Set to self if creation parameter value is None
- self.instance_gui (dict of objects)
- Only exists for main GUI
- Contains
- Initial value is empty dict: {}
- Added to when an instance GUI is launched
- Deleted from when an instance GUI is closed
- Set root to tk.Toplevel() instead of tk.Tk() for instance GUIs
- Pass instance value to set_root_options() method
- Append /inst/{instance} to app_data_dir for instances and pass
that in the creation of the ivs2 object
- Set instance ivs2 object's usb_port property to DISCONNECTED
- Set instance app_dir property to the main GUI's value (for
Windows bug workaround)
- Add derived properties:
- instances
- Sorted list of already-created instances
- usb_ports_in_use
- List of ports used by the main GUI and all instance GUIs
- Change check_app_data_dir() method to take the app_data_dir as a
parameter so it can be called before the creation of the ivs2 object
- Modify set_root_options() method:
- Added instance parameter
- Append instance to title if instance is not None
- In swing_loop() method, change minimum value of delay_ms from 1 to
10 to prevent any GUI from monopolizing the CPU
- Modify start_centered(), start_to_right(), and start_to_left()
methods to tile instance GUIs
- Modify the close_gui() method:
- Add warning if closing the main GUI and instance GUIs are still
open
- Add instance name to dialog that is generated when there are >5
changes to the config file
- When the method is called for an instance GUI, remove the
instance GUI object and delete it from the main GUI's
instance_gui dict
- Modify the run() method:
- Suppress attempting the Arduino handshake if the usb_port property
is DISCONNECTED
- Suppress calling mainloop for instances
- MenuBar class changes:
- Add the instances menu to the MenuBar class
- Call new create_instances_menu() method in __init__
- Add methods:
- create_instances_menu()
- populate_instances_menu()
- depopulate_instances_menu()
- update_instances_menu()
- launch_entry_action()
- launch_instance()
- add_new_instance()
- show_instances_help()
- Add InstancesHelpDialog class
- Suppress creating the Mac Preferences and Help menus for instance
GUIs (because they crash, but are still present from main GUI)
- Modify update_usb_port_menu() method:
- Add call to find_serial_ports before populating the menu
- Disable entries that are in use by other GUIs
- Add DISCONNECTED entry to allow user to disconnect from any USB
port
- Modify select_serial() method:
- Handle value of DISCONNECTED;
- Close the current USB port (if any) by calling the ivs2
object's close_usb() method
- Disable the go button
- Save value in the config file
- Modify run_simulator() method to pass the app_data_dir value in the
creation of the SimulatorDialog object
IV_Swinger2.py:
- Move code to get the default app_data_dir into a global function so
it can be used by GUI
- Resurrect the extended PrintAndLog class.
- Add instance variable for log_file_name to allow (but not
require) instance-specific logging
- Remove terminate_log() global function since it is a method in
the extended PrintAndLog class
- Modify the apply_usb method in the Configuration class:
- Handle the case where the USB port is in use:
- print and log a message
- set ivs2 object's usb_port property to DISCONNECTED
- Handle the case where the config value is DISCONNECTED
- Treat just the same as case where the port in the config
is attached; do not try to find an Arduino port
- Add optional usb_ports_in_use creation parameter to IV_Swinger2 class
- If the object is created with that parameter specified, set the
object's usb_ports_in_use attribute to the list passed
in. Otherwise, set it to an empty list
- Add a close_usb() method and use that in the reset_arduino()
method. This method is now used by the GUI when closing an instance
GUI.
- Add logging of the resetting of an Arduino
IV_Swinger2_sim.py:
- Add support for non-default app_data_dir:
- Pass the app_data_dir creation parameter to the IV_Swinger2
__init__
- Add app_data_dir creation parameter to the SimulatorDialog class
and pass it to the ivs2_sim object at creation