Merge pull request #484 from Calinou/add-os-testing-demo

Add an operating system testing demo
This commit is contained in:
Aaron Franke
2020-06-23 13:51:54 -04:00
committed by GitHub
9 changed files with 504 additions and 0 deletions

75
misc/os_test/actions.gd Normal file
View File

@@ -0,0 +1,75 @@
extends VBoxContainer
func _on_OpenShellWeb_pressed():
OS.shell_open("https://example.com")
func _on_OpenShellFolder_pressed():
var path = OS.get_environment("HOME")
if path == "":
# Windows-specific.
path = OS.get_environment("USERPROFILE")
OS.shell_open(path)
func _on_ChangeWindowTitle_pressed():
OS.set_window_title("Modified window title. Unicode characters for testing: é € × Ù ¨")
func _on_ChangeWindowIcon_pressed():
var image = preload("res://icon.png").get_data()
# Use an operation that will cause the icon to change in a visible manner.
image.bumpmap_to_normalmap()
OS.set_icon(image)
func _on_MoveWindowToForeground_pressed():
OS.set_window_title("Will move window to foreground in 5 seconds, try unfocusing the window...")
yield(get_tree().create_timer(5), "timeout")
OS.move_window_to_foreground()
# Restore the previous window title.
OS.set_window_title(ProjectSettings.get_setting("application/config/name"))
func _on_RequestAttention_pressed():
OS.set_window_title("Will request attention in 5 seconds, try unfocusing the window...")
yield(get_tree().create_timer(5), "timeout")
OS.request_attention()
# Restore the previous window title.
OS.set_window_title(ProjectSettings.get_setting("application/config/name"))
func _on_VibrateDeviceShort_pressed():
Input.vibrate_handheld(200)
func _on_VibrateDeviceLong_pressed():
Input.vibrate_handheld(1000)
func _on_AddGlobalMenuItems_pressed():
OS.global_menu_add_item("Hello", "World", 0, null)
OS.global_menu_add_separator("Hello")
OS.global_menu_add_item("Hello2", "World2", 0, null)
func _on_RemoveGlobalMenuItem_pressed():
OS.global_menu_remove_item("Hello", 0)
func _on_GetClipboard_pressed():
OS.alert("Clipboard contents:\n\n%s" % OS.clipboard)
func _on_SetClipboard_pressed():
OS.clipboard = "Modified clipboard contents. Unicode characters for testing: é € × Ù ¨"
func _on_DisplayAlert_pressed():
OS.alert("Hello from Godot! Close this dialog to resume the main window.")
func _on_KillCurrentProcess_pressed():
OS.kill(OS.get_process_id())

View File

