示例#1
0
文件: Menu.py 项目: brainysmurf/pydir
    def pdf(self, *args):
        """
        Communicates with app and tries to make current file a pdf file
        at the same location with the same name, but with .pdf extension.
        """
        wanted_app = None
        if len(args) == 1:
            if args[0].isdigit():
                the_file = self.cntrl.get_item(args[0])
                self.command_line("open {0}".format(the_file.quoted_full_path))
                wanted_app = get_name_of_front_application()
            else:
                entered = args[0]
                all_open_apps = get_list_of_every_open_application()
                list_of_possibles = [appli for appli in all_open_apps if appli.lower().startswith(entered.lower())]
                if len(list_of_possibles) > 1:
                    try:
                        wanted_app = choose_from_list("Which app?", list_of_possibles)
                    except User_Canceled:
                        return
                elif len(list_of_possibles) == 0:
                    return ["", "Error, no app by that name"]
                else:
                    wanted_app = list_of_possibles[0]
        else:
            try:
                all_open_apps = get_list_of_every_open_application()
                wanted_app = choose_from_list("Which app?", get_list_of_every_open_application())
            except User_Canceled:
                return

        if wanted_app:
            a = get_app(wanted_app)
            a.save_as_pdf()
示例#2
0
文件: Menu.py 项目: brainysmurf/pydir
    def save(self, *args):
        """
        Provide name of application and will tell it to save.
        Gives you a chance to name it before doing so.
        """
        """
        FIXME: Applescript's save command makes keynote and pages files a directory instead of a file (for some reason)
        I know what the problem is now... have to test to ensure
        """
        wanted_app = args[0] if args else None
        wanted_where = args[1] if len(args) > 1 else None
        if wanted_app:
            all_open_apps = get_list_of_every_open_application()
            list_of_possibles = [appli for appli in all_open_apps if appli.lower().startswith(wanted_app.lower())]
            if len(list_of_possibles) > 1:
                try:
                    wanted_app = choose_from_list("Which app?", list_of_possibles)
                except User_Canceled:
                    return
            elif len(list_of_possibles) == 0:
                return ["", "Error, no app by that name"]
            else:
                wanted_app = list_of_possibles[0]
            if not wanted_where:
                try:
                    wanted_where = get_app(wanted_app).name_of_current_document()
                except:
                    wanted_where = input("Couldn't figure out name to use, enter now: ")

        else:
            try:
                all_open_apps = get_list_of_every_open_application()
                try:
                    wanted_app = choose_from_list("Which app?", get_list_of_every_open_application())
                except User_Canceled:
                    return
            except User_Canceled:
                return
            try:
                wanted_where = get_app(wanted_app).name_of_current_document()
            except:
                wanted_where = input("Couldn't figure out name to use, enter now: ")

        try:
            wanted_where = get_app(wanted_app).display_dialog_convenience("Modify?", default_answer=wanted_where)
        except User_Canceled:
            return

        if wanted_app and wanted_where:
            a = get_app(wanted_app)
            path = os.path.join(self.cntrl.current_directory, wanted_where)
            a.save_as(path)
            ext = a.extension_of_current_document()
            a.close()
            a.open(path + ext)