Skip to content

Instantly share code, notes, and snippets.

@cocuh
Created February 11, 2014 10:00
Show Gist options
  • Save cocuh/8932122 to your computer and use it in GitHub Desktop.
Save cocuh/8932122 to your computer and use it in GitHub Desktop.
for minecraft japanese input on linux. linuxのまいんくらふとでもにほんごにゅうりょくしたい!
import sys
import subprocess as sp
if sys.version_info.major == 2:
import Tkinter as tk
stringfy = lambda string: string
else:
import tkinter as tk
stringfy = lambda string: string.encode(encoding='utf-8')
class Gui(tk.Frame):
DEFAULT_FONT = ('Ricty','20')
def __init__(self, master):
tk.Frame.__init__(self,master)
self.pack()
self.create_widgets()
self.init_binds()
def create_widgets(self):
self.elem_text=tk.Text(self, font=self.DEFAULT_FONT)
self.elem_text.pack({'side':'top','fill':tk.BOTH})
self.elem_text.focus_set()
def init_binds(self):
self.master.bind('<Escape>',self.action_destroy)
self.master.bind('<Control-Return>',self.action_finish)
def action_destroy(self,*args):
self.master.destroy()
def action_finish(self,*args):
text = self.elem_text.get('1.0',tk.END)
write_clipboard(text)
self.action_destroy()
def write_clipboard(string,selection='clipboard'):
p = sp.Popen(['xclip','-selection',selection],stdin=sp.PIPE)
p.communicate(stringfy(string))
p.wait()
def main():
w = tk.Tk()
gui = Gui(w)
gui.mainloop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment