-
Notifications
You must be signed in to change notification settings - Fork 0
/
13_LoggingWindow_ModifyingTheTextInCode_Text.rb
112 lines (92 loc) · 2.02 KB
/
13_LoggingWindow_ModifyingTheTextInCode_Text.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# coding: utf-8
# Copyright (C) 2019 Mark D. Blackwell.
require 'tk'
require 'tkextlib/tile'
module ::LoggingWindow
module GraphicalHelper
def f_content
$f_content_private ||= begin
f = ::Tk::Tile::Frame.new root
f.grid sticky: :wnes
end
end
def root
$root_private ||= begin
tell_tk_which_encoding_to_use
::TkRoot.new
end
end
def weights_column_and_row_default_set_up(*args)
first = 0
args.reverse_each do |e|
::TkGrid.columnconfigure e, first, weight: 1
::TkGrid. rowconfigure e, first, weight: 1
end
nil
end
private
def tell_tk_which_encoding_to_use
::Tk::Encoding.encoding = ''.encoding
nil
end
end
end
module ::LoggingWindow
module GraphicalObjects
def t_log
@t_log_private ||= begin
t = ::TkText.new f_content
t.height 24
t.state :disabled
t.width 80
t.wrap :none
t.grid
end
end
end
end
module ::LoggingWindow
module Graphical
extend GraphicalHelper
extend GraphicalObjects
extend self
def main
weights_column_and_row_set_up
lines_write
::Tk.mainloop
nil
end
private
def lines_write
size = 25
size.times.each do |i|
log_write "Line #{i + 1} of #{size}"
end
nil
end
def log_delete_some_maybe
t_log.delete 1.0, 2.0 unless log_line_count < 24
nil
end
def log_line_count
t_log.index('end - 1 line').split('.').first.to_i
end
def log_newline_append_maybe
t_log.insert :end, "\n" unless '1.0' == (t_log.index 'end-1c')
nil
end
def log_write(message)
t_log[:state] = :normal
log_delete_some_maybe
log_newline_append_maybe
t_log.insert :end, message
t_log[:state] = :disabled
nil
end
def weights_column_and_row_set_up
weights_column_and_row_default_set_up f_content, root
nil
end
end
end
::LoggingWindow::Graphical.main