Example #1
0
    def __init__(self,
                 name,
                 app_id,
                 id=None,
                 icon=None,
                 startup=None,
                 document_types=None,
                 factory=None):

        self.factory = get_platform_factory(factory)

        # Keep an accessible copy of the app instance
        App.app = self
        App.app_module = self.__module__.split('.')[0]
        App.app_dir = os.path.dirname(sys.modules[App.app_module].__file__)

        self.name = name
        self._app_id = app_id
        self._id = id if id else identifier(self)

        self.commands = CommandSet(None)

        self.document_types = document_types
        self._documents = []

        self._startup_method = startup

        self.default_icon = Icon('tiberius', system=True)
        self.icon = icon

        self._impl = self.factory.App(interface=self)
Example #2
0
    def __init__(self,
                 id=None,
                 title=None,
                 position=(100, 100),
                 size=(640, 480),
                 toolbar=None,
                 resizeable=True,
                 closeable=True,
                 minimizable=True,
                 factory=None):

        self._id = id if id else identifier(self)
        self._impl = None
        self._app = None
        self._content = None
        self._position = position
        self._size = size
        self._is_full_screen = False

        self.resizeable = resizeable
        self.closeable = closeable
        self.minimizable = minimizable

        self.factory = get_platform_factory(factory)
        self._impl = getattr(self.factory, self._WINDOW_CLASS)(interface=self)

        self._toolbar = CommandSet(self, self._impl.create_toolbar)

        self.position = position
        self.size = size
        self.title = title
Example #3
0
File: app.py Project: djay/toga
    def __init__(self,
                 name,
                 app_id,
                 id=None,
                 icon=None,
                 startup=None,
                 on_exit=None,
                 factory=None):
        self.factory = get_platform_factory(factory)

        # Keep an accessible copy of the app instance
        App.app = self
        App.app_module = self.__module__.split('.')[0]
        App.app_dir = os.path.dirname(sys.modules[App.app_module].__file__)

        self.name = name
        self._app_id = app_id
        self._id = id if id else identifier(self)

        self.commands = CommandSet(factory=self.factory)

        self._startup_method = startup

        self.default_icon = Icon('tiberius', system=True)
        self.icon = icon
        self._main_window = None
        self._on_exit = None

        self._full_screen_windows = None

        self._impl = self._create_impl()
        self.on_exit = on_exit
Example #4
0
    def __init__(self,
                 action,
                 label,
                 shortcut=None,
                 tooltip=None,
                 icon=None,
                 group=None,
                 section=None,
                 order=None,
                 factory=None):
        self.action = wrapped_handler(self, action)
        self.label = label

        self.shortcut = shortcut
        self.tooltip = tooltip
        self.icon_id = icon

        self.group = group if group else Group.COMMANDS
        self.section = section if section else 0
        self.order = order if order else 0

        self._enabled = self.action is not None

        self._widgets = []

        self.factory = get_platform_factory()
        self._impl = self.factory.Command(interface=self)
Example #5
0
File: app.py Project: pybee/toga
    def __init__(self, name, app_id,
                 id=None, icon=None, startup=None, on_exit=None, factory=None):
        self.factory = get_platform_factory(factory)

        # Keep an accessible copy of the app instance
        App.app = self
        App.app_module = self.__module__.split('.')[0]
        App.app_dir = os.path.dirname(sys.modules[App.app_module].__file__)

        self.name = name
        self._app_id = app_id
        self._id = id if id else identifier(self)

        self.commands = CommandSet(None)

        self._startup_method = startup

        self.default_icon = Icon('tiberius', system=True)
        self.icon = icon
        self._main_window = None
        self._on_exit = None

        self._full_screen_windows = None

        self._impl = self._create_impl()
        self.on_exit = on_exit
Example #6
0
File: window.py Project: pybee/toga
    def __init__(self, id=None, title=None,
                 position=(100, 100), size=(640, 480),
                 toolbar=None, resizeable=True,
                 closeable=True, minimizable=True, factory=None):

        self._id = id if id else identifier(self)
        self._impl = None
        self._app = None
        self._content = None
        self._position = position
        self._size = size
        self._is_full_screen = False

        self.resizeable = resizeable
        self.closeable = closeable
        self.minimizable = minimizable

        self.factory = get_platform_factory(factory)
        self._impl = getattr(self.factory, self._WINDOW_CLASS)(interface=self)

        self._toolbar = CommandSet(self, self._impl.create_toolbar)

        self.position = position
        self.size = size
        self.title = title
Example #7
0
    def __init__(self, id=None, enabled=True, style=None, factory=None):
        super().__init__(style=style if style else Pack(),
                         applicator=TogaApplicator(self))

        self._id = id if id else identifier(self)
        self._window = None
        self._app = None
        self._impl = None

        self._enabled = enabled

        self.factory = get_platform_factory(factory)
