1 #!/usr/bin/env python
\r
7 import tkinter.filedialog
\r
10 import opengl.rokuro
\r
16 class Frame(tkinter.Frame):
\r
17 def __init__(self, width, height, master=None, **kw):
\r
18 super(Frame, self).__init__(master, **kw)
\r
19 self.master.title('pymeshio viewer')
\r
22 menu_bar = tkinter.Menu(self)
\r
23 self.master.config(menu=menu_bar)
\r
25 menu_file = tkinter.Menu(menu_bar, tearoff=False)
\r
26 menu_bar.add_cascade(label='File', menu=menu_file, underline=0)
\r
28 menu_file.add_command(label='Open', under=0, command=self.onOpen)
\r
30 # setup opengl widget
\r
31 self.view=opengl.rokuro.RokuroView()
\r
32 self.glworld=opengl.BaseController(self.view)
\r
33 self.glwidget=togl.Widget(self, self.glworld, width=width, height=height)
\r
34 self.glwidget.pack(fill=tkinter.BOTH, expand=True)
\r
37 self.bind('<Key>', self.onKeyDown)
\r
38 self.bind('<MouseWheel>', lambda e: self.glworld.onWheel(-e.delta) and self.glwidget.onDraw())
\r
41 path=tkinter.filedialog.askopenfilename(
\r
43 ('poloygon model files', '*.mqo;*.pmd;*.pmx'),
\r
45 initialdir=self.current)
\r
46 self.current=os.path.dirname(path)
\r
49 def load(self, path):
\r
50 model=self.loadModel(path)
\r
52 print('fail to load %s' % path)
\r
54 print('load %s' % path)
\r
56 self.glworld.setRoot(model)
\r
57 bb=model.get_boundingbox()
\r
59 self.view.look_bb(*bb)
\r
60 self.glwidget.onDraw()
\r
62 def loadModel(self, path):
\r
63 if path.lower().endswith(".mqo"):
\r
64 return mqobuilder.build(path)
\r
65 elif path.lower().endswith(".pmd"):
\r
66 return pmdbuilder.build(path)
\r
67 elif path.lower().endswith(".pmx"):
\r
68 return pmxbuilder.build(path)
\r
70 print("unknown file format: {0}".format(path))
\r
72 def onKeyDown(self, event):
\r
81 print("keycode: %d" % key)
\r
84 if __name__ == '__main__':
\r
85 f = Frame(width=600, height=600)
\r
86 f.pack(fill=tkinter.BOTH, expand=True)
\r