@@ -0,0 +1,7 @@
[gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
[resource]
background_mode = 2
background_sky = SubResource( 1 )

BIN
misc/os_test/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

Binary file not shown.

139
misc/os_test/os_test.gd Normal file
View File

@@ -0,0 +1,139 @@
extends Panel
onready var rtl = $HBoxContainer/Features
# Returns a human-readable string from a date and time, date, or time dictionary.
func datetime_to_string(date):
if (
date.has("year")
and date.has("month")
and date.has("day")
and date.has("hour")
and date.has("minute")
and date.has("second")
):
# Date and time.
return "{year}-{month}-{day} {hour}:{minute}:{second}".format({
year = str(date.year).pad_zeros(2),
month = str(date.month).pad_zeros(2),
day = str(date.day).pad_zeros(2),
hour = str(date.hour).pad_zeros(2),
minute = str(date.minute).pad_zeros(2),
second = str(date.second).pad_zeros(2),
})
elif date.has("year") and date.has("month") and date.has("day"):
# Date only.
return "{year}-{month}-{day}".format({
year = str(date.year).pad_zeros(2),
month = str(date.month).pad_zeros(2),
day = str(date.day).pad_zeros(2),
})
else:
# Time only.
return "{hour}:{minute}:{second}".format({
hour = str(date.hour).pad_zeros(2),
minute = str(date.minute).pad_zeros(2),
second = str(date.second).pad_zeros(2),
})
func add_header(header):
rtl.append_bbcode("\n[b][u][color=#6df]{header}[/color][/u][/b]\n".format({
header = header,
}))
func add_line(key, value):
rtl.append_bbcode("[b]{key}:[/b] {value}\n".format({
key = key,
value = value if str(value) != "" else "[color=#8fff](empty)[/color]",
}))
func _ready():
add_header("Audio")
var audio_drivers = PoolStringArray()
for i in OS.get_audio_driver_count():
audio_drivers.push_back(OS.get_audio_driver_name(i))
add_line("Available drivers", audio_drivers.join(", "))
add_line("MIDI inputs", OS.get_connected_midi_inputs().join(", "))
add_header("Date")
add_line("Date and time (local)", datetime_to_string(OS.get_datetime()))
add_line("Date and time (UTC)", datetime_to_string(OS.get_datetime(true)))
add_line("Date (local)", datetime_to_string(OS.get_date()))
add_line("Date (UTC)", datetime_to_string(OS.get_date(true)))
add_line("Time (local)", datetime_to_string(OS.get_time()))
add_line("Time (UTC)", datetime_to_string(OS.get_time(true)))
add_line("Timezone", OS.get_time_zone_info())
add_line("System time (milliseconds)", OS.get_system_time_msecs())
add_line("System time (seconds)", OS.get_system_time_secs())
add_line("UNIX time", OS.get_unix_time())
add_header("Display")
add_line("Screen count", OS.get_screen_count())
add_line("DPI", OS.get_screen_dpi())
add_line("Startup screen position", OS.get_screen_position())
add_line("Startup screen size", OS.get_screen_size())
add_line("Safe area rectangle", OS.get_window_safe_area())
add_line("Screen orientation", [
"Landscape",
"Portrait",
"Landscape (reverse)",
"Portrait (reverse)",
"Landscape (defined by sensor)",
"Portrait (defined by sensor)",
"Defined by sensor",
][OS.screen_orientation])
add_header("Engine")
add_line("Command-line arguments", str(OS.get_cmdline_args()))
add_line("Is debug build", OS.is_debug_build())
add_line("Executable path", OS.get_executable_path())
add_line("User data directory", OS.get_user_data_dir())
add_line("Filesystem is persistent", OS.is_userfs_persistent())
add_header("Environment")
add_line("Value of `PATH`", OS.get_environment("PATH"))
add_line("Value of `path`", OS.get_environment("path"))
add_header("Input")
add_line("Latin keyboard variant", OS.get_latin_keyboard_variant())
add_line("Device has touch screen", OS.has_touchscreen_ui_hint())
add_line("Device has virtual keyboard", OS.has_virtual_keyboard())
add_line("Virtual keyboard height", OS.get_virtual_keyboard_height())
add_header("Localization")
add_line("Locale", OS.get_locale())
add_header("Hardware")
add_line("Model name", OS.get_model_name())
add_line("Processor count", OS.get_processor_count())
add_line("Device unique ID", OS.get_unique_id())
add_line("Video adapter name", VisualServer.get_video_adapter_name())
add_line("Video adapter vendor", VisualServer.get_video_adapter_vendor())
add_header("Mobile")
add_line("Granted permissions", OS.get_granted_permissions())
add_header("Software")
add_line("OS name", OS.get_name())
add_line("Process ID", OS.get_process_id())
add_header("System directories")
add_line("Desktop", OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP))
add_line("DCIM", OS.get_system_dir(OS.SYSTEM_DIR_DCIM))
add_line("Documents", OS.get_system_dir(OS.SYSTEM_DIR_DOCUMENTS))
add_line("Downloads", OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS))
add_line("Movies", OS.get_system_dir(OS.SYSTEM_DIR_MOVIES))
add_line("Music", OS.get_system_dir(OS.SYSTEM_DIR_MUSIC))
add_line("Pictures", OS.get_system_dir(OS.SYSTEM_DIR_PICTURES))
add_line("Ringtones", OS.get_system_dir(OS.SYSTEM_DIR_RINGTONES))
add_header("Video")
var video_drivers = PoolStringArray()
for i in OS.get_video_driver_count():
video_drivers.push_back(OS.get_video_driver_name(i))
add_line("Available drivers", video_drivers.join(", "))
add_line("Current driver", OS.get_video_driver_name(OS.get_current_video_driver()))

212
misc/os_test/os_test.tscn Normal file
View File

