TextInput to display Korean characters

146 views
Skip to first unread message

Titus Cheng

unread,
Nov 8, 2016, 12:35:41 AM11/8/16
to Kivy users support
I have been working on this problem for a while and can't seem to find an answer to solve this particular problem.  I have a string that reads from a file which contains both English and Korean characters.  But the Korean text that comes out is a box with an 'x' inside.  I used unicode encoding and the Korean words are still not displaying problem. Any help would be appreciated.

ZenCODE

unread,
Nov 8, 2016, 1:25:43 AM11/8/16
to Kivy users support
Try a posting a minimal example which we can help with.

Titus Cheng

unread,
Nov 8, 2016, 1:31:21 AM11/8/16
to Kivy users support


On Monday, November 7, 2016 at 9:35:41 PM UTC-8, Titus Cheng wrote:
I have been working on this problem for a while and can't seem to find an answer to solve this particular problem.  I have a string that reads from a file which contains both English and Korean characters.  But the Korean text that comes out is a box with an 'x' inside.  I used unicode encoding and the Korean words are still not displaying problem. Any help would be appreciated.

def openFile(self, fname):
        file = codecs.open(fname, encoding='utf-8')
        file_str = file.read()
        file.close()
        return file_str 

def test(self, obj):
        MainApp.sourceInput.text = MainApp.fs.openFile(obj.text)
example.tiff

ZenCODE

unread,
Nov 8, 2016, 2:08:43 AM11/8/16
to Kivy users support
We can;t run that. Does it have a utf-8 header? Where/how is the font set? The example need to be complete and runnable.

Titus Cheng

unread,
Nov 8, 2016, 2:48:17 AM11/8/16
to Kivy users support
# -*- coding: utf-8 -*-

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.treeview import TreeView
from kivy.uix.treeview import TreeViewLabel
from kivy.uix.treeview import TreeViewNode

import os
import codecs


class SourceInput(TextInput):
    multiline=True

# class Main(Widget):
#     layout = BoxLayout(padding=10, orientation='horizontal')
#     sourceInput = SourceInput()
#     layout.add_widget(sourceInput)

class FileTree:
    files = []
    def __init__(self):
        print("File Tree Instance created")
        for file in os.listdir("./"):
            if file.endswith(".lodc"):
                FileTree.files.append(file)
                print("filename: " + file)

    def getFiles(self):
        return FileTree.files

    def openFile(self, fname):
        file = codecs.open(fname, encoding='utf-8')
        file_str = file.read()
        file.close()
        return file_str

class PPTNode(Button, TreeViewNode):
    pass


class MainApp(App):
    fs = FileTree()
    sourceInput = SourceInput()

    def test(self, obj):
        MainApp.sourceInput.text = MainApp.fs.openFile(obj.text)



    def build(self):
        mainLayout = BoxLayout(orientation="vertical")

        contentLayout = BoxLayout(orientation="horizontal")

        tv = TreeView(size_hint=(0.3, 1.0))

        for file in MainApp.fs.getFiles():
            tLabel = PPTNode(text=file)
            tLabel.bind(on_press=self.test)
            tv.add_node(tLabel, parent=None)
        contentLayout.add_widget(tv)
        contentLayout.add_widget(MainApp.sourceInput)

        toolbar = BoxLayout(size_hint=(1.0, 0.08))
        createButton = Button(text="Convert", size=(200,100), size_hint=(None, None))
        highlightButton = Button(text="Highlight", size=(200,100), size_hint=(None, None))
        toolbar.add_widget(createButton)
        toolbar.add_widget(highlightButton)

        mainLayout.add_widget(toolbar)
        mainLayout.add_widget(contentLayout)
        return mainLayout


if __name__ == '__main__':
    MainApp().run()

  Here is the complete code, I do have the utf-8 header.  What do you meant by font set?  It is necessary for the foreign language to be display properly?  Thanks for your help!


On Monday, November 7, 2016 at 9:35:41 PM UTC-8, Titus Cheng wrote:

ZenCODE

unread,
Nov 8, 2016, 5:19:13 AM11/8/16
to Kivy users support
Yes, the font needs to be able to display Korean characters. You need to find a font that supportd these characters and then use that font in Kivy. That's almost certainly the issue here?

Titus Cheng

unread,
Nov 8, 2016, 2:26:08 PM11/8/16
to Kivy users support
Thank ZenCODE!  Yes, I didn't realize it was needed until you mentioned it, I got used to other system where it automatically supports and didn't realize that this one didn't.  It is fixed now that I have added the fonts, thanks very much!

But I have another issue that once I type in Korean character, it doesn't automatically displays the individual letters right away, but rather it waits until I press space that the letters I typed is shown.  Do you happen to know this issue also?

ZenCODE

unread,
Nov 8, 2016, 4:53:23 PM11/8/16
to Kivy users support
Glad you got it working :-)

As for the display issue, afraid not. Which version of kivy are you using? All I can suggest is experimenting and seeing whether it's a device/OS/setting specific issue.
Reply all
Reply to author
Forward
0 new messages