-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmahir.class
588 lines (490 loc) · 13.9 KB
/
mahir.class
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
' Gambas class file
' Typoo --------------------------------------------
' Small software to learn fast typing
'
' Developers: --------------------------------------------------------
' Project Founder : Kusuma Negara <[email protected]>
' Programmer : Christian Kurniawan <[email protected]>
' Artwork Designer : Hamzah Fahrudin <[email protected]>
' Package Maintainer : Damar Riyadi <[email protected]>
' License : GPL GNU General Public License Version 2
'
' coded in Gambas 2.22 on Kubuntu 11.10 machine
'
' ---------------------------------------------------------------------------------------
' "Diluar sana orang bisa berbagi "emas". Meski saya cuma bisa berbagi "kerikil",
' setidaknya hal itu tidak mengurangi semangat berbagi saya untuk teman - teman
' semua"
'
' Semoga Aplikasi ini bisa bermanfaat untuk dunia pendidikan di Indonesia :)
'
'
' Thanks to:
' GAMBAS Creator
' ---------------------------------------------------------------------------------------
PUBLIC __text AS String
PUBLIC __start_type AS Boolean
PUBLIC __pos AS Integer
PUBLIC __char AS String
PUBLIC __error AS Integer
PUBLIC __type_count AS Integer
PUBLIC __time AS Integer
PUBLIC __start_time AS Date
PUBLIC __stop_type AS Boolean
PUBLIC __red_alert AS Boolean
PUBLIC __mulai_ngetik AS Boolean
PUBLIC __correct_typing AS Boolean
PUBLIC __is_capslock_on AS Boolean
PUBLIC __mode_typoo AS Integer
PUBLIC tuts_number AS Integer
PUBLIC key_function AS String = "4100,4097,4096,4144,4145,4146,4147,4148,4149,4150,4151,4152,4153,4154,4155,4134,4104,4102,4112,4118,4103,4113,4119,4114,4115,4117,4116,4133,4129,4179,4131"
PUBLIC func_array AS String[]
PRIVATE CONST MaxRecentFiles AS Integer = 5
PRIVATE RecentFiles AS NEW String[]
PRIVATE RecentMenus AS NEW Object[]
PRIVATE FirstLoad AS Boolean = FALSE
PRIVATE __lastOpenDir AS String
PUBLIC SUB _new()
init_key_function
LoadConfig
ME.Center
ME.Show
END
PUBLIC SUB detect_capslock()
'this code take from Stefano Palmeri post in gambas forum (http://gambasrad.org/zforum/view_topic?topic_id=1685)
DIM sShellOutput AS String
DIM iKeyLocks AS Integer
SHELL "xset q | grep 'LED mask:' | grep -o 0000000." TO sShellOutput
iKeyLocks = Val(sShellOutput)
SELECT iKeyLocks
CASE 0
__is_capslock_on = FALSE
CASE 1
__is_capslock_on = TRUE
CASE 2
__is_capslock_on = FALSE
CASE 3
__is_capslock_on = TRUE
END SELECT
END
PUBLIC SUB caps_indicator(show_indicator AS Boolean)
IF show_indicator = TRUE THEN
pict_caps_indicator__.Visible = TRUE
lb_caps_indicator__.Visible = TRUE
ELSE
pict_caps_indicator__.Visible = FALSE
lb_caps_indicator__.Visible = FALSE
ENDIF
END
PUBLIC SUB capslock_info()
'detect caps lock
detect_capslock
IF __is_capslock_on = TRUE THEN
caps_indicator(TRUE)
ELSE
caps_indicator(FALSE)
ENDIF
END
PUBLIC SUB init_key_function()
func_array = Split(key_function, ",")
END
PUBLIC SUB type_here___KeyPress()
DIM i AS Integer
'Case sensitive key code still not supported by Gambas
IF __start_type = FALSE THEN
Message.Info("Silahkan klik tombol Mulai untuk memulai")
STOP EVENT
RETURN
ENDIF
' Block some key function
FOR i = 0 TO func_array.Max
IF func_array[i] = Str(Key.Code) THEN
type_here__.SetFocus
STOP EVENT
RETURN
ENDIF
NEXT
IF __stop_type = FALSE THEN
IF Key.Code = Key.BackSpace THEN
STOP EVENT
RETURN
ENDIF
ENDIF
capslock_info
__char = Mid(__text, __pos, 1)
IF Asc(__char) >= 97 AND Asc(__char) <= 122 THEN ' letter a - z
detect_capslock
IF __is_capslock_on = TRUE THEN
__correct_typing = FALSE
'RETURN
GOTO checktype
ENDIF
IF Key.Code = Key[__char] AND IF Key.Shift THEN
__correct_typing = FALSE
ELSE IF Key.Code = Key[__char] THEN
__correct_typing = TRUE
ELSE
__correct_typing = FALSE
ENDIF
ELSE IF Asc(__char) >= 65 AND Asc(__char) <= 90 THEN ' letter A - Z
IF Key.Code = Key[__char] AND IF Key.Shift THEN
detect_capslock
IF __is_capslock_on = FALSE THEN
__correct_typing = TRUE
ELSE
__correct_typing = FALSE
ENDIF
ELSE
detect_capslock
IF __is_capslock_on = TRUE THEN
IF (Key.Code) = Key[__char] THEN
__correct_typing = TRUE
ELSE
__correct_typing = FALSE
ENDIF
ELSE
__correct_typing = FALSE
ENDIF
ENDIF
ELSE IF Asc(__char) >= 44 AND Asc(__char) <= 57 THEN ' number 0 - 9 dan some character
IF (Key.Code) = Key[__char] THEN
__correct_typing = TRUE
ELSE
__correct_typing = FALSE
ENDIF
ELSE IF (Asc(__char) = 32) OR (Asc(__char) = 39) OR (Asc(__char) = 59) OR (Asc(__char) = 61) OR (Asc(__char) = 91) OR (Asc(__char) = 92) OR (Asc(__char) = 93) OR (Asc(__char) = 96) THEN ' spasi 59 61 91 92 93 96
IF (Key.Code) = Key[__char] THEN
__correct_typing = TRUE
ELSE
__correct_typing = FALSE
ENDIF
ELSE IF Asc(__char) >= 33 AND Asc(__char) <= 38 THEN ' huruf ! - +
IF Key.Code = Key[__char] AND IF Key.Shift THEN
__correct_typing = TRUE
ELSE
__correct_typing = FALSE
ENDIF
ELSE IF Asc(__char) >= 40 AND Asc(__char) <= 43 THEN ' huruf ! - +
IF Key.Code = Key[__char] AND IF Key.Shift THEN
__correct_typing = TRUE
ELSE
__correct_typing = FALSE
ENDIF
ELSE IF (Asc(__char) = 58) OR (Asc(__char) = 60) OR (Asc(__char) = 62) OR (Asc(__char) = 63) OR (Asc(__char) = 64) OR (Asc(__char) = 94) OR (Asc(__char) = 95) OR (Asc(__char) = 126) OR (Asc(__char) = 123) OR (Asc(__char) = 124) OR (Asc(__char) = 125) THEN ' huruf ! - +
IF Key.Code = Key[__char] AND IF Key.Shift THEN
__correct_typing = TRUE
ELSE
__correct_typing = FALSE
ENDIF
ELSE
RETURN
ENDIF
checktype:
IF __stop_type = TRUE THEN
IF Key.Code = Key.BackSpace THEN
__stop_type = FALSE
RETURN
ELSE
__stop_type = TRUE
STOP EVENT
RETURN
ENDIF
ENDIF
IF __correct_typing = TRUE THEN
'// if correct typing then mark next letter with blue color
IF __pos <= Len(__text)
WITH board__
.Select(__pos, 1)
.Format.Color = Color.Blue
.Format.Font.Underline = TRUE
.Unselect
END WITH
ENDIF
'// if error typing, mark old letter with gray colors
WITH board__
.Select(__pos - 1, 1)
IF __red_alert = FALSE THEN
.Format.Color = &FF6600&
ELSE
.Format.Color = Color.Gray
ENDIF
.Format.Font.Underline = FALSE
.Unselect
END WITH
'// go to next letter
__pos = __pos + 1
__type_count = __type_count + 1
info_char__.Foreground = &HFFFF00&
__stop_type = FALSE
__red_alert = FALSE
ELSE '// user type wrong letter :(
'// if user press shift or capslock button don't record it as error :(
IF Key.Code = 4128 THEN 'key shift
__stop_type = __stop_type
RETURN
ENDIF
IF Key.Code = 4132 THEN 'key capslock
__stop_type = __stop_type
capslock_info
RETURN
ENDIF
'// don't record again if user have error before
IF __stop_type = FALSE THEN
__error = __error + 1
ENDIF
__pos = __pos
__stop_type = TRUE
char_error__.Text = Format(__error, "#,##")
'// show some error info with red color
info_char__.Foreground = Color.Red
WITH board__
.Select(__pos - 1, 1)
.Format.Color = Color.Red
.Format.Font.Underline = TRUE
.Unselect
END WITH
__red_alert = TRUE
ENDIF
IF __pos <= Len(__text) THEN
'// show detail information until no letter to type
info_char__.Text = Mid(__text, __pos, 1)
ELSE
stop_type___Click
ENDIF
END
PUBLIC SUB mn_open_Click()
' DIM texttemp AS String
'
' __text = ""
' texttemp = ""
' Dialog.Title = "Pilih berkas latihan..."
' Dialog.Filter = ["*", "Text File"]
' Dialog.Path = User.home
' IF Dialog.OpenFile(FALSE) THEN RETURN
' __text = Trim((File.Load(Dialog.Path)))
' texttemp = __text
' __text = Replace(__text, "<", "< ")
' __text = Replace(__text, ">", "> ")
' board__.Text = __text
' __text = texttemp
' texttemp = ""
' char_count__.Text = Format(Len(__text), "#,##")
OpenFileTutorial
END
PUBLIC SUB Board_Init()
__pos = 1
__type_count = 0
__error = 0
WITH board__
.SelectAll
.Format.Color = Color.Black
.Format.Font.Underline = FALSE
.Format.Alignment = Align.Justify
.Refresh
.Select(__pos - 1, 1)
.Format.Color = Color.Blue
.Format.Font.Underline = TRUE
.Unselect
END WITH
type_here__.SetFocus
END
PUBLIC SUB Board_First_Char()
__char = Mid(__text, __pos, 1)
char_error__.Caption = "0"
info_char__.Caption = __char
info_char__.ForeColor = &HFFFF00&
speed__.Caption = "0"
END
PUBLIC SUB Form_Activate()
type_here__.SetFocus
END
PUBLIC SUB start_type___Click()
IF Len(__text) = 0 THEN
Message.Info("Silahkan buka berkas tutorial")
RETURN
ENDIF
__start_type = TRUE
start_type__.Enabled = FALSE
stop_type__.Enabled = TRUE
mn_open.Enabled = FALSE
null_info
Board_Init
Board_First_Char
__time = 0
Init_Timer
END
PUBLIC SUB Init_Timer()
start_time__.Caption = Format(Time(Now), "hh:nn:ss")
__start_time = Time(Now)
stop_time__.Caption = "00:00:00"
Timer1.Enabled = TRUE
END
PUBLIC SUB null_info()
start_time__.Caption = "00:00:00"
stop_time__.Caption = "00:00:00"
info_char__.Caption = ""
char_error__.Caption = "0"
speed__.Caption = "0"
char_accuracy__.Caption = "0 %"
END
PUBLIC SUB Form_Close()
Timer1.Enabled = FALSE
FMain.Show
SaveConfig
END
PUBLIC SUB stop_type___Click()
__start_type = FALSE
start_type__.Enabled = TRUE
stop_type__.Enabled = FALSE
mn_open.Enabled = TRUE
Timer1.Enabled = FALSE
IF __type_count > 0 THEN
calculate_speed
calculate_accuracy
IF Len(__text) = __type_count THEN
Message.Info("Selesai")
ELSE
Message.Warning("diakhiri oleh pengguna")
ENDIF
ENDIF
END
PUBLIC SUB calculate_speed()
DIM speed AS Integer
stop_time__.Caption = Format(CDate(__start_time + Date(0, 0, 0, 0, 0, __time)), "hh:nn:ss")
speed = __type_count / (__time / 60)
speed__.Caption = speed
END
PUBLIC SUB calculate_accuracy()
DIM accuracy AS Integer
accuracy = ((__type_count - __error) / Len(__text)) * 100
char_accuracy__.Caption = accuracy & " %"
END
PUBLIC SUB Timer1_Timer()
__time = __time + 1
END
PUBLIC SUB mn_exit_Click()
ME.Close
END
PUBLIC SUB mn_recent1_Click()
IF FirstLoad = FALSE THEN
OpenFileTutorial(RecentFiles[0])
FirstLoad = TRUE
ENDIF
END
PUBLIC SUB mn_recent2_Click()
OpenFileTutorial(RecentFiles[1])
END
PUBLIC SUB mn_recent3_Click()
OpenFileTutorial(RecentFiles[2])
END
PUBLIC SUB mn_recent4_Click()
OpenFileTutorial(RecentFiles[3])
END
PUBLIC SUB mn_recent5_Click()
OpenFileTutorial(RecentFiles[4])
END
PRIVATE SUB OpenFileTutorial(OPTIONAL filePath AS String = "")
DIM texttemp AS String
DIM iIndex AS Integer
__text = ""
texttemp = ""
iIndex = -1 ' not in recent files
IF filePath <> "" THEN
IF Exist(filePath) = FALSE THEN
Message.Warning("File not exist, please choose another file.", "OK")
filePath = ""
ENDIF
ENDIF
IF filePath = "" THEN
Dialog.Title = "Select tutorial file..."
Dialog.Filter = ["*", "Text File"]
IF Exist(__lastOpenDir) = FALSE THEN
__lastOpenDir = User.Home
ENDIF
Dialog.Path = __lastOpenDir
IF Dialog.OpenFile(FALSE) THEN
RETURN
ENDIF
filePath = Dialog.Path
ENDIF
IF RecentFiles.Exist(filePath) THEN
iIndex = RecentFiles.Find(filePath)
IF iIndex > 0 THEN
RecentFiles.Remove(iIndex)
ENDIF
ENDIF
IF iIndex = -1 AND RecentFiles.Count = 0 THEN
RecentFiles.Add(filePath)
ELSE IF (iIndex = -1 AND RecentFiles.Count > 0) OR iIndex > 0 THEN
RecentFiles.Add(filePath, 0)
ENDIF
IF RecentFiles.Count > MaxRecentFiles THEN ' make sure RecentFiles.count is only 5
RecentFiles.Pop()
ENDIF
IF iIndex = -1 OR iIndex > 0 THEN
RearrangeSubMenuRecentFiles
ENDIF
IF mn_recentFiles.Enabled = FALSE THEN
mn_recentFiles.Enabled = TRUE
ENDIF
__lastOpenDir = DirPath(filePath)
__text = Trim((File.Load(filePath)))
texttemp = __text
__text = Replace(__text, "<", "< ")
__text = Replace(__text, ">", "> ")
board__.Text = __text
__text = texttemp
texttemp = ""
char_count__.Text = Format(Len(__text), "#,##")
END
PRIVATE SUB LoadConfig()
DIM filePath AS String
DIM i AS Integer
__lastOpenDir = Settings["Config/LastOpenDir", User.Home]
IF Exist(__lastOpenDir) = FALSE THEN __lastOpenDir = User.Home
FOR i = 1 TO MaxRecentFiles STEP 1
filePath = Settings["RecentFiles/File" & i, ""]
IF Len(filePath) > 0 THEN
RecentFiles.Add(filePath)
ELSE
BREAK
ENDIF
NEXT
RecentMenus.Add(mn_recent1)
RecentMenus.Add(mn_recent2)
RecentMenus.Add(mn_recent3)
RecentMenus.Add(mn_recent4)
RecentMenus.Add(mn_recent5)
IF RecentFiles.Count > 0 THEN
mn_recentFiles.Enabled = TRUE
FOR i = 0 TO RecentFiles.Count - 1 STEP 1
RecentMenus[i].Text = RecentFiles[i]
NEXT
ELSE
mn_recentFiles.Enabled = FALSE
ENDIF
RearrangeSubMenuRecentFiles
END
PRIVATE SUB SaveConfig()
DIM i AS Integer
Settings["Config/LastOpenDir"] = __lastOpenDir
FOR i = 1 TO RecentFiles.Count STEP 1
Settings["RecentFiles/File" & i] = RecentFiles[i - 1]
NEXT
END
PRIVATE FUNCTION DirPath(OPTIONAL filePath AS String = "") AS String
DIM filename AS String
DIM length AS Integer
DIM result AS String
filename = File.Name(filePath)
length = RInStr(filePath, filename) - 1
result = Left(filePath, length)
RETURN result
END
PRIVATE FUNCTION RearrangeSubMenuRecentFiles()
DIM i AS Integer
FOR i = 0 TO RecentFiles.Count - 1 STEP 1
RecentMenus[i].Text = RecentFiles[i]
IF RecentMenus[i].Visible = FALSE THEN RecentMenus[i].Visible = TRUE
NEXT
END