Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Progress bar, static typing, comments
Browse files Browse the repository at this point in the history
  • Loading branch information
WallK committed Sep 24, 2023
1 parent 1af8d8c commit 03f4bf8
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 18 deletions.
5 changes: 2 additions & 3 deletions Button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ func _ready():
self.pressed.connect(self._button_pressed)

func _button_pressed():
var output = []
# var exit_code = OS.execute("ls", ["-l", "/"], output, true)
var exit_code = OS.execute("touch", ["godot_configurator_hardcoded"], output)
var output := [] #[] is shared, Array isn't (maybe fixed in 4.1)
var exit_code := OS.execute("touch", ["godot_configurator_hardcoded"], output)
print("exit code: ", exit_code)
print("output: ", output)

Expand Down
8 changes: 3 additions & 5 deletions Button2.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ func _ready():
self.pressed.connect(self._button_pressed)

func _button_pressed():
var output = []
# var exit_code = OS.execute("ls", ["-l", "/"], output, true)
var exit_code = OS.execute("bash", ["touch_external.sh"], output)
var output := [] #[] is shared, Array isn't (maybe fixed in 4.1)
var exit_code := OS.execute("bash", ["touch_external.sh"], output)
print("exit code: ", exit_code)
print("output: ",
output)
print("output: ", output)
32 changes: 32 additions & 0 deletions ProgressBar.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
extends ProgressBar

var progress_file := "progress" #File with progress from 0 to 100
var progress_button: Button
var file := FileAccess

var prev_prog: float = 0

func _ready():
self.value = 0
progress_button = $"../HBoxContainerProgress/ProgressButton"

func _process(delta):
if file.file_exists(progress_file): #File to be removed after script is done
var file := FileAccess.open(progress_file, FileAccess.READ)
var _progress := float(file.get_as_text())
if prev_prog != _progress: #To not rewrite every frame
self.value = _progress
print("boom", _progress)
prev_prog = _progress
else:
if prev_prog == 100:
progress_button.disabled = false #Reenable progress button
prev_prog = 0


func _on_check_button_toggled(button_pressed):
var _fill_color := Color("999999")
if button_pressed:
_fill_color = Color("FF0000")
self.get("theme_override_styles/fill").set_bg_color(_fill_color)

17 changes: 17 additions & 0 deletions ProgressButton.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extends Button

var thread: Thread

func _ready():
self.pressed.connect(self._button_pressed)

func _button_pressed():
thread = Thread.new()
thread.start(_execute_bash.bind(["progress_file.sh"])) #Need to bind
self.disabled = true #To prevent multiple launches
# thread.wait_to_finish() #Should be done somewhere

func _execute_bash(filename):
var output := []
var exit_code := OS.execute("bash", filename, output)
print(exit_code)
2 changes: 1 addition & 1 deletion main.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends Control

func _ready():
$VBoxContainerButtons/Button.grab_focus()
$VBoxContainerButtons/Button.grab_focus() #Required to enable controller focusing
56 changes: 47 additions & 9 deletions main.tscn
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
[gd_scene load_steps=6 format=3 uid="uid://qk2gw74anwlq"]
[gd_scene load_steps=9 format=3 uid="uid://qk2gw74anwlq"]

[ext_resource type="Texture2D" uid="uid://bv6vh33cnfaw4" path="res://icon.svg" id="1_axfei"]
[ext_resource type="Script" path="res://main.gd" id="1_obpq7"]
[ext_resource type="Script" path="res://Button.gd" id="3_aenvv"]
[ext_resource type="Script" path="res://Button2.gd" id="4_u2f14"]
[ext_resource type="Script" path="res://ProgressButton.gd" id="5_slq0p"]
[ext_resource type="Script" path="res://ProgressBar.gd" id="6_cx658"]

[sub_resource type="LabelSettings" id="LabelSettings_b77hh"]
font_size = 24

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_xyjyy"]
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5

[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 15
Expand Down Expand Up @@ -52,25 +60,55 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -70.5
offset_top = -33.0
offset_right = 70.5
offset_bottom = 33.0
offset_left = -74.0
offset_top = -66.0
offset_right = 273.0
offset_bottom = 66.0
grow_horizontal = 2
grow_vertical = 2

[node name="Button" type="Button" parent="VBoxContainerButtons"]
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
size_flags_horizontal = 4
focus_neighbor_top = NodePath("../Button2")
size_flags_horizontal = 0
focus_neighbor_top = NodePath("../HBoxContainerProgress/ProgressButton")
focus_neighbor_bottom = NodePath("../Button2")
text = "Hardcoded script"
script = ExtResource("3_aenvv")

[node name="Button2" type="Button" parent="VBoxContainerButtons"]
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
size_flags_horizontal = 4
size_flags_horizontal = 0
focus_neighbor_top = NodePath("../Button")
focus_neighbor_bottom = NodePath("../Button")
focus_neighbor_bottom = NodePath("../HBoxContainerProgress/ProgressButton")
text = "External script"
script = ExtResource("4_u2f14")

[node name="HBoxContainerProgress" type="HBoxContainer" parent="VBoxContainerButtons"]
layout_mode = 2

[node name="ProgressButton" type="Button" parent="VBoxContainerButtons/HBoxContainerProgress"]
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
focus_neighbor_top = NodePath("../../Button2")
focus_neighbor_bottom = NodePath("../../Button")
text = "Start progress"
script = ExtResource("5_slq0p")

[node name="CheckButton" type="CheckButton" parent="VBoxContainerButtons/HBoxContainerProgress"]
layout_mode = 2
text = "Make progress red"

[node name="ProgressBar" type="ProgressBar" parent="VBoxContainerButtons"]
custom_minimum_size = Vector2(150, 0)
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 1
size_flags_stretch_ratio = 8.13
theme_override_styles/fill = SubResource("StyleBoxFlat_xyjyy")
step = 1.0
value = 25.0
script = ExtResource("6_cx658")

[connection signal="toggled" from="VBoxContainerButtons/HBoxContainerProgress/CheckButton" to="VBoxContainerButtons/ProgressBar" method="_on_check_button_toggled"]
15 changes: 15 additions & 0 deletions progress_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

progress_file="progress"
echo "0" > "$progress_file"

for ((i=1; i<=100; i++)); do
echo -ne "$i" > "$progress_file"
# echo $i
# sleep 0.1
sleep $((RANDOM / 30000))
done

sleep 1

rm "$progress_file"

0 comments on commit 03f4bf8

Please sign in to comment.