Example #8
0
    def __init__(self, family, size, factory=None):
        """ A :obj:`Font` is a font family (e.g. "Helvetica") and a size (e.g. 15) that can
        be applied to widgets.

        Args:
            family (str): Name of the font family.
            size (int): Defines the display size of the font.
        """
        self._family = family
        self._size = size

        self.factory = get_platform_factory(factory)
        self._impl = self.factory.Font(interface=self)
Example #9
0
File: base.py Project: pybee/toga
    def __init__(self, id=None, enabled=True, style=None, factory=None):
        super().__init__(
            style=style if style else Pack(),
            applicator=TogaApplicator(self)
        )

        self._id = id if id else identifier(self)
        self._window = None
        self._app = None
        self._impl = None

        self._enabled = enabled

        self.factory = get_platform_factory(factory)
Example #10
0
    def __init__(self, id=None, style=None, factory=None):
        self._id = id if id else identifier(self)
        self._parent = None
        self._children = None
        self._window = None
        self._app = None
        self._impl = None
        self._layout_in_progress = False

        self.layout = Layout(self)
        if style:
            self.style = style.copy()
        else:
            self.style = CSS()

        self._font = None

        self.factory = get_platform_factory(factory)
Example #11
0
    def __init__(self,
                 id=None,
                 title=None,
                 position=(100, 100),
                 size=(640, 480),
                 toolbar=None,
                 resizeable=True,
                 closeable=True,
                 minimizable=True,
                 factory=None,
                 on_close=None):

        self._id = id if id else identifier(self)
        self._impl = None
        self._app = None
        self._content = None
        self._is_full_screen = False

        self.resizeable = resizeable
        self.closeable = closeable
        self.minimizable = minimizable

        self.factory = get_platform_factory(factory)
        self._impl = getattr(self.factory, self._WINDOW_CLASS)(
            interface=self,
            title='Toga' if title is None else title,
            position=position,
            size=size,
        )

        self._toolbar = CommandSet(factory=self.factory,
                                   widget=self,
                                   on_change=self._impl.create_toolbar)

        self._on_close = None
        if on_close is not None:
            self.on_close = on_close
Example #12
0
 def bind(self, factory):
     factory = get_platform_factory(factory)
     self.__impl = factory.Font(self)
     return self.__impl
Example #13
0
    def __init__(
        self,
        formal_name=None,
        app_id=None,
        app_name=None,
        id=None,
        icon=None,
        author=None,
        version=None,
        home_page=None,
        description=None,
        startup=None,
        on_exit=None,
        factory=None,
    ):
        # Keep an accessible copy of the app instance
        App.app = self

        # We need a module name to load app metadata. If an app_name has been
        # provided, we can set the app name now, and derive the module name
        # from there.
        if app_name:
            self._app_name = app_name
        else:
            # If the code is contained in appname.py, and you start the app
            # using `python -m appname`, the main module package will report
            # as ''. Set the initial app name as None.
            # If the code is contained in appname.py, and you start the app
            # using `python appname.py`, the main module will report as None.
            # If the code is contained in a folder, and you start the app
            # using `python -m appname`, the main module will report as the
            # name of the folder.
            main_module_pkg = sys.modules['__main__'].__package__
            if main_module_pkg == '':
                self._app_name = None
            else:
                self._app_name = main_module_pkg

            # During tests, and when running from a prompt, there won't be
            # a __main__ module.

            # Try deconstructing the app name from the app ID
            if self._app_name is None and app_id:
                self._app_name = app_id.split('.')[-1]

        # Load the app metdata (if it is available)
        # Apps packaged with Briefcase will have this metadata.
        try:
            self.metadata = importlib_metadata.metadata(self.module_name)
        except importlib_metadata.PackageNotFoundError:
            self.metadata = Message()

        # Now that we have metadata, we can fix the app name (in the case
        # where the app name and the module name differ - e.g., an app name
        # of ``hello-world`` will have a module name of ``hello_world``).
        # We use the PEP566-compliant key ``Name```, rather than the internally
        # consistent key ``App-Name```.
        if self.metadata['Name'] is not None:
            self._app_name = self.metadata['Name']

        # Whatever app name has been given, speculatively attempt to import
        # the app module. Single-file apps won't have an app folder; apps with
        # misleading or misconfigured app names haven't given us enough
        # metadata to determine the app folder. In those cases, fall back to
        # an app name that *will* exist (``toga```)
        try:
            sys.modules[self.module_name]
        except KeyError:
            # Well that didn't work...
            self._app_name = 'toga'

        # If a name has been provided, use it; otherwise, look to
        # the module metadata. However, a name *must* be provided.
        if formal_name:
            self._formal_name = formal_name
        else:
            self._formal_name = self.metadata['Formal-Name']

        if self._formal_name is None:
            raise RuntimeError('Toga application must have a formal name')

        # If an app_id has been provided, use it; otherwise, look to
        # the module metadata. However, an app_id *must* be provied
        if app_id:
            self._app_id = app_id
        else:
            self._app_id = self.metadata.get('App-ID', None)

        if self._app_id is None:
            raise RuntimeError('Toga application must have an App ID')

        # If an author has been provided, use it; otherwise, look to
        # the module metadata.
        if author:
            self._author = author
        else:
            self._author = self.metadata.get('Author', None)

        # If a version has been provided, use it; otherwise, look to
        # the module metadata.
        if version:
            self._version = version
        else:
            self._version = self.metadata.get('Version', None)

        # If a home_page has been provided, use it; otherwise, look to
        # the module metadata.
        if home_page:
            self._home_page = home_page
        else:
            self._home_page = self.metadata.get('Home-page', None)

        # If a description has been provided, use it; otherwise, look to
        # the module metadata.
        if description:
            self._description = description
        else:
            self._description = self.metadata.get('Summary', None)

        # Set the application DOM ID; create an ID if one hasn't been provided.
        self._id = id if id else identifier(self)

        # Get a platform factory, and a paths instance from the factory.
        self.factory = get_platform_factory(factory)
        self.paths = self.factory.paths

        # If an icon (or icon name) has been explicitly provided, use it;
        # otherwise, the icon will be based on the app name.
        if icon:
            self.icon = icon
        else:
            self.icon = 'resources/{app_name}'.format(app_name=self.app_name)

        self.commands = CommandSet(factory=self.factory)

        self._startup_method = startup

        self._main_window = None
        self._on_exit = None

        self._full_screen_windows = None

        self._impl = self._create_impl()
        self.on_exit = on_exit
