code: refactoring, use variables instead of path to components to make code easier to read
This commit is contained in:
parent
16fbbbfc9d
commit
c939300658
|
@ -10,6 +10,9 @@ var packages_to_delete = []
|
|||
var output = []
|
||||
var root_tree
|
||||
|
||||
onready var Tree = $Panel/Tree
|
||||
onready var ConsoleDisplay = $Panel/Panel/RichTextLabel
|
||||
|
||||
func get_installed_packages():
|
||||
var buffer = []
|
||||
installed_packages = []
|
||||
|
@ -29,22 +32,26 @@ func _ready():
|
|||
|
||||
# click on APPLY CHANGES
|
||||
func _on_Button_pressed():
|
||||
$Panel/Panel/RichTextLabel.text = ""
|
||||
ConsoleDisplay.text = ""
|
||||
if packages.size() > 0:
|
||||
$Panel/Panel/RichTextLabel.text = "You are going to install these packages:\n"
|
||||
ConsoleDisplay.text = "You are going to install these packages:\n"
|
||||
for l in packages:
|
||||
$Panel/Panel/RichTextLabel.text += "- " + l + "\n"
|
||||
ConsoleDisplay.text += "- " + l + "\n"
|
||||
if packages_to_delete.size() > 0:
|
||||
$Panel/Panel/RichTextLabel.text += "You are going to remove these packages:\n"
|
||||
ConsoleDisplay.text += "You are going to remove these packages:\n"
|
||||
for l in packages_to_delete:
|
||||
$Panel/Panel/RichTextLabel.text += "- " + l + "\n"
|
||||
$Panel/Panel/RichTextLabel.text += "\n\nClick on Accept to apply changes"
|
||||
$Panel/Panel/Accept.visible = true
|
||||
ConsoleDisplay.text += "- " + l + "\n"
|
||||
if packages_to_delete.size() > 0 or packages.size() > 0:
|
||||
ConsoleDisplay.text += "\n\nClick on Accept to apply changes"
|
||||
$Panel/Panel/Accept.visible = true
|
||||
else:
|
||||
ConsoleDisplay.text = "No change to make"
|
||||
$Panel/Panel/Accept.visible = false
|
||||
$Panel/Panel/Cancel.visible = true
|
||||
$Panel/Panel.visible = true
|
||||
|
||||
func _on_Tree_multi_selected():
|
||||
var item = $Panel/Tree.get_selected()
|
||||
var item = Tree.get_selected()
|
||||
if item.get_parent() == root_tree:
|
||||
return(0)
|
||||
|
||||
|
@ -69,16 +76,16 @@ func _on_Tree_multi_selected():
|
|||
|
||||
|
||||
func _on_LineEdit_text_entered(text):
|
||||
$Panel/Tree.clear()
|
||||
root_tree = $Panel/Tree.create_item()
|
||||
$Panel/Tree.set_hide_root(true)
|
||||
gui_program = $Panel/Tree.create_item()
|
||||
Tree.clear()
|
||||
root_tree = Tree.create_item()
|
||||
Tree.set_hide_root(true)
|
||||
gui_program = Tree.create_item()
|
||||
gui_program.set_text(0, "Graphical programs")
|
||||
gui_program.collapsed = false
|
||||
tui_program = $Panel/Tree.create_item($Panel/Tree)
|
||||
tui_program = Tree.create_item(Tree)
|
||||
tui_program.set_text(0, "Terminal/console programs")
|
||||
tui_program.collapsed = false
|
||||
other = $Panel/Tree.create_item($Panel/Tree)
|
||||
other = Tree.create_item(Tree)
|
||||
other.set_text(0, "Other programs")
|
||||
other.collapsed = false
|
||||
|
||||
|
@ -100,11 +107,11 @@ func _on_LineEdit_text_entered(text):
|
|||
continue
|
||||
|
||||
if str(s["gui"]) == "True":
|
||||
root = $Panel/Tree.create_item(gui_program)
|
||||
root = Tree.create_item(gui_program)
|
||||
elif str(s["tui"]) == "True":
|
||||
root = $Panel/Tree.create_item(tui_program)
|
||||
root = Tree.create_item(tui_program)
|
||||
else:
|
||||
root = $Panel/Tree.create_item(other)
|
||||
root = Tree.create_item(other)
|
||||
|
||||
root.set_text(0, s["pkgname"])
|
||||
if s["comment"]:
|
||||
|
@ -114,37 +121,23 @@ func _on_LineEdit_text_entered(text):
|
|||
root.set_metadata(0, "installed")
|
||||
root.set_custom_bg_color(0, Color(0.7, 0.7,0.2,0.5))
|
||||
|
||||
func _on_Hide_pressed():
|
||||
$Panel/Panel.visible = false
|
||||
$Panel/Panel/Hide.visible = false
|
||||
$Panel/Panel/Accept.visible = false
|
||||
func reset_display():
|
||||
$Panel/Panel.hide()
|
||||
$Panel/Panel/Accept.hide()
|
||||
packages = []
|
||||
packages_to_delete = []
|
||||
print("Regenerating display")
|
||||
get_installed_packages()
|
||||
_on_LineEdit_text_entered($Panel/LineEdit.text)
|
||||
|
||||
func _on_Accept_pressed():
|
||||
$Panel/Panel/Accept.visible = false
|
||||
$Panel/Panel/Hide.visible = true
|
||||
$Panel/Panel/Cancel.visible = false
|
||||
$Panel/Panel/RichTextLabel.text = ""
|
||||
ConsoleDisplay.text = ""
|
||||
if packages_to_delete.size() > 0:
|
||||
if $Panel/doas_nopass.pressed:
|
||||
OS.execute("doas", ["pkg_delete", "-Ivx"] + packages_to_delete, true, output, true)
|
||||
else:
|
||||
OS.execute("xterm", ["-e", "doas", "pkg_delete", "-Ivx"] + packages_to_delete, true, output, true)
|
||||
for l in output:
|
||||
$Panel/Panel/RichTextLabel.text += l
|
||||
OS.execute("xterm", ["-e", "doas", "pkg_delete", "-Ivx"] + packages_to_delete, true, output, true)
|
||||
if packages.size() > 0:
|
||||
if $Panel/doas_nopass.pressed:
|
||||
print(OS.execute("doas", ["pkg_add", "-Ivx"] + packages, true, output, true))
|
||||
else:
|
||||
print(OS.execute("xterm", ["-e", "doas", "pkg_add", "-Ivx"] + packages, true, output, true))
|
||||
for l in output:
|
||||
$Panel/Panel/RichTextLabel.text += l
|
||||
if not $Panel/doas_nopass.pressed:
|
||||
_on_Hide_pressed()
|
||||
OS.execute("xterm", ["-e", "doas", "pkg_add", "-Ivx"] + packages, true, output, true)
|
||||
reset_display()
|
||||
|
||||
func _on_Cancel_pressed():
|
||||
$Panel/Panel.visible = false
|
||||
|
|
|
@ -50,14 +50,6 @@ margin_bottom = 300.0
|
|||
custom_colors/default_color = Color( 0, 1, 0.0156863, 1 )
|
||||
scroll_following = true
|
||||
|
||||
[node name="Hide" type="Button" parent="Panel/Panel"]
|
||||
visible = false
|
||||
margin_left = 253.0
|
||||
margin_top = 375.0
|
||||
margin_right = 356.0
|
||||
margin_bottom = 395.0
|
||||
text = "Hide message"
|
||||
|
||||
[node name="Accept" type="Button" parent="Panel/Panel"]
|
||||
visible = false
|
||||
anchor_left = 0.5
|
||||
|
@ -86,16 +78,8 @@ margin_right = 782.0
|
|||
margin_bottom = 40.0
|
||||
text = "Search in DESCR"
|
||||
|
||||
[node name="doas_nopass" type="CheckButton" parent="Panel"]
|
||||
margin_left = 832.0
|
||||
margin_right = 1014.0
|
||||
margin_bottom = 40.0
|
||||
pressed = true
|
||||
text = "doas_nopass"
|
||||
|
||||
[connection signal="text_entered" from="Panel/LineEdit" to="." method="_on_LineEdit_text_entered"]
|
||||
[connection signal="item_selected" from="Panel/Tree" to="." method="_on_Tree_multi_selected"]
|
||||
[connection signal="pressed" from="Panel/Button" to="." method="_on_Button_pressed"]
|
||||
[connection signal="pressed" from="Panel/Panel/Hide" to="." method="_on_Hide_pressed"]
|
||||
[connection signal="pressed" from="Panel/Panel/Accept" to="." method="_on_Accept_pressed"]
|
||||
[connection signal="pressed" from="Panel/Panel/Cancel" to="." method="_on_Cancel_pressed"]
|
||||
|
|
Loading…
Reference in New Issue