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.
# -*- coding: utf-8 -*-
from kivy.app import Appfrom kivy.uix.widget import Widgetfrom kivy.uix.boxlayout import BoxLayoutfrom kivy.uix.anchorlayout import AnchorLayoutfrom kivy.uix.textinput import TextInputfrom kivy.uix.button import Buttonfrom kivy.uix.treeview import TreeViewfrom kivy.uix.treeview import TreeViewLabelfrom kivy.uix.treeview import TreeViewNode
import osimport 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()