@@ -0,0 +1,212 @@
[gd_scene load_steps=8 format=2]
[ext_resource path="res://os_test.gd" type="Script" id=1]
[ext_resource path="res://noto_sans_ui_bold.ttf" type="DynamicFontData" id=2]
[ext_resource path="res://noto_sans_ui_regular.ttf" type="DynamicFontData" id=3]
[ext_resource path="res://actions.gd" type="Script" id=4]
[sub_resource type="DynamicFont" id=1]
size = 14
font_data = ExtResource( 3 )
[sub_resource type="Theme" id=2]
default_font = SubResource( 1 )
[sub_resource type="DynamicFont" id=3]
size = 14
font_data = ExtResource( 2 )
[node name="OSTest" type="Panel"]
anchor_right = 1.0
anchor_bottom = 1.0
theme = SubResource( 2 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxContainer" type="HBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 20.0
margin_top = 20.0
margin_right = -20.0
margin_bottom = -20.0
custom_constants/separation = 20
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Features" type="RichTextLabel" parent="HBoxContainer"]
margin_right = 482.0
margin_bottom = 560.0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_fonts/bold_font = SubResource( 3 )
custom_fonts/normal_font = SubResource( 1 )
custom_constants/line_separation = 4
bbcode_enabled = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Actions" type="VBoxContainer" parent="HBoxContainer"]
margin_left = 502.0
margin_right = 984.0
margin_bottom = 560.0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/separation = 20
script = ExtResource( 4 )
[node name="Label" type="Label" parent="HBoxContainer/Actions"]
margin_right = 482.0
margin_bottom = 20.0
custom_fonts/font = SubResource( 3 )
text = "Actions"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="GridContainer" type="GridContainer" parent="HBoxContainer/Actions"]
margin_top = 40.0
margin_right = 482.0
margin_bottom = 560.0
size_flags_horizontal = 3
size_flags_vertical = 3
columns = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="OpenShellWeb" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_right = 239.0
margin_bottom = 70.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Open Shell (web)"
[node name="OpenShellFolder" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_left = 243.0
margin_right = 482.0
margin_bottom = 70.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Open Shell (folder)"
[node name="ChangeWindowTitle" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_top = 74.0
margin_right = 239.0
margin_bottom = 144.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Change Window Title"
[node name="ChangeWindowIcon" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_left = 243.0
margin_top = 74.0
margin_right = 482.0
margin_bottom = 144.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Change Window Icon"
[node name="MoveWindowToForeground" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_top = 148.0
margin_right = 239.0
margin_bottom = 218.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Move Window to Foreground"
[node name="RequestAttention" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_left = 243.0
margin_top = 148.0
margin_right = 482.0
margin_bottom = 218.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Request Attention"
[node name="VibrateDeviceShort" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_top = 222.0
margin_right = 239.0
margin_bottom = 292.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Vibrate Device (200 ms)"
[node name="VibrateDeviceLong" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_left = 243.0
margin_top = 222.0
margin_right = 482.0
margin_bottom = 292.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Vibrate Device (1000 ms)"
[node name="AddGlobalMenuItems" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_top = 296.0
margin_right = 239.0
margin_bottom = 366.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Add Global Menu Items"
[node name="RemoveGlobalMenuItem" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_left = 243.0
margin_top = 296.0
margin_right = 482.0
margin_bottom = 366.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Remove Global Menu Item"
[node name="GetClipboard" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_top = 370.0
margin_right = 239.0
margin_bottom = 440.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Get Clipboard Contents"
[node name="SetClipboard" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_left = 243.0
margin_top = 370.0
margin_right = 482.0
margin_bottom = 440.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Set Clipboard Contents"
[node name="DisplayAlert" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_top = 444.0
margin_right = 239.0
margin_bottom = 514.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Display Alert"
[node name="KillCurrentProcess" type="Button" parent="HBoxContainer/Actions/GridContainer"]
margin_left = 243.0
margin_top = 444.0
margin_right = 482.0
margin_bottom = 514.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Kill Current Process"
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/OpenShellWeb" to="HBoxContainer/Actions" method="_on_OpenShellWeb_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/OpenShellFolder" to="HBoxContainer/Actions" method="_on_OpenShellFolder_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/ChangeWindowTitle" to="HBoxContainer/Actions" method="_on_ChangeWindowTitle_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/ChangeWindowIcon" to="HBoxContainer/Actions" method="_on_ChangeWindowIcon_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/MoveWindowToForeground" to="HBoxContainer/Actions" method="_on_MoveWindowToForeground_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/RequestAttention" to="HBoxContainer/Actions" method="_on_RequestAttention_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/VibrateDeviceShort" to="HBoxContainer/Actions" method="_on_VibrateDeviceShort_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/VibrateDeviceLong" to="HBoxContainer/Actions" method="_on_VibrateDeviceLong_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/AddGlobalMenuItems" to="HBoxContainer/Actions" method="_on_AddGlobalMenuItems_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/RemoveGlobalMenuItem" to="HBoxContainer/Actions" method="_on_RemoveGlobalMenuItem_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/GetClipboard" to="HBoxContainer/Actions" method="_on_GetClipboard_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/SetClipboard" to="HBoxContainer/Actions" method="_on_SetClipboard_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/DisplayAlert" to="HBoxContainer/Actions" method="_on_DisplayAlert_pressed"]
[connection signal="pressed" from="HBoxContainer/Actions/GridContainer/KillCurrentProcess" to="HBoxContainer/Actions" method="_on_KillCurrentProcess_pressed"]

View File

@@ -0,0 +1,37 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
_global_script_classes=[ ]
_global_script_class_icons={
}
[application]
config/name="Operating System Testing"
run/main_scene="res://os_test.tscn"
run/low_processor_mode=true
config/icon="res://icon.png"
[debug]
gdscript/warnings/return_value_discarded=false
[display]
window/stretch/mode="2d"
window/stretch/aspect="expand"
[rendering]
quality/driver/driver_name="GLES2"
vram_compression/import_etc=true
vram_compression/import_etc2=false
environment/default_environment="res://default_env.tres"