Example #14
0
 def __init__(self, path, factory=None):
     self.factory = factory if factory else get_platform_factory()
     self._impl = self.factory.Image(interface=self)
     self.path = path
Example #15
0
    def __init__(
        self,
        formal_name=None,
        app_id=None,
        app_name=None,
        id=None,
        icon=None,
        author=None,
        version=None,
        home_page=None,
        description=None,
        startup=None,
        on_exit=None,
        factory=None,
    ):
        # Keep an accessible copy of the app instance
        App.app = self

        # We need a module name to load app metadata. If an app_name has been
        # provided, we can set the app name now, and derive the module name
        # from there.
        if app_name:
            self._app_name = app_name
        else:
            self._app_name = sys.modules['__main__'].__package__
            # During tests, and when running from a prompt, there won't be
            # a __main__ module. Fall back to a module that we know *does*
            # exist.
            if self._app_name is None:
                self._app_name = 'toga'

        # Load the app metdata (if it is available)
        # Apps packaged with Briefcase will have this metadata.
        try:
            self.metadata = importlib_metadata.metadata(self.module_name)
        except importlib_metadata.PackageNotFoundError:
            self.metadata = Message()

        # Now that we have metadata, we can fix the app name (in the case
        # where the app name and the module name differ - e.g., an app name
        # of `hello-world` will have a module name of `hello_world`).
        # We use the PEP566 key "Name", rather than "App-Name".
        if app_name is None and self.metadata['Name'] is not None:
            self._app_name = self.metadata['Name']

        # If a name has been provided, use it; otherwise, look to
        # the module metadata. However, a name *must* be provided.
        if formal_name:
            self._formal_name = formal_name
        else:
            self._formal_name = self.metadata['Formal-Name']

        if self._formal_name is None:
            raise RuntimeError('Toga application must have a formal name')

        # If an app_id has been provided, use it; otherwise, look to
        # the module metadata. However, an app_id *must* be provied
        if app_id:
            self._app_id = app_id
        else:
            self._app_id = self.metadata['App-ID']

        if self._app_id is None:
            raise RuntimeError('Toga application must have an App ID')

        # If an author has been provided, use it; otherwise, look to
        # the module metadata.
        if author:
            self._author = author
        elif self.metadata['Author']:
            self._author = self.metadata['Author']

        # If a version has been provided, use it; otherwise, look to
        # the module metadata.
        if version:
            self._version = version
        elif self.metadata['Version']:
            self._version = self.metadata['Version']

        # If a home_page has been provided, use it; otherwise, look to
        # the module metadata.
        if home_page:
            self._home_page = home_page
        elif self.metadata['Home-page']:
            self._home_page = self.metadata['home_page']

        # If a description has been provided, use it; otherwise, look to
        # the module metadata.
        if description:
            self._description = description
        elif self.metadata['description']:
            self._description = self.metadata['Summary']

        # Set the application DOM ID; create an ID if one hasn't been provided.
        self._id = id if id else identifier(self)

        # Get a platform factory, and a paths instance from the factory.
        self.factory = get_platform_factory(factory)
        self.paths = self.factory.paths

        # If an icon (or icon name) has been explicitly provided, use it;
        # otherwise, the icon will be based on the app name.
        if icon:
            self.icon = icon
        else:
            self.icon = 'resources/{app_name}'.format(app_name=self.app_name)

        self.commands = CommandSet(factory=self.factory)

        self._startup_method = startup

        self._main_window = None
        self._on_exit = None

        self._full_screen_windows = None

        self._impl = self._create_impl()
        self.on_exit = on_exit