Example #1
0
def setup_vlc_files(intf_lua_name):
  """Copies the lua interface script to VLC's per-user data dir."""
  src_intf_file = os.path.join("share", intf_lua_name)
  if (not os.path.isfile(src_intf_file)):
    raise Exception("Could not find VLC lua interface file: %s" % src_intf_file)

  vlc_app_dir = osutils.get_gui_app_user_data_dir({"Darwin":"org.videolan.vlc", "Any":"vlc"})
  vlc_intf_dir = os.path.join(vlc_app_dir, "lua", "intf")
  osutils.ensure_dir_exists(vlc_intf_dir, 0700)
  vlc_intf_file = os.path.join(vlc_intf_dir, intf_lua_name)
  if (not os.path.isfile(vlc_intf_file) or (osutils.get_file_md5(vlc_intf_file) != osutils.get_file_md5(src_intf_file))):
    logging.info("Copying %s to %s." % (src_intf_file, vlc_intf_file))
    shutil.copyfile(src_intf_file, vlc_intf_file)
Example #2
0
def main():
  cleanup_handler = None

  try:
    logging.info("TweetSubs %s (on %s)" % (global_config.VERSION, platform.platform(aliased=True, terse=False)))

    logging.info("Registering ctrl-c handler.")
    cleanup_handler = cleanup.CustomCleanupHandler()
    cleanup_handler.register()  # Must be called from main thread.
    # Warning: If the main thread gets totally blocked, it'll never notice sigint.

    vlc_path = get_vlc_dir()
    setup_vlc_files(global_config.INTF_LUA_NAME)

    tweetsubs_data_dir = osutils.get_gui_app_user_data_dir({"Any":"TweetSubs"})
    osutils.ensure_dir_exists(tweetsubs_data_dir, 0700)

    root = tk.Tk()
    root.withdraw()

    # Tkinter mainloop doesn't normally die and let its exceptions be caught.
    def tk_error_func(exc, val, tb):
      logging.exception("%s" % exc)
      root.destroy()
    root.report_callback_exception = tk_error_func

    mygui = tsgui.GuiApp(master=root)
    mygui.update()  # No mainloop to auto-update yet.
    mygui.center_window()
    cleanup_handler.add_gui(mygui)

    logic_thread = LogicThread(mygui, cleanup_handler, tweetsubs_data_dir, vlc_path)
    logic_thread.start()

    try:
      root.mainloop()
    finally:
      mygui.done = True

  except (Exception) as err:
    logging.exception(err)  #raise

  finally:
    if (cleanup_handler is not None): cleanup_handler.cleanup()