-
Notifications
You must be signed in to change notification settings - Fork 0
/
yast-test.rb
executable file
·78 lines (65 loc) · 1.62 KB
/
yast-test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/sbin/yast2
# coding: utf-8
# ./yast-test.rb "مرحبا"
require "yast"
require "ui/dialog"
Yast.import "Label"
Yast.import "UI"
class TestDialog < UI::Dialog
def initialize(text)
@direction = :ltr
@text = text
end
def flip_widget
label = (@direction == :ltr) ? "Make Right to Left" : "Make Left to Right"
PushButton(Id(:flip), label)
end
def dialog_content
VBox(
InputField(Id(:text), Opt(:notify), "Enter a text"),
PushButton(Id(:file), "Text from a file"),
VSpacing(1),
ReplacePoint(Id(:rsample), sample_widgets),
VSpacing(1),
ReplacePoint(Id(:rflip), flip_widget),
HBox(
PushButton(Id(:close), Yast::Label.CloseButton)
)
)
end
def sample_widgets
box = VBox(
RichText(@text),
Label(@text),
RadioButton(@text),
PushButton(@text)
)
Frame("Sample widgets with that text", box)
end
def flip_handler
if @direction == :ltr
@direction = :rtl
lang = "ar_EG" # enables RTL UI layout
else
@direction = :ltr
lang = "en_US"
end
Yast::UI.ReplaceWidget(Id(:rflip), flip_widget)
Yast::UI.SetLanguage(lang)
end
def text_handler
@text = Yast::UI.QueryWidget(Id(:text), :Value)
Yast::UI.ReplaceWidget(Id(:rsample), sample_widgets)
end
def file_handler
file = Yast::UI.AskForExistingFile(".", "*", "Choose a File")
return unless file
@text = File.read(file).strip
Yast::UI.ReplaceWidget(Id(:rsample), sample_widgets)
end
def close_handler
finish_dialog(:next)
end
end
text = Yast::WFM::Args(0) || "مرحبا"
TestDialog.new(text).run