PageRenderTime 94ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/amis31/src/AmisGuiGtk/AmisGuiGtk.py

https://github.com/daisy/amis
Python | 92 lines | 64 code | 24 blank | 4 comment | 4 complexity | 0825a3f08a0284764d6ced2e0b7052b9 MD5 | raw file
  1. #!/usr/bin/env/python
  2. """AMIS gui test
  3. A simple gui for the first linux version of AMIS"""
  4. import gtk
  5. import gobject
  6. import gtkmozembed
  7. import os
  8. import amiscore
  9. class AmisGuiGtk(gtk.Window):
  10. def __init__(self, parent=None):
  11. gtk.Window.__init__(self)
  12. self.moz = gtkmozembed.MozEmbed()
  13. self.dtb = amiscore.Dtb()
  14. try:
  15. self.set_screen(parent.get_screen())
  16. except AttributeError:
  17. self.connect('destroy', lambda *w: gtk.main_quit())
  18. self.set_title("AMIS")
  19. vbox = gtk.VBox(False, 0)
  20. self.add(vbox)
  21. filemenulist = gtk.Menu()
  22. open = gtk.MenuItem("open")
  23. quit = gtk.MenuItem("quit")
  24. filemenulist.append(open)
  25. filemenulist.append(quit)
  26. file = gtk.MenuItem("file")
  27. file.set_submenu(filemenulist)
  28. menubar = gtk.MenuBar()
  29. menubar.append(file)
  30. vbox.pack_start(menubar, expand=False)
  31. hpaned = gtk.HPaned()
  32. model = gtk.TreeStore(gobject.TYPE_PYOBJECT, gobject.TYPE_STRING)
  33. treeitem= { "hello": "hi"}
  34. iter = model.insert_before(None, None)
  35. model.set_value(iter, 0, treeitem)
  36. treeview = gtk.TreeView(model)
  37. hpaned.add1(treeview)
  38. hpaned.add2(self.moz)
  39. vbox.pack_end(hpaned)
  40. self.show_all()
  41. open_book(self, None)
  42. def play_audio(filepath, clipbegin, clipend):
  43. cmd = "mplayer %s >/dev/null 2>&1 1</dev/null"%filepath
  44. os.system(cmd)
  45. def open_book(self, filepath):
  46. self.dtb.open("/media/winxp/dtb/Mountains_skip/ncc.html", "/home/med/bmk")
  47. media = self.dtb.startReading(False)
  48. text_node = media.getText()
  49. audio_node = media.getAudio(0)
  50. text_path = "file://" + getPathFromNode(self, text_node)
  51. audio_path = getPathFromNode(self, audio_node)
  52. showText(self, text_path)
  53. play_audio(audio_path, audio_node.getClipBegin(), None)
  54. def getPathFromNode(self, node):
  55. if not node: return None
  56. src = node.getSrc()
  57. fileset = self.dtb.getFileSet()
  58. smil_file = fileset.getSmilFile()
  59. smil_dir = os.path.dirname(smil_file)
  60. return os.path.join(smil_dir, src)
  61. def showText(self, url):
  62. self.moz.load_url(url)
  63. def main():
  64. AmisGuiGtk()
  65. gtk.main()
  66. if __name__ == '__main__':
  67. main()