示例#1
0
 def __init__(self, path):
     # type: (str) -> None
     path = os.path.abspath(path)
     if (len(path) >= 260 and System.is_windows()
             and not path.startswith(WINDOWS_PATH_PREFIX)):
         path = WINDOWS_PATH_PREFIX + path
     self.__path = path
示例#2
0
def main():
    from multiprocessing import freeze_support

    freeze_support()
    # Initialize.
    app = QApplication.instance() or QApplication(sys.argv)
    sys.excepthook = generate_except_hook(app)
    threading.excepthook = generate_thread_except_hook(app)
    # Set geometry.
    screen_rect = app.desktop().screen().rect()
    screen_center = screen_rect.center()
    width = (7 * screen_rect.width()) // 10
    height = (2 * screen_rect.height()) // 3
    x = screen_center.x() - width // 2
    y = screen_center.y() - height // 2
    print(f"Window: size {width} x {height}, position ({x}; {y})",
          file=sys.stderr)
    view = PysaurusQtApplication(geometry=(x, y, width, height))
    # Set zoom.
    if System.is_windows():
        # view.setZoomFactor(1.8)
        screen_height = screen_rect.height()
        base_height = 1080
        if screen_height > base_height:
            scale = (screen_height / base_height) * 0.9
            print("Scale", scale)
            view.setZoomFactor(scale)
    # Display.
    view.show()
    sys.exit(app.exec_())
示例#3
0
    def locate_file(self):
        if System.is_windows():
            command = f'explorer /select,"{self.__path}"'
        elif System.is_mac():
            # TODO not tested
            command = ["open", "-R", self.__path]
        elif System.is_linux():
            # TODO not tested
            command = ["nautilus", self.__path]
        else:
            raise core_exceptions.UnsupportedSystemError(System.platform())
        process = subprocess.Popen(command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        stdout, stderr = process.communicate()
        if stdout or stderr:
            return OSError(f"""Unable to locate file: {self.__path}
STDOUT: {stdout.strip()}
STDERR: {stderr.strip()}""")
        return self.get_directory()
示例#4
0
    def open(self):
        """Open path with default OS program."""
        if System.is_linux():
            subprocess.run(["xdg-open", self.__path])
        elif System.is_mac():
            subprocess.run(["open", self.__path])
        elif System.is_windows():
            if self.__path.startswith(WINDOWS_PATH_PREFIX):
                from pysaurus.core.native.windows import get_short_path_name

                path = get_short_path_name(self.standard_path)
                print("AbsolutePath: opening Windows short path",
                      path,
                      file=sys.stderr)
            else:
                path = self.__path
            FileSystem.startfile(path)
        else:
            raise core_exceptions.UnsupportedSystemError(System.platform())
        return self
示例#5
0
 def set_view(self, app: QApplication):
     # Set geometry.
     screen_rect = app.desktop().screen().rect()
     # Set zoom.
     if System.is_windows():
         # view.setZoomFactor(1.8)
         screen_height = screen_rect.height()
         base_height = 1080
         if screen_height > base_height:
             scale = (screen_height / base_height) * 0.9
             print("[Qt/window] scale", scale)
             self.setZoomFactor(scale)
示例#6
0
 def set_view(self, app: QApplication):
     # Set geometry.
     screen_rect = app.desktop().screen().rect()
     screen_center = screen_rect.center()
     width = (7 * screen_rect.width()) // 10
     height = (2 * screen_rect.height()) // 3
     x = screen_center.x() - width // 2
     y = screen_center.y() - height // 2
     print(
         f"[Qt/window] size {width} x {height}, position ({x}; {y})", file=sys.stderr
     )
     self.setGeometry(x, y, width, height)
     # Set zoom.
     if System.is_windows():
         # view.setZoomFactor(1.8)
         screen_height = screen_rect.height()
         base_height = 1080
         if screen_height > base_height:
             scale = (screen_height / base_height) * 0.9
             print("[Qt/window] scale", scale)
             self.setZoomFactor(scale)
示例#7
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.sys_is_case_insensitive = System.is_case_insensitive(
         self.folder.path)
示例#8
0
    def best_path(self):
        if System.is_windows():
            from pysaurus.core.native.windows import get_short_path_name

            return get_short_path_name(self.standard_path)
        return self.__path
示例#9
0
 def __init__(self, expected, given):
     self.platform = System.platform()
     self.expected = expected
     self.given = given
示例#10
0
if __name__ == "__main__":
    import sys
    from pysaurus.core.modules import System
    from pysaurus.core.functions import fatal

    CEF = "cef"
    QT = "qt"
    GUIS = (CEF, QT)

    class UnknownGUI(Exception):
        def __init__(self, expected, given):
            self.platform = System.platform()
            self.expected = expected
            self.given = given

    if len(sys.argv) == 2:
        gui = sys.argv[1].strip().lower()
        if System.is_windows():
            if gui not in GUIS:
                fatal(UnknownGUI(GUIS, gui))
        elif gui != QT:
            fatal(UnknownGUI(QT, gui))
    else:
        gui = CEF if System.is_windows() else QT
    if gui == CEF:
        from pysaurus.interface.cefgui.run import main
    else:  # assert gui == QT
        from pysaurus.interface.qtwebview.run import main
    main()