diff options
| -rw-r--r-- | logic/database.gd | 19 | ||||
| -rw-r--r-- | logic/stage.gd | 6 | ||||
| -rw-r--r-- | main.gd | 6 | ||||
| -rw-r--r-- | main.tscn | 44 | ||||
| -rw-r--r-- | menu/menu.gd | 126 | ||||
| -rw-r--r-- | readme.md | 17 |
6 files changed, 102 insertions, 116 deletions
diff --git a/logic/database.gd b/logic/database.gd index 438a2dd..2285470 100644 --- a/logic/database.gd +++ b/logic/database.gd @@ -12,7 +12,7 @@ const ENTRY_PROTOTYPE: Dictionary = { "date_year": 0, "date_month": 0, "date_day": 0, - "anesthetic": "", + "anesthesia": "", "first_assistant": "", "type": "", "sub_type": "", @@ -195,6 +195,14 @@ func store_database(file_path: String = DATABASE_FILE_PATH): file.close() +func clear_database(save_changes: bool = false): + clear_selection() + self.clear() + db.resize(0) + if save_changes: + store_database() + + static func instance_entry(params: Dictionary = {}) -> Dictionary: var new_entry := ENTRY_PROTOTYPE.duplicate(true) new_entry.process_id = params.get("process_id", "") @@ -207,7 +215,7 @@ static func instance_entry(params: Dictionary = {}) -> Dictionary: new_entry.date_day = params.get("date_day", today.day) new_entry.date = params.get("date", get_entry_date(new_entry)) # @DAM We should store only one version of the date. - new_entry.anesthetic = params.get("anesthetic", "") + new_entry.anesthesia = params.get("anesthesia", "") new_entry.first_assistant = params.get("first_assistant", "") new_entry.type = params.get("type", "") new_entry.sub_type = params.get("sub_type", "") @@ -234,9 +242,8 @@ static func set_entry_date(entry: Dictionary, date: String): entry.date_day = int(date.substr(month_day_idx + 1)) -func fake_database(): - self.clear() - db.resize(0) +func fake_database(save_changes: bool = false): + clear_database() for idx in range(500): var date_year = 1 + int(float(idx) / 365.0) var date_month = idx % 12 @@ -248,6 +255,8 @@ func fake_database(): }) db.append(fake_entry) self.add_item(get_entry_view(fake_entry)) + if save_changes: + store_database() func pointer_input_handler(pointer: PointerInputSensor.PointerInputData): diff --git a/logic/stage.gd b/logic/stage.gd index 27962c6..73d905e 100644 --- a/logic/stage.gd +++ b/logic/stage.gd @@ -13,7 +13,7 @@ onready var process_id: LineEdit = get_node("controls/process_id") onready var surgery_id: LineEdit = get_node("controls/surgery_id") onready var date: DatePicker = get_node("controls/date_picker") onready var place: LineEdit = get_node("controls/place") -onready var anesthetic: LineEdit = get_node("controls/anesthetic") +onready var anesthesia: LineEdit = get_node("controls/anesthesia") onready var first_assistant: LineEdit = get_node("controls/first_assistant") onready var type: LineEdit = get_node("controls/type") onready var sub_type: LineEdit = get_node("controls/sub_type") @@ -81,7 +81,7 @@ func set_stage(entry: Dictionary): surgery_id.text = entry.surgery_id date.set_date(entry.date_year, entry.date_month, entry.date_day) place.text = entry.place - anesthetic.text = entry.anesthetic + anesthesia.text = entry.anesthesia first_assistant.text = entry.first_assistant type.text = entry.type sub_type.text = entry.sub_type @@ -102,7 +102,7 @@ func get_stage() -> Dictionary: "date_month": date.get_month(), "date_day": date.get_day(), "place": place.text, - "anesthetic": anesthetic.text, + "anesthesia": anesthesia.text, "first_assistant": first_assistant.text, "type": type.text, "sub_type": sub_type.text, @@ -4,10 +4,8 @@ var timeout: float onready var controls_sensible_to_keyboard: Array = [ self, - get_node("/root/main/about"), - get_node("/root/main/delete_filters"), - get_node("/root/main/import_filters"), - get_node("/root/main/export_filters"), + get_node("/root/main/file_picker"), + get_node("/root/main/confirm_action"), ] @@ -133,7 +133,7 @@ placeholder_text = "Local" caret_blink = true caret_blink_speed = 0.5 -[node name="anesthetic" type="LineEdit" parent="stage/controls"] +[node name="anesthesia" type="LineEdit" parent="stage/controls"] margin_top = 363.0 margin_right = 1080.0 margin_bottom = 412.0 @@ -237,36 +237,12 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="about" type="AcceptDialog" parent="."] +[node name="file_picker" type="FileDialog" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 size_flags_horizontal = 3 size_flags_vertical = 3 -window_title = "" -dialog_autowrap = true -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="delete_filters" type="ConfirmationDialog" parent="."] -anchor_right = 1.0 -anchor_bottom = 1.0 -size_flags_horizontal = 3 -size_flags_vertical = 3 -window_title = "delete filters" -dialog_text = "Are you sure you want to delete all filters?" -dialog_autowrap = true -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="import_filters" type="FileDialog" parent="."] -anchor_right = 1.0 -anchor_bottom = 1.0 -size_flags_horizontal = 3 -size_flags_vertical = 3 -window_title = "Open a File" -mode = 0 +window_title = "PICK FILE" access = 2 filters = PoolStringArray( "*.csv" ) show_hidden_files = true @@ -276,20 +252,14 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="export_filters" type="FileDialog" parent="."] +[node name="confirm_action" type="ConfirmationDialog" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 size_flags_horizontal = 3 size_flags_vertical = 3 -window_title = "export filters" -access = 2 -filters = PoolStringArray( "*.csv" ) -show_hidden_files = true -current_dir = "" -current_path = "" -__meta__ = { -"_edit_use_anchors_": false -} +window_title = "CONFIRM ACTION" +dialog_text = "Are you sure you want to delete all filters?" +dialog_autowrap = true [node name="debug" type="Label" parent="."] visible = false diff --git a/menu/menu.gd b/menu/menu.gd index 36beee8..3384436 100644 --- a/menu/menu.gd +++ b/menu/menu.gd @@ -4,100 +4,94 @@ const menu_items: Array = [ { label = "IMPORT FILTERS", action = "_menu_import_filters_action" }, { label = "EXPORT FILTERS", action = "_menu_export_filters_action" }, { label = "CLEAR FILTERS", action = "_menu_clear_filters_action" }, + { label = "EXPORT DATA", action = "_menu_export_data_action" }, + { label = "CLEAR DATA", action = "_menu_clear_data_action" }, { label = "ABOUT", action = "_menu_about_action" }, { label = "FAKE_DB", action = "_menu_fake_db_action" }, ] const license_font_b612: String = "res://licenses/font_b612.txt" const license_godot: String = "res://licenses/godot.txt" -onready var popup: PopupMenu = get_popup() -onready var debug: Label = get_node("/root/main/debug") as Label +onready var popup := get_popup() as PopupMenu +onready var confirm_action := get_node("/root/main/confirm_action") as ConfirmationDialog +onready var file_picker := get_node("/root/main/file_picker") as FileDialog +onready var database := get_node("/root/main/database") as Database + func _ready(): - for idx in range(menu_items.size()): popup.add_item(menu_items[idx].label, idx) popup.connect("id_pressed", self, "id_pressed") - -# load_file(file) - + file_picker.get_cancel().connect("pressed", self, "dialog_cancelled", ["file_selected"]) + confirm_action.get_cancel().connect("pressed", self, "dialog_cancelled", ["confirmed"]) func id_pressed(id: int): - debug.text += "'%d':'%s'" % [id, menu_items[id].action] self.call_deferred(menu_items[id].action) - debug.text += "!\n" -var csv_file: Array -var has_permissions := false +func dialog_cancelled(confirmation_signal_name: String): + var confirmation_handlers = confirm_action.get_signal_connection_list(confirmation_signal_name) + for it in confirmation_handlers: + confirm_action.disconnect(it.signal, it.target, it.method) + + func _menu_import_filters_action(): - -# printerr("pressed: %s" % get_stack()[0]); - debug.text += "> import: " - - if OS.get_name() == "Android": - while not has_permissions: - var permissions := Array(OS.get_granted_permissions()) - if not permissions.has("android.permission.READ_EXTERNAL_STORAGE") \ - or not permissions.has("android.permission.WRITE_EXTERNAL_STORAGE"): - OS.request_permissions() - # await get_tree().create_timer(1).timeout - yield(get_tree().create_timer(1), "timeout") # - for Godot 3 branch - else: - has_permissions = true - - - - var file_dialog := get_node("/root/main/import_filters") as FileDialog - file_dialog.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) - file_dialog.connect("file_selected", self, "file_selected", [], CONNECT_ONESHOT) - file_dialog.show_modal(true) - file_dialog.invalidate() -# printerr("download: '%s'" % OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)) - -func file_selected(path: String): - debug.text += "'%s'\n" % path - - var file = File.new() - file.open(path, File.READ) - while file.eof_reached() == false: - var line = file.get_line() - csv_file.append(line) - printerr("%s" % line) - file.close() + return + file_picker.window_title = "IMPORT FILTERS" + file_picker.mode = FileDialog.MODE_OPEN_FILE + file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) +# file_picker.connect("file_selected", filters, "TODO", [], CONNECT_ONESHOT) +# file_picker.show_modal(true) +# file_picker.invalidate() + func _menu_export_filters_action(): - debug.text += "> export: \n" -# printerr("pressed: %s" % get_stack()[0]); - var file_dialog := get_node("/root/main/export_filters") as FileDialog - file_dialog.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) - file_dialog.connect("file_selected", self, "file_selected_export", [], CONNECT_ONESHOT) - file_dialog.show_modal(true) - file_dialog.invalidate() - -func file_selected_export(path: String): - debug.text += "'%s'\n" % path - var file = File.new() - file.open(path, File.WRITE) - for ln in csv_file: - file.store_line(ln) - file.close() + return + file_picker.window_title = "EXPORT FILTERS" + file_picker.mode = FileDialog.MODE_SAVE_FILE + file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) +# file_picker.connect("file_selected", filters, "TODO", [], CONNECT_ONESHOT) +# file_picker.show_modal(true) +# file_picker.invalidate() func _menu_clear_filters_action(): - debug.text += "> clear\n" -# printerr("pressed: %s" % get_stack()[0]); - (get_node("/root/main/delete_filters") as ConfirmationDialog).show_modal(true) + return + confirm_action.window_title = "CLEAR FILTERS" + confirm_action.dialog_text = "Do you want to delete all filters?" +# confirm_action.connect("confirmed", filters, "TDO", [true], CONNECT_ONESHOT) +# confirm_action.show_modal(true) + + +func _menu_export_data_action(): + file_picker.window_title = "EXPORT DATA" + file_picker.mode = FileDialog.MODE_SAVE_FILE + file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) + file_picker.connect("file_selected", database, "store_database", [], CONNECT_ONESHOT) + file_picker.show_modal(true) + file_picker.invalidate() + + +func _menu_clear_data_action(): + confirm_action.window_title = "CLEAR DATA" + confirm_action.dialog_text = "Do you want to delete all entries from the database?" + confirm_action.connect("confirmed", database, "clear_database", [true], CONNECT_ONESHOT) + confirm_action.show_modal(true) func _menu_about_action(): -# printerr("pressed: %s" % get_stack()[0]); - debug.text += "> about\n" - (get_node("/root/main/about") as AcceptDialog).show_modal() + confirm_action.window_title = "FAKE DB" + confirm_action.dialog_text = "About text here!" +# confirm_action.connect("confirmed", database, "fake_database", [true], CONNECT_ONESHOT) + confirm_action.show_modal(true) + func _menu_fake_db_action(): - get_node("/root/main/database").fake_database() + confirm_action.window_title = "FAKE DB" + confirm_action.dialog_text = "Do you want to delete all entries from the database and replace by fake entries?" + confirm_action.connect("confirmed", database, "fake_database", [true], CONNECT_ONESHOT) + confirm_action.show_modal(true) @@ -14,7 +14,22 @@ Surgery Log - [x] edited entry does not show updated once saved; - [x] edited entry shows updated when selected then press back button; - [x] load/store database CSV file; -- [ ] export database to CSV file; +- [x] export database to CSV file; +- [x] allow to reset database; +- [ ] Implement file access permission check on Android: + ```py + if OS.get_name() == "Android": + var has_permissions := false + while not has_permissions: + var permissions := Array(OS.get_granted_permissions()) + if not permissions.has("android.permission.READ_EXTERNAL_STORAGE") \ + or not permissions.has("android.permission.WRITE_EXTERNAL_STORAGE"): + OS.request_permissions() + # await get_tree().create_timer(1).timeout + yield(get_tree().create_timer(1), "timeout") # - for Godot 3 branch + else: + has_permissions = true + ``` - [ ] load/store filters CSV file; - [ ] import/export filters to CSV file; - [ ] add auto-fill buttons on stage screen: |
