Skip to content

Commit 1ceec18

Browse files
committed
Append statistics
1 parent 0563f75 commit 1ceec18

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

EscapeString/main.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,27 @@ def log_uncaught_exceptions(ex_cls, ex, tb):
3737

3838

3939
class MainWindow(QWidget):
40+
ESCAPE_RULES = [
41+
('"', '"', r'\"', True),
42+
("'", "'", r"\'", True),
43+
(r'\n', "\n", r'\n', True),
44+
(r'\t', "\t", r'\t', True),
45+
(r'\b', "\b", r'\b', True),
46+
(r'\f', "\f", r'\f', False),
47+
('\\', "\\", '\\\\', False),
48+
]
49+
TITLE = 'EscapeString'
50+
4051
def __init__(self):
4152
super().__init__()
4253

43-
self.setWindowTitle('EscapeString')
44-
45-
self.escape_rules = [
46-
('"', '"', r'\"', True),
47-
("'", "'", r"\'", True),
48-
(r'\n', "\n", r'\n', True),
49-
(r'\t', "\t", r'\t', True),
50-
(r'\b', "\b", r'\b', True),
51-
(r'\f', "\f", r'\f', False),
52-
('\\', "\\", '\\\\', False),
53-
]
54+
self.setWindowTitle(self.TITLE)
5455

5556
self.escape_char_by_checkbox = {}
5657
self.char_by_escape = {}
5758

5859
button_layout = QHBoxLayout()
59-
for title, char, escape, checked in self.escape_rules:
60+
for title, char, escape, checked in self.ESCAPE_RULES:
6061
checkbox = QCheckBox(title)
6162
checkbox.setChecked(checked)
6263
checkbox.clicked.connect(self.input_text_changed)
@@ -89,12 +90,16 @@ def __init__(self):
8990
self.button_detail_error.setFixedSize(20, 20)
9091
self.button_detail_error.setToolTip('Detail error')
9192
self.button_detail_error.clicked.connect(self.show_detail_error_massage)
93+
self.button_detail_error.hide()
9294

9395
self.last_error_message = None
9496
self.last_detail_error_message = None
9597

9698
self.text_edit_input.textChanged.connect(self.input_text_changed)
9799

100+
self.label_input_number = QLabel()
101+
self.label_output_number = QLabel()
102+
98103
splitter = QSplitter()
99104
splitter.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
100105
splitter.addWidget(self.text_edit_input)
@@ -111,6 +116,9 @@ def __init__(self):
111116
self.setLayout(layout)
112117

113118
def show_detail_error_massage(self):
119+
if not self.last_error_message or not self.last_detail_error_message:
120+
return
121+
114122
message = self.last_error_message + '\n\n' + self.last_detail_error_message
115123

116124
mb = QErrorMessage()
@@ -149,6 +157,11 @@ def input_text_changed(self):
149157

150158
self.text_edit_output.setPlainText(out_text)
151159

160+
self.setWindowTitle(
161+
f'{self.TITLE} (number of characters: '
162+
f'{len(self.text_edit_input.toPlainText())} -> '
163+
f'{len(self.text_edit_output.toPlainText())})'
164+
)
152165
print('Escape for {:.6f} secs'.format(time.clock() - t))
153166

154167
except Exception as e:

0 commit comments

Comments
 (0)