Ejemplo n.º 1
0
Archivo: app.py Proyecto: 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
Ejemplo n.º 2
0
Archivo: app.py Proyecto: 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
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
Archivo: window.py Proyecto: 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
Ejemplo n.º 5
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
Ejemplo n.º 6
0
    def __init__(self,
                 name,
                 app_id,
                 id=None,
                 icon=None,
                 startup=None,
                 document_types=None,
                 factory=None):

        self.factory = get_platform_factory(factory)

        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, factory=self.factory)
        self.icon = icon

        self._impl = self.factory.App(interface=self)
Ejemplo n.º 7
0
    def __init__(self,
                 name,
                 app_id,
                 icon=None,
                 id=None,
                 startup=None,
                 document_types=None,
                 factory=None):
        '''
        Instantiate a new application
        
        :param name: The name of the application
        :type  name: ``str``
        
        :param app_id: The unique application identifier,
            the reversed domain name, e.g. 'org.pybee.me'
        :type  app_id: ``str``
        
        :param icon: Icon for the application
        :type  icon: ``str``
        
        :param id: The DOM identifier for the app (optional)
        :type  id: ``str``
        
        :param startup: The callback method before starting the app, typically
            to add the components
        :type  startup: ``callable`` that expects a single argument of :class:`toga.App`
        
        :param document_types: Document types
        :type  document_types: ``list`` of ``str``
        '''

        App.app = self

        # if self._MAIN_WINDOW_CLASS is None:
        #     raise NotImplementedError('App class must define _MAIN_WINDOW_CLASS')

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

        self.icon = icon

        self.document_types = document_types
        self._documents = []

        self._startup_method = startup

        if factory is None:
            self.factory = get_platform_factory()
        else:
            self.factory = factory
        self._impl = self.factory.App(creator=self)

        # Call user code to populate the main window
        self.startup()
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
Archivo: base.py Proyecto: 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)
Ejemplo n.º 10
0
    def __init__(self, id=None, style=None, **config):
        self._id = id if id else identifier(self)
        self._parent = None
        self._children = None
        self._window = None
        self._app = None
        self._impl = None
        self.__container = None
        self._layout_in_progress = False

        self._config = config

        self.layout = Layout(self)
        if style:
            self.style = style.copy()
        else:
            self.style = CSS()
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
    def __init__(self, name, app_id, icon=None,
                 id=None, startup=None, document_types=None):
        '''
        Instantiate a new application

        :param name: The name of the application
        :type  name: ``str``

        :param app_id: The unique application identifier,
            the reversed domain name, e.g. 'org.pybee.me'
        :type  app_id: ``str``

        :param icon: Icon for the application
        :type  icon: ``str``

        :param id: The DOM identifier for the app (optional)
        :type  id: ``str``

        :param startup: The callback method before starting the app, typically
            to add the components
        :type  startup: ``callable`` that expects a single argument of :class:`toga.App`

        :param document_types: Document types
        :type  document_types: ``list`` of ``str``
        '''
        App.app = self

        if self._MAIN_WINDOW_CLASS is None:
            raise NotImplementedError('App class must define _MAIN_WINDOW_CLASS')

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

        self.icon = icon

        self._commands = CommandSet(None, self._create_menus)

        self.document_types = document_types
        self._documents = []

        self._startup_method = startup
Ejemplo n.º 13
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
Ejemplo n.º 14
0
Archivo: base.py Proyecto: pybee/toga
 def __repr__(self):
     return "<%s:0x%x>" % (self.__class__.__name__, identifier(self))
Ejemplo n.º 15
0
 def __repr__(self):
     return "<%s:0x%x>" % (self.__class__.__name__, identifier(self))
Ejemplo n.º 16
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
Ejemplo n.º 17
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