Пример #1
0
 def print(self):
     """ @method
     ファイル・フォルダを印刷する。
     """
     if self.isdir():
         raise ValueError("Unsupported")
     shellpath().start_file(self._path, "print")
Пример #2
0
 def start(self, operation=None):
     """ @method [open]
     ファイル・フォルダをデフォルトの方法で開く。
     Params:
         operation(str): *動作のカテゴリ。[open|print|edit|explore|find|...]
     """
     shellpath().start_file(self._path, operation)
Пример #3
0
    def open_by_text_editor(self, filepath, line=None, column=None):
        """ テキストエディタで開く。
        Params:
            filepath(str): ファイルパス
            line(int): 行番号
            column(int): 文字カラム番号
        """
        if self._has_external_app("text-editor"):
            editor = None
            lineopt = None
            charopt = None

            editor = self._external_apps.get_option("text-editor", "path")
            if line is not None and self._external_apps.has_option(
                    "text-editor", "line"):
                lineopt = self._external_apps.get_option(
                    "text-editor", "line").format(line)
            if column is not None and self._external_apps.has_option(
                    "text-editor", "column"):
                charopt = self._external_apps.get_option(
                    "text-editor", "column").format(column)

            args = []
            args.append(editor)
            args.append(filepath)
            if lineopt is not None:
                args.append(lineopt)
            if charopt is not None:
                args.append(charopt)
            subprocess.Popen(args, shell=False)

        else:
            from machaon.types.shellplatform import shellpath
            shellpath().open_by_system_text_editor(filepath, line, column)
Пример #4
0
    def initialize(self, *, ui, basic_dir=None, **uiargs):
        if isinstance(ui, str):
            if ui == "tk":
                from machaon.ui.tk import tkLauncher
                ui = tkLauncher(**uiargs)
            else:
                raise ValueError("不明なUIタイプです")

        self.ui = ui

        if basic_dir is None:
            basic_dir = os.path.join(
                shellpath().get_known_path("documents", approot=self),
                "machaon")
        self.basicdir = basic_dir

        package_dir = self.get_package_dir()
        self.pkgmanager = PackageManager(
            package_dir, os.path.join(self.basicdir, "packages.ini"))
        self.pkgmanager.add_to_import_path()
        self.pkgs = []

        self.typemodule = TypeModule()
        self.typemodule.add_fundamental_types()

        self.processhive = ProcessHive()

        if hasattr(self.ui, "init_with_app"):
            self.ui.init_with_app(self)

        chamber = self.processhive.addnew(self.ui.get_input_prompt())
        self.ui.activate_new_chamber(chamber)

        self.ui.init_startup_message()
Пример #5
0
 def known_names(self, spirit):
     """ @method spirit
     場所の名前のリスト。
     Returns:
         Sheet[ObjectCollection]: (name, path)
     """
     res = []
     for k, v in shellpath().known_paths(spirit.get_root()):
         if v is not None:
             res.append({"name": k, "path": Path(v)})
     return res
Пример #6
0
 def ishidden(self):
     """ @method
     隠しファイルかどうか
     ファイル名がピリオドで始まるか、隠し属性がついているか
     Returns:
         Bool:
     """
     if self.name().startswith("."):
         return True
     if shellpath().has_hidden_attribute(self._path):
         return True
     return False
Пример #7
0
 def constructor(self, context, value):
     """ @meta """
     if isinstance(value, str):
         head, tail = os.path.split(value)
         if not head:  # no slash in path
             # 場所の識別名として解釈
             if tail == "machaon":
                 p = context.spirit.get_root().get_basic_dir()
             else:
                 name, _, param = value.partition(":")
                 p = shellpath().get_known_path(name, param,
                                                context.spirit.get_root())
             if p is not None:
                 return Path(p)
         # 識別名が存在しなければパスとする
         return Path(value)
     else:
         return Path(str(value))
Пример #8
0
 def explore(self):
     """ @method
     ファイル・フォルダをエクスプローラで開く。
     """
     p = self.dir()
     shellpath().start_file(p._path, "explore")