-
Notifications
You must be signed in to change notification settings - Fork 0
/
frontend.py
1472 lines (1165 loc) · 69.5 KB
/
frontend.py
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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from math import ceil
from functools import partial
import webbrowser
import threading
import paradigm_panes
import os
import time
from kivy.properties import ObjectProperty
from kivy.clock import Clock, mainthread
from kivy.app import App
from kivy.metrics import dp
from kivy.properties import StringProperty, BooleanProperty, NumericProperty
from kivy.uix.image import Image
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.screenmanager import ScreenManager
from kivy.uix.button import ButtonBehavior
from kivy.uix.label import Label
from kivy.core.window import Window
from kivy.core.audio import SoundLoader
from kivy.storage.jsonstore import JsonStore
from kivymd.app import MDApp
from kivymd.uix.list import MDList, OneLineListItem, OneLineIconListItem, IconLeftWidget
from kivymd.uix.screen import MDScreen
from kivymd.uix.card import MDCard, MDSeparator
from kivymd.uix.tooltip import MDTooltip
from kivymd.uix.button import MDIconButton
from kivymd.uix.label import MDLabel
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.menu import MDDropdownMenu
from kivymd.uix.spinner import MDSpinner
from kivymd.uix.selectioncontrol import MDCheckbox
from kivymd.toast import toast
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelOneLine, MDExpansionPanelTwoLine
from cree_sro_syllabics import sro2syllabics
from uiToBackendConnector import getSearchResultsFromQuery
from api.api import get_sound
from shared.generalData import SOUND_FILE_NAME, LEGEND_OF_ABBREVIATIONS_TEXT, CONTACT_US_TEXT, HELP_CONTACT_FORM_LINK, ABOUT_TEXT_SOURCE_MATERIALS, ABOUT_TEXT_CREDITS, ABOUT_URL_LINKS, LABEL_TYPES, PARADIGM_LABEL_TYPES, PARADIGM_PANES_AVAILABLE
from shared.generalFunctions import cells_contains_only_column_labels, is_core_column_header, replace_hats_to_lines_SRO, getHeaderAndSubheader, SoundAPIResponse
from backend.frontendShared.relabelling import relabel, relabel_source
######################################################
# Global variable declarations
######################################################
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
######################################################
# Custom component declarations
######################################################
class ClickableLabel(ButtonBehavior, MDLabel):
pass
class ClickableImage(ButtonBehavior, Image):
pass
class InfoTooltipButton(MDIconButton, MDTooltip):
pass
class MainLoaderSpinner(MDSpinner):
pass
class SoundLoadSpinner(MDSpinner):
pass
class AboutMDList(MDList):
pass
class DrawerList(MDList):
pass
class LabelSettingsItem(OneLineListItem):
text = StringProperty()
######################################################
# Custom screens declarations
######################################################
class HomeScreen(MDScreen):
pass
class ResultScreen(MDScreen):
pass
class LegendOfAbbrPage(MDScreen):
pass
class ContactUsScreen(MDScreen):
pass
class AboutScreen(MDScreen):
pass
class ResultPageMainLayout(MDBoxLayout):
pass
class LegendPageMainLayout(MDBoxLayout):
pass
class ContactPageMainLayout(MDBoxLayout):
pass
class AboutPageMainLayout(MDBoxLayout):
pass
class ContentNavigationDrawer(MDBoxLayout):
pass
######################################################
# Logic componenents
######################################################
class ParadigmExpansionPanel(MDExpansionPanel):
'''
This class represents each paradigm panel added on the second specific result page.
'''
def __init__(self, isFirst, dynamicHeight, **kwargs ):
super().__init__(**kwargs)
self.isFirst = isFirst
self.dynamicHeight = dynamicHeight
Clock.schedule_once(self.openFirstPanel, 0)
def openFirstPanel(self, args):
if self.isFirst:
self.height += self.dynamicHeight
self.open_panel()
class EmojiSwitch(MDCheckbox):
'''
This class represents the emoji display switch in the options of drawer navigation.
'''
def changeMode(self, currentQuery, lingMode):
searchResultsList = getSearchResultsFromQuery(currentQuery, lingMode)
Clock.schedule_once(partial(self.updateEmojiForUI, searchResultsList))
time.sleep(1)
def updateEmojiForUI(self, prefetched_list, *args):
app = App.get_running_app()
store = JsonStore('store.json')
if self.active:
app.displayEmojiMode = True
store.put('displayEmojiMode', displayEmojiMode = True)
else:
app.displayEmojiMode = False
store.put('displayEmojiMode', displayEmojiMode = False)
app.root.ids.mainBoxLayout.onSubmitWord(prefetchedSearchResultsList=prefetched_list)
specificResultPagePopulationList = app.root.ids.specificResultPageMainListLayout
app.root.ids.specificResultPageMainListLayout.populate_page( specificResultPagePopulationList.title,
specificResultPagePopulationList.emojis,
app.latestSpecificResultPageMainList[app.latestResultClickIndex]['subtitle'] if app.latestResultClickIndex is not None else "",
specificResultPagePopulationList.defaultTitleText,
specificResultPagePopulationList.inflectionalCategory,
specificResultPagePopulationList.paradigm_type,
specificResultPagePopulationList.lemmaParadigmType,
specificResultPagePopulationList.definitions)
app.main_loader_spinner_toggle()
def emoji_display_thread(self):
app = App.get_running_app()
app.main_loader_spinner_toggle()
current_query = app.root.ids.input_word.text
lingMode = "community"
if app.selectedParadigmOptionIndex == 1:
lingMode = "linguistic"
elif app.selectedParadigmOptionIndex == 2:
lingMode = "source_language"
threading.Thread(target=(self.changeMode), args=[current_query, lingMode]).start()
class InflectionalSwitch(MDCheckbox):
'''
This class represents the inflectional category display switch
in the options of drawer navigation.
'''
def changeMode(self):
app = App.get_running_app()
store = JsonStore('store.json')
if self.active:
app.displayInflectionalCategory = True
store.put('displayInflectionalCategory', displayInflectionalCategory = True)
else:
app.displayInflectionalCategory = False
store.put('displayInflectionalCategory', displayInflectionalCategory = False)
app.root.ids.mainBoxLayout.onSubmitWord()
specificResultPagePopulationList = app.root.ids.specificResultPageMainListLayout
app.root.ids.specificResultPageMainListLayout.populate_page( specificResultPagePopulationList.title,
specificResultPagePopulationList.emojis,
app.latestSpecificResultPageMainList[app.latestResultClickIndex]['subtitle'] if app.latestResultClickIndex is not None else "",
specificResultPagePopulationList.defaultTitleText,
specificResultPagePopulationList.inflectionalCategory,
specificResultPagePopulationList.paradigm_type,
specificResultPagePopulationList.lemmaParadigmType,
specificResultPagePopulationList.definitions)
class ParadigmLabelContent(MDBoxLayout):
'''
This class represents the main box layout of paradigm panes in the main list.
We just attach one copy of this class to the main layout MDList.
'''
def __init__(self, data, **kwargs ):
super().__init__(**kwargs)
self.data = data
self.orientation = 'vertical'
self.padding = "20dp"
self.spacing = "20dp"
Clock.schedule_once(self.populate_content, 0)
def populate_content(self, args):
'''
Population of each expansion panel
'''
root = App.get_running_app().root
app = App.get_running_app()
self.add_widget(MDLabel(text = "", size_hint = (1, 0.1)))
layout_row_list = MDList()
paradigm_parameter = ["english", "linguistic", "source_language"]
# Prepare the paradigm data and add it to the screen
for row in self.data['tr_rows']:
row_box_layout = MDBoxLayout(height="40dp", size_hint = (1, None))
if row['is_header']:
txt_label = relabel(row['label'], paradigm_parameter[app.selectedParadigmOptionIndex])
if app.selectedParadigmOptionIndex == 2:
# source language labels
txt_label = app.get_syllabics_sro_correct_label(txt_label)
txt_label = "[font=bjcrus.ttf]" + txt_label + "[/font]"
txt_label = "[i]" + txt_label + "[/i]"
row_box_layout.add_widget(Label(text = txt_label,
markup = True,
size_hint = (0.05, None),
pos_hint = {'center_x': 0.5},
color= (0, 0, 0, 1)))
else:
for cell in row['cells']:
if cell['should_suppress_output']:
continue
elif cell['is_label']:
paradigmLabelText = relabel(cell['label'], paradigm_parameter[app.selectedParadigmOptionIndex])
paradigmLabelText = paradigmLabelText.replace("→", "->")
if app.selectedParadigmOptionIndex == 2:
paradigmLabelText = app.get_syllabics_sro_correct_label(paradigmLabelText)
paradigmLabelText = "[font=bjcrus.ttf]" + paradigmLabelText + "[/font]"
paradigmLabelText = "[i]" + paradigmLabelText + "[/i]"
row_box_layout.add_widget(Label(text = paradigmLabelText,
markup = True,
size_hint = (0.05, None),
pos_hint = {'center_x': 0.5},
color= (0, 0, 0, 1)))
elif cell['is_missing'] or cell['is_empty']:
row_box_layout.add_widget(Label(text = "--",
size_hint = (0.05, None),
pos_hint = {'center_x': 0.5},
color= (0, 0, 0, 1)))
else:
txt_label = app.get_syllabics_sro_correct_label(cell['inflection'])
row_box_layout.add_widget(Label(text = txt_label,
size_hint = (0.05, None),
pos_hint = {'center_x': 0.5},
color= (0, 0, 0, 1),
font_name = 'bjcrus.ttf'))
layout_row_list.add_widget(row_box_layout)
self.add_widget(layout_row_list)
# self.add_widget(within_paradigm_scrollview)
class WindowManager(ScreenManager):
'''
This is the navigation manager within the app.
Any screen changes should be declared here.
'''
def __init__(self, **kwargs):
super(WindowManager, self).__init__(**kwargs)
def switch_to_result_screen(self, _, title, emojis, subtitle, defaultTitleText, inflectionalCategory, paradigm_type, definitions):
root = App.get_running_app().root
root.ids.specificResultPageMainListLayout.populate_page(title, emojis, subtitle, defaultTitleText, inflectionalCategory, paradigm_type, None, definitions)
self.transition.direction = "left"
self.current = "Result"
def launchSpecificResultPageOnLemmaClick(self, lemma, _, emojis, subtitle, defaultTitleText, inflectionalCategory, paradigm_type, lemmaParadigmType, definitions):
root = App.get_running_app().root
# root.ids.option_clicked.text = lemma
root.ids.specificResultPageMainListLayout.populate_page(lemma, emojis, subtitle, defaultTitleText, inflectionalCategory, paradigm_type, lemmaParadigmType, definitions)
self.transition.direction = "left"
self.current = "Result"
def switch_back_home_screen(self):
self.transition.direction = "right"
self.current = "Home"
def switch_to_legend_screen(self):
root = App.get_running_app().root
root.ids.drawerNavigator.set_state("close")
self.current = "Legend"
def switch_to_contact_screen(self):
root = App.get_running_app().root
root.ids.drawerNavigator.set_state("close")
self.current = "Contact"
def switch_to_about_screen(self):
root = App.get_running_app().root
root.ids.drawerNavigator.set_state("close")
self.current = "About"
class MainLayout(BoxLayout):
'''
This class is the main layout of the app (the first launch page).
'''
def onSubmitWord(self, widget= None, prefetchedSearchResultsList = None):
root = App.get_running_app().root
app = App.get_running_app()
current_query = root.ids.input_word.text
if not current_query:
# Empty query
print("Empty query")
return
lingMode = "community"
if app.selectedParadigmOptionIndex == 1:
lingMode = "linguistic"
elif app.selectedParadigmOptionIndex == 2:
lingMode = "source_language"
output_res = prefetchedSearchResultsList
if prefetchedSearchResultsList is None:
output_res = getSearchResultsFromQuery(current_query, lingMode)
resultToPrint = output_res.copy()
self.displayResultList(resultToPrint)
def displayResultList(self, data_list):
'''
This method goes through the output from the backend and serializes
it to make it UI-friendly.
'''
initialSearchResultsList = []
result_id_counter = 0
app = App.get_running_app()
for data in data_list:
title = data['lemma_wordform']['text'] if data['is_lemma'] else data['wordform_text']
defaultTitleText = data['lemma_wordform']['text'] if data['is_lemma'] else data['wordform_text']
paradigm_type = data['lemma_wordform']['paradigm'] if data['is_lemma'] else None
lemmaParadigmType = None
# Note that the ic can also be set using relabel_plain_english and relabel_linguistic_long
inflectionalCategory = data['lemma_wordform']['inflectional_category'] if data['is_lemma'] or (not data['is_lemma'] and data['show_form_of']) else "None"
ic = data['lemma_wordform']['inflectional_category_plain_english']
if app.selectedParadigmOptionIndex == 1:
ic = data['lemma_wordform']['inflectional_category_linguistic']
if ic is not None and 'linguist_info' in data['lemma_wordform'] and data['lemma_wordform']['linguist_info']['inflectional_category'] is not None:
ic += " (" + data['lemma_wordform']['linguist_info']['inflectional_category'] + ")"
if app.selectedParadigmOptionIndex == 2 and inflectionalCategory != "None":
ic = relabel_source(inflectionalCategory)
emoji = data['lemma_wordform']['wordclass_emoji']
emojis = ""
subtitle = ""
defs = []
if emoji:
updated_emoji = emoji.replace("🧑🏽", "🧑")
emojis += updated_emoji
# if ic and emoji:
# subtitle += "-"
if ic:
subtitle += ic
lemma_definitions = []
if not data['is_lemma'] and data['show_form_of']:
result_defs = data['lemma_wordform']['definitions']
flag = 1
for lemma_def in result_defs:
lemma_definitions.append(str(flag) + ". " + lemma_def['text'])
flag += 1
flag = 1
for definition in data['definitions']:
defs.append(str(flag) + ". " + definition['text'])
flag += 1
defaultLemmaTitleText = data['lemma_wordform']['text']
if app.labelTypeIndexSelected == 2:
# Syllabics selected
title = sro2syllabics(title)
if not data['is_lemma'] and data['show_form_of']:
data['lemma_wordform']['text'] = sro2syllabics(data['lemma_wordform']['text'])
elif app.labelTypeIndexSelected == 1:
# ēīōā selected
title = replace_hats_to_lines_SRO(title)
if not data['is_lemma'] and data['show_form_of']:
data['lemma_wordform']['text'] = replace_hats_to_lines_SRO(data['lemma_wordform']['text'])
defsToPass = defs.copy()
dynamic_tile_height = 0
for d in defsToPass:
dynamic_tile_height += 30
dynamic_tile_height += int(ceil(len(d) / 30)) * 35
if not data['is_lemma'] and data['show_form_of']:
lemmaParadigmType = data['lemma_wordform']['paradigm']
dynamic_tile_height += 15
for d in lemma_definitions:
dynamic_tile_height += 30
dynamic_tile_height += int(ceil(len(d) / 30)) * 35
# If linguistic mode, increase dynamic height to give space for the larger subtitle
if app.selectedParadigmOptionIndex == 1 or app.selectedParadigmOptionIndex == 2:
dynamic_tile_height += 20
initialSearchResultsList.append({'index': result_id_counter,
'defaultTitleText': defaultTitleText,
'height': dp(max(100, dynamic_tile_height)),
'title': title,
'emojis': emojis,
'subtitle': subtitle,
'inflectionalCategory': inflectionalCategory,
'paradigm_type': paradigm_type,
'lemmaParadigmType': lemmaParadigmType,
'lemma_definitions': lemma_definitions,
'friendly_linguistic_breakdown_head': data['friendly_linguistic_breakdown_head'],
'friendly_linguistic_breakdown_tail': data['friendly_linguistic_breakdown_tail'],
'relabelled_fst_analysis': data['relabelled_fst_analysis'],
'is_lemma': data['is_lemma'] if 'is_lemma' in data else True,
'show_form_of': data['show_form_of'] if 'show_form_of' in data else False,
'defaultLemmaTitleText': defaultLemmaTitleText,
'lemma_wordform': data['lemma_wordform'] if 'lemma_wordform' in data else None,
'definitions': defsToPass
})
result_id_counter += 1
if len(initialSearchResultsList) == 0:
root = App.get_running_app().root
initialSearchResultsList.append({'index': -1, 'title': 'No results found!', 'definitions': [root.ids.input_word.text]})
root = App.get_running_app().root
root.ids.result_list_main.update_data(initialSearchResultsList)
class ResultView(RecycleView):
def __init__(self, **kwargs):
super(ResultView, self).__init__(**kwargs)
self.data = []
def update_data(self, data):
app = App.get_running_app()
self.data = data.copy()
app.latestSpecificResultPageMainList = data.copy()
self.refresh_from_data()
class ResultWidget(RecycleDataViewBehavior, MDBoxLayout):
'''
This class represents the view class of every result from the search query
on the main page (results list page).
'''
_latest_data = None
_rv = None
index = ObjectProperty()
defaultTitleText = ObjectProperty()
title = ObjectProperty()
subtitle = ObjectProperty()
emojis = ObjectProperty()
inflectionalCategory = ObjectProperty()
paradigm_type = ObjectProperty(allownone = True)
lemmaParadigmType = ObjectProperty(allownone = True)
lemma_definitions = ObjectProperty()
friendly_linguistic_breakdown_head = ObjectProperty()
friendly_linguistic_breakdown_tail = ObjectProperty()
relabelled_fst_analysis = ObjectProperty()
is_lemma = ObjectProperty()
show_form_of = ObjectProperty()
defaultLemmaTitleText = ObjectProperty()
lemma_wordform = ObjectProperty()
# ---------------------------------------------------
# Any new properties should be added above definitions for proper rendering
definitions = ObjectProperty()
def __init__(self,**kwargs):
super().__init__(**kwargs)
Clock.schedule_once(self.row_initialization, 0)
def refresh_view_attrs(self, rv, index, data):
self._rv = rv
if self._latest_data is not None:
self._latest_data["height"] = self.height
self._latest_data = data
super(ResultWidget, self).refresh_view_attrs(rv, index, data)
def on_height(self, instance, value):
data = self._latest_data
if data is not None and data["height"] != value:
data["height"] = value
self._rv.refresh_from_data()
def row_initialization(self, *args):
if self.index != -1:
app = App.get_running_app()
title_icon_box_layout = BoxLayout()
main_title_label_text_markup = "[font=bjcrus.ttf][color=4C0121][size=20dp][u]" + self.title + "[/u][/size][/color][/font]"
if not self.is_lemma and self.show_form_of:
main_title_label_text_markup = "[font=bjcrus.ttf]" + self.title + "[/font]"
title_label = Label(text="[font=bjcrus.ttf][color=4C0121][size=20dp][u]" + self.title + "[/u][/size][/color][/font]", markup=True)
title_label._label.refresh()
title_label_width = title_label._label.texture.size[0] + 10
title_label = ClickableLabel(text=main_title_label_text_markup,
markup=True,
on_release=self.on_click_label,
size_hint=(None, 1),
width = title_label._label.texture.size[0] + 10)
title_icon_box_layout.add_widget(title_label)
tooltip_and_sound_float_layout = FloatLayout(size=(150, 150))
if self.friendly_linguistic_breakdown_head or self.friendly_linguistic_breakdown_tail:
tooltip_content = ""
for chunk in self.relabelled_fst_analysis:
chunk_label = chunk['label']
if len(chunk_label) > 0:
chunk_label = chunk_label.replace("→", "->")
tooltip_content += chunk_label + "\n"
if len(tooltip_content) > 0:
tooltip_content = tooltip_content[:-1]
tooltip_and_sound_float_layout.add_widget(InfoTooltipButton(icon="information",
tooltip_text= tooltip_content,
icon_size="19dp",
shift_y="100dp",
size_hint_x = 0.5,
pos_hint = {'center_y': 0.5},
pos=(app.root.ids.input_word.pos[0] + title_label_width, title_label_width)))
tooltip_and_sound_float_layout.add_widget(InfoTooltipButton(icon="volume-high",
icon_size="19dp",
on_release=self.play_sound,
size_hint_x = 0.5,
pos_hint = {'center_y': 0.5},
pos=(app.root.ids.input_word.pos[0] + title_label_width + 60, title_label_width + 60)))
title_icon_box_layout.add_widget(tooltip_and_sound_float_layout)
self.add_widget(title_icon_box_layout)
# Add the line here.
if not self.is_lemma and self.show_form_of:
for definition in self.definitions:
definition_label = MDLabel(text=definition)
self.add_widget(definition_label)
# Add the "form of" first
form_of_box_layout = BoxLayout()
form_of = Label(text="[size=14dp][i]form of[/i][/size]", markup=True)
form_of._label.refresh()
form_of = MDLabel(text="[size=14dp][i]form of[/i][/size]",
markup = True,
size_hint=(None, 1),
width = form_of._label.texture.size[0] + 10)
form_of_box_layout.add_widget(form_of)
lemma_wordform_text = "[size=14dp][font=bjcrus.ttf][u][color=4C0121]" + self.lemma_wordform['text'] + "[/color][/u][/font][/size]"
form_of_lemma = ClickableLabel(text=lemma_wordform_text,
markup=True,
on_release=self.on_click_form_of_lemma
)
form_of_box_layout.add_widget(form_of_lemma)
self.add_widget(form_of_box_layout)
line_break = MDSeparator()
self.add_widget(line_break)
form_of_lemma2 = ClickableLabel(text=lemma_wordform_text,
markup=True,
on_release=self.on_click_form_of_lemma
)
self.add_widget(form_of_lemma2)
description_box_layout = BoxLayout()
app = App.get_running_app()
# Add the inflectional category only if the option is on
if app.displayInflectionalCategory:
inflection_label = Label(text="[size=15dp]" + self.inflectionalCategory + "[/size]", markup=True)
inflection_label._label.refresh()
inflection_label = MDLabel(text="[size=15dp]" + self.inflectionalCategory + "[/size]",
markup=True,
size_hint=(None, 1),
width=inflection_label._label.texture.size[0] + 5)
description_box_layout.add_widget(inflection_label)
additional_emoji_margin = 0 if not self.emojis else 10
emoji_label = Label(text="[size=15dp][font=NotoEmoji-Regular.ttf]" + self.emojis + "[/font][/size]", markup=True)
emoji_label._label.refresh()
emoji_label = MDLabel(text="[size=15dp][font=NotoEmoji-Regular.ttf]" + self.emojis + "[/font][/size]",
markup=True,
size_hint=(None, 1),
width=emoji_label._label.texture.size[0] + additional_emoji_margin)
if self.subtitle == "":
self.subtitle = "None"
desc_label = MDLabel(text="[size=15dp]" + self.subtitle + "[/size]", markup=True)
if app.displayEmojiMode == True:
description_box_layout.add_widget(emoji_label)
description_box_layout.add_widget(desc_label)
self.add_widget(description_box_layout)
definitions_to_display = self.definitions
if not self.is_lemma and self.show_form_of:
definitions_to_display = self.lemma_definitions
for definition in definitions_to_display:
definition_label = MDLabel(text="[size=14dp]" + definition + "[/size]", markup = True)
self.add_widget(definition_label)
else:
root = App.get_running_app().root
self.add_widget(MDLabel(text="[color=800000]" + "No results found for [b][i]<<" + root.ids.input_word.text + ">>" + "[/i][/b][/color]",
markup=True,
halign= 'center'))
self.bind(definitions = self.update_row, lemma_wordform = self.update_row)
def update_row(self, *args):
self.clear_widgets()
if self.index == -1:
root = App.get_running_app().root
self.add_widget(MDLabel(text="[color=800000]" + "No results found for [b][i]<<" + root.ids.input_word.text + ">>" + "[/i][/b][/color]",
markup=True,
halign= 'center'))
return
title_icon_box_layout = BoxLayout()
main_title_label_text_markup = "[font=bjcrus.ttf][u][color=4C0121][size=20dp]" + self.title + "[/size][/color][/u][/font]"
if not self.is_lemma and self.show_form_of:
main_title_label_text_markup = "[font=bjcrus.ttf]" + self.title + "[/font]"
title_label = Label(text="[font=bjcrus.ttf][u][color=4C0121][size=20dp]" + self.title + "[/size][/color][/u][/font]", markup=True)
title_label._label.refresh()
title_label_width = title_label._label.texture.size[0] + 10
title_label = ClickableLabel(text=main_title_label_text_markup,
markup=True,
on_release=self.on_click_label,
size_hint=(None, 1),
width = title_label._label.texture.size[0] + 10)
title_icon_box_layout.add_widget(title_label)
tooltip_and_sound_float_layout = FloatLayout(size=(150, 150))
app = App.get_running_app()
if self.friendly_linguistic_breakdown_head or self.friendly_linguistic_breakdown_tail:
tooltip_content = ""
for chunk in self.relabelled_fst_analysis:
chunk_label = chunk['label']
if len(chunk_label) > 0:
chunk_label = chunk_label.replace("→", "->")
tooltip_content += chunk_label + "\n"
if len(tooltip_content) > 0:
tooltip_content = tooltip_content[:-1]
tooltip_and_sound_float_layout.add_widget(InfoTooltipButton(icon="information",
tooltip_text= tooltip_content,
shift_y="100dp",
icon_size="19dp",
size_hint_x = 0.5,
pos_hint = {'center_y': 0.5},
pos = (app.root.ids.input_word.pos[0] + title_label_width, title_label_width)))
tooltip_and_sound_float_layout.add_widget(InfoTooltipButton(icon="volume-high",
icon_size="19dp",
on_release=self.play_sound,
size_hint_x = 0.5,
pos_hint = {'center_y': 0.5},
pos = (app.root.ids.input_word.pos[0] + title_label_width + 60, title_label_width)))
title_icon_box_layout.add_widget(tooltip_and_sound_float_layout)
self.add_widget(title_icon_box_layout)
if not self.is_lemma and self.show_form_of:
for definition in self.definitions:
definition_label = MDLabel(text=definition)
self.add_widget(definition_label)
# Add the "form of" first
form_of_box_layout = BoxLayout()
form_of = Label(text="[size=14dp][i]form of[/i][/size]", markup=True)
form_of._label.refresh()
form_of = MDLabel(text="[size=14dp][i]form of[/i][/size]",
markup = True,
size_hint=(None, 1),
width = form_of._label.texture.size[0] + 10)
form_of_box_layout.add_widget(form_of)
lemma_wordform_text = "[size=14dp][font=bjcrus.ttf][u][color=4C0121]" + self.lemma_wordform['text'] + "[/color][/u][/font][/size]"
app = App.get_running_app()
form_of_lemma = ClickableLabel(text=lemma_wordform_text,
markup=True,
on_release=self.on_click_form_of_lemma
)
form_of_box_layout.add_widget(form_of_lemma)
self.add_widget(form_of_box_layout)
line_break = MDSeparator()
self.add_widget(line_break)
form_of_lemma2 = ClickableLabel(text=lemma_wordform_text,
markup=True,
on_release=self.on_click_form_of_lemma
)
self.add_widget(form_of_lemma2)
description_box_layout = BoxLayout()
app = App.get_running_app()
# Add the inflectional category
if app.displayInflectionalCategory:
inflection_label = Label(text="[size=15dp]" + self.inflectionalCategory + "[/size]", markup=True)
inflection_label._label.refresh()
inflection_label = MDLabel(text="[size=15dp]" + self.inflectionalCategory + "[/size]",
markup=True,
size_hint=(None, 1),
width=inflection_label._label.texture.size[0] + 5)
description_box_layout.add_widget(inflection_label)
additional_emoji_margin = 0 if not self.emojis else 10
emoji_label = Label(text="[size=15dp][font=NotoEmoji-Regular.ttf]" + self.emojis + "[/font][/size]", markup=True)
emoji_label._label.refresh()
emoji_label = MDLabel(text="[size=15dp][font=NotoEmoji-Regular.ttf]" + self.emojis + "[/font][/size]",
markup=True,
size_hint=(None, 1),
width=emoji_label._label.texture.size[0] + additional_emoji_margin)
if self.subtitle == "":
self.subtitle = "None"
desc_label = MDLabel(text="[size=15dp]" + self.subtitle + "[/size]", markup=True)
if app.displayEmojiMode == True:
description_box_layout.add_widget(emoji_label)
description_box_layout.add_widget(desc_label)
self.add_widget(description_box_layout)
definitions_to_display = self.definitions
if not self.is_lemma and self.show_form_of:
definitions_to_display = self.lemma_definitions
for definition in definitions_to_display:
definition_label = MDLabel(text="[size=14dp]" + definition + "[/size]", markup = True)
self.add_widget(definition_label)
def on_click_label(self, touch):
if not self.is_lemma and self.show_form_of:
# Shouldn't be clicked/redirected.
return
app = App.get_running_app()
root = App.get_running_app().root
app.latestResultClickIndex = self.index
root.ids.screen_manager.switch_to_result_screen(self.index, self.title, self.emojis, self.subtitle, self.defaultTitleText, self.inflectionalCategory, self.paradigm_type, self.definitions)
def on_click_form_of_lemma(self, touch):
root = App.get_running_app().root
lemma = self.lemma_wordform['text']
root.ids.screen_manager.launchSpecificResultPageOnLemmaClick(lemma, self.title, self.emojis, self.subtitle, self.defaultLemmaTitleText, self.inflectionalCategory, self.paradigm_type, self.lemmaParadigmType, self.definitions)
def play_sound(self, touch):
audioFetchStatus = get_sound(self.defaultTitleText)
if audioFetchStatus == SoundAPIResponse.CONNECTION_ERROR:
toast("This feature needs a reliable internet connection.")
return
elif audioFetchStatus == SoundAPIResponse.NO_AUDIO_AVAILABLE:
toast("No recording available for this word.")
return
elif audioFetchStatus == SoundAPIResponse.API_NO_HIT:
# No audio found
toast("Audio currently unavailable.")
return
toast("Playing sound...", duration = 1)
# Instead of audio URL, play the file just loaded
sound = SoundLoader.load(SOUND_FILE_NAME)
if sound:
sound.play()
class SpecificResultMainList(MDList):
'''
This is the specific result page (2nd page) main list where
title, description, panes, etc. are added in order.
'''
def __init__(self,**kwargs):
super().__init__(**kwargs)
self.title = None
self.emojis = None
self.subtitle = None
self.defaultTitleText = None
self.inflectionalCategory = None
self.paradigm_type = None
self.lemmaParadigmType = None
self.definitions = None
def populate_page(self, title, emojis, subtitle, defaultTitleText, inflectionalCategory, paradigm_type, lemmaParadigmType, definitions):
'''
Populates the second result-specific page
'''
self.title = title
self.emojis = emojis
self.subtitle = subtitle
self.defaultTitleText = defaultTitleText
self.inflectionalCategory = inflectionalCategory
self.paradigm_type = paradigm_type
self.lemmaParadigmType = lemmaParadigmType
self.definitions = definitions
app = App.get_running_app()
root = App.get_running_app().root
self.clear_widgets()
if title is None and defaultTitleText is None and definitions is None:
# This page is still empty, don't do anything!
return
dynamic_details_height = 0
for d in definitions:
dynamic_details_height += max(int(ceil(len(d) / 30)) * 40, 60)
details_box_layout_height = max(dynamic_details_height, 100)
top_details_box_layout = MDBoxLayout(orientation = "vertical",
padding = "20dp",
spacing = "30dp",
size_hint = (1, None),
height= str(details_box_layout_height) + "dp")
title_and_sound_boxlayout = BoxLayout(size_hint = (1, 0.000001))
txt_main_title = app.get_syllabics_sro_correct_label(title)
title_label = Label(text="[font=bjcrus.ttf][size=20dp]" + txt_main_title + "[/font][/size]", markup=True)
title_label._label.refresh()
title_label = MDLabel(text = "[font=bjcrus.ttf][size=20dp]" + txt_main_title + "[/size][/font]",
markup=True,
valign = "bottom",
size_hint=(None, 1),
text_size=title_label._label.size,
width = title_label._label.texture.size[0] + 10,
height = title_label._label.texture.size[1] + 10)
title_and_sound_boxlayout.add_widget(title_label)
# Get sound playing to work
title_and_sound_boxlayout.add_widget(InfoTooltipButton(icon="volume-high",
icon_size="16dp",
on_release=self.play_sound,
pos_hint={'center_y': 1}))
# Add loading spinner
title_and_sound_boxlayout.add_widget(SoundLoadSpinner())
top_details_box_layout.add_widget(title_and_sound_boxlayout)
# Add description
description_box_layout = MDBoxLayout(size_hint = (1, 0.5))
# Add the inflectional category
if app.displayInflectionalCategory:
inflection_label = Label(text="[size=14dp]" + self.inflectionalCategory + "[/size]", markup=True)
inflection_label._label.refresh()
inflection_label = MDLabel(text="[size=14dp]" + self.inflectionalCategory + "[/size]",
markup=True,
size_hint=(None, 1),
width=inflection_label._label.texture.size[0] + 5)
description_box_layout.add_widget(inflection_label)
additional_emoji_margin = 0 if not emojis else 10
emoji_label = Label(text="[size=14dp][font=NotoEmoji-Regular.ttf]" + emojis + "[/font][/size]", markup=True)
emoji_label._label.refresh()
emoji_label = MDLabel(text="[size=14dp][font=NotoEmoji-Regular.ttf]" + emojis + "[/font][/size]",
markup=True,
size_hint=(None, 1),
width=emoji_label._label.texture.size[0] + additional_emoji_margin)
desc_label = MDLabel(text="[size=14dp]" + subtitle + "[/size]", markup=True)
if app.displayEmojiMode:
description_box_layout.add_widget(emoji_label)
description_box_layout.add_widget(desc_label)
top_details_box_layout.add_widget(description_box_layout)
# Add definitions
for definition in definitions:
top_details_box_layout.add_widget(MDLabel(text = "[size=13dp]" + definition + "[/size]", markup = True))