Пример #1
0
 def __init__(self, title="Dresscode App", width=800, height=500,
              theme=Cyberpunk(), caching=False,
              resizable=(False, True), on_exit=None):
     """
     Parameters
     ==========
     - title: string, the title of the app
     - width: int, the width of the app
     - height: int, the height of the app
     - scrolling: the orient of the scrollbar, "vertical", "horizontal", "both".
     - theme: the theme, i.e. an instance of tkstyle.Theme
     - on_exit: the on_exit handler, ie a function that will be called on exit.
     """
     self._title = title
     self._width = width
     self._height = height
     self._theme = theme
     self._caching = caching
     self._resizable = resizable
     self._on_exit = on_exit
     self._pages = {}
     self._page = None
     self._todo_open_cache = []
     self._todo_menu_cache = []
     self._menubar = None
     self._view = None
     self._menu_map = {}
     self._pids = []
     self._pids_count = 0
     self._pyrustic_app = PyrusticApp()
     self._root = self._pyrustic_app.root
     self._opening = False
     self._started = False
     self._setup()
Пример #2
0
def main():
    # The App
    app = App(__package__)
    # Set theme
    app.theme = Cyberpunk()
    # Set view
    app.view = MainView(app)
    # Center the window
    app.center()
    # Lift off !
    app.start()
Пример #3
0
 def __init__(self, title=None, width=900, height=550,
              home=None, scrollbar="vertical",
              theme=Cyberpunk(), on_exit=None):
     self._title = title
     self._width = width
     self._height = height
     self._home = home
     self._scrollbar = scrollbar
     self._theme = theme
     self._on_exit = on_exit
     self._pages = {}
     self._opened_page = None
     self._menubar = None
     self._main_view = None
     self._menu_map = {}
     self._pids = []
     self._pids_count = 0
     self._pyrustic_app = PyrusticApp(None)
     self._root = self._pyrustic_app.root
     self._setup()
Пример #4
0
class App:
    def __init__(self, title=None, width=900, height=550,
                 home=None, scrollbar="vertical",
                 theme=Cyberpunk(), on_exit=None):
        self._title = title
        self._width = width
        self._height = height
        self._home = home
        self._scrollbar = scrollbar
        self._theme = theme
        self._on_exit = on_exit
        self._pages = {}
        self._opened_page = None
        self._menubar = None
        self._main_view = None
        self._menu_map = {}
        self._pids = []
        self._pids_count = 0
        self._pyrustic_app = PyrusticApp(None)
        self._root = self._pyrustic_app.root
        self._setup()

    @property
    def opened_page(self):
        return self._opened_page

    @property
    def pyrustic_app(self):
        return self._pyrustic_app

    @property
    def main_view(self):
        return self._main_view

    @property
    def root(self):
        return self._root

    def add_page(self, page, category=None):
        pid = page.pid
        if not pid:
            pid = self._gen_pid()
            page.pid = pid
        if pid in self._pages:
            message = "Duplicate page id isn't allowed ({})".format(pid)
            raise DresscodeException(message)
        self._pages[pid] = page
        self._pids.append(pid)
        self._main_view.populate_menubar(pid, page, category)
        page.app = self

    def open_page(self, pid):
        if pid not in self._pages:
            message = "You cannot open a page that you haven't added yet"
            raise DresscodeException(message)
        if self._opened_page:
            self._opened_page.destroy_page_view()
        page = self._pages[pid]
        self._opened_page = page
        scrollbox = self._main_view.body
        scrollbox.clear()
        page.install_page_view(scrollbox.box)

    def open_home(self):
        if self._home:
            self.open_page(self._home)

    def start(self):
        self._pyrustic_app.start()

    def _setup(self):
        # set theme
        if self._theme:
            self._pyrustic_app.theme = self._theme
        # set title
        if self._title:
            self._title = "{} | built with Pyrustic".format(self._title)
            self._pyrustic_app.root.title(self._title)
        # set width and height
        if self._width and self._height:
            cache = "{}x{}+0+0".format(self._width, self._height)
            self._pyrustic_app.root.geometry(cache)
        # center the app
        self._pyrustic_app.center()
        # set exit handler
        if self._on_exit:
            self._pyrustic_app.exit_handler = self._on_exit
        # set the main view
        self._main_view = _MainView(self, self._scrollbar)
        self._pyrustic_app.view = self._main_view

    def _gen_pid(self):
        self._pids_count += 1
        return "pid_{}".format(self._pids_count)
Пример #5
0
from pyrustic.app import App
import about
import sys
import os.path
from tool.runtest.misc.builder import MainViewBuilder
from tool.runtest.theme import RUNTEST_THEME

app = App()
app.root.title("Pyrustic Test Runner")
app.theme = RUNTEST_THEME
app.config = os.path.join(about.ROOT_DIR, "tool", "runtest", "config.ini")
app.view = MainViewBuilder().build(app.root)
app.start()
Пример #6
0
class App:
    """This is the entry point of your Dresscode app"""
    def __init__(self, title="Dresscode App", width=800, height=500,
                 theme=Cyberpunk(), caching=False,
                 resizable=(False, True), on_exit=None):
        """
        Parameters
        ==========
        - title: string, the title of the app
        - width: int, the width of the app
        - height: int, the height of the app
        - scrolling: the orient of the scrollbar, "vertical", "horizontal", "both".
        - theme: the theme, i.e. an instance of tkstyle.Theme
        - on_exit: the on_exit handler, ie a function that will be called on exit.
        """
        self._title = title
        self._width = width
        self._height = height
        self._theme = theme
        self._caching = caching
        self._resizable = resizable
        self._on_exit = on_exit
        self._pages = {}
        self._page = None
        self._todo_open_cache = []
        self._todo_menu_cache = []
        self._menubar = None
        self._view = None
        self._menu_map = {}
        self._pids = []
        self._pids_count = 0
        self._pyrustic_app = PyrusticApp()
        self._root = self._pyrustic_app.root
        self._opening = False
        self._started = False
        self._setup()

    @property
    def title(self):
        """Return the title of the app"""
        return self._title

    @title.setter
    def title(self, val):
        """Set the title of the app"""
        if self._started and self._title:
            raise error.AlreadyDefinedError
        self._title = val

    @property
    def width(self):
        """Return the width of the app"""
        return self._width

    @width.setter
    def width(self, val):
        """Set the width of the app"""
        if self._started and self._width:
            raise error.AlreadyDefinedError
        self._width = val

    @property
    def height(self):
        """Return the height of the app"""
        return self._height

    @height.setter
    def height(self, val):
        """Set the height of the app"""
        if self._started and self._height:
            raise error.AlreadyDefinedError
        self._height = val

    @property
    def theme(self):
        """Return the current theme"""
        return self._theme

    @theme.setter
    def theme(self, val):
        """Set a theme, ie, a themebase.Theme instance"""
        if self._started and self._theme:
            raise error.AlreadyDefinedError
        self._theme = val

    @property
    def caching(self):
        """Return a boolean to indicate if the caching option is True or False.
        By default, caching is set to False."""
        return self._caching

    @caching.setter
    def caching(self, val):
        """Set True if you want pages to be cached. Cached pages retains their data.
        By default, caching is set to False."""
        if self._started and self._caching:
            raise error.AlreadyDefinedError
        self._caching = val

    @property
    def resizable(self):
        """Return the resizable tuple state"""
        return self._pyrustic_app.resizable

    @resizable.setter
    def resizable(self, val):
        if self._started:
            raise error.AlreadyDefinedError
        self._pyrustic_app.resizable = val

    @property
    def on_exit(self):
        """Return the on_exit handler"""
        return self._on_exit

    @on_exit.setter
    def on_exit(self, val):
        """Set the on_exit handler. The handler is a function that accepts no argument"""
        if self._started and self._on_exit:
            raise error.AlreadyDefinedError
        self._on_exit = val

    @property
    def page(self):
        """Return the currently opened page"""
        return self._page

    @property
    def pages(self):
        """Return an internal dictionary that contains pages. Keys are pages ids"""
        return self._pages.copy()

    @property
    def pyrustic_app(self):
        """Under the hood, Dresscode uses Pyrustic Framework.
        This property returns the instance of pyrustic.app.App"""
        return self._pyrustic_app

    @property
    def root(self):
        """Return the root Tk object"""
        return self._root

    @property
    def view(self):
        """Under the hood, Dresscode uses Pyrustic Framework.
        This property returns the main view."""
        return self._view

    def add(self, page, indexable=True, category=None):
        """ Add a page to the app.
        Parameters
        ==========
            - page: an instance of dresscode.page.Page
            - indexable: boolean, if False, the page won't be indexed in the menubar
            - category: string, the menu category name under
             which the page is indexed

        Returns the pid

        Raises dresscode.error.DuplicatePageError if the pid already exists
        """
        if not page.app:
            page.app = self
        if not page.pid:
            page.pid = self.new_pid()
        pid = page.pid
        if pid in self._pages:
            raise error.DuplicatePageError
        self._pages[pid] = page
        self._pids.append(pid)
        if indexable:
            if self._view.body:
                self._view.populate_menubar(pid, page, category)
            else:
                data = (pid, page, category)
                self._todo_menu_cache.append(data)
        return pid

    def new_pid(self):
        self._pids_count += 1
        return "pid-{}".format(self._pids_count)

    def open(self, pid):
        """ Open a page specified by its pid
        Raise dresscode.error.PageNotFoundError if not page is associated to this PID
        Raise dresscode.error.NestedOpeningError if you try to open a new page inside
        on_open and on_close callbacks
        """
        if self._opening:
            msg = "Don't open a new page inside on_open and on_close callbacks"
            raise error.NestedOpeningError(msg)
        if not self._view.body:
            self._todo_open_cache.append(pid)
            return
        if pid not in self._pages:
            raise error.PageNotFoundError
        self._opening = True
        if self._page:
            self._page.close()
        self._page = self._pages[pid]
        self._page.open()
        self._opening = False

    def start(self):
        """ Start the app. Mainloop here."""
        self._started = True
        self._pyrustic_app.start()

    def exit(self):
        """Exit the app"""
        self._pyrustic_app.exit()

    def _setup(self):
        # set theme
        if self._theme:
            self._pyrustic_app.theme = self._theme
        # set title
        self._pyrustic_app.title = self._title
        # set width and height
        if self._width and self._height:
            cache = "{}x{}+0+0".format(self._width, self._height)
            self._root.geometry(cache)
        # set resizable
        self.resizable = self._resizable
        # center the app
        self._pyrustic_app.center()
        # set the main view
        self._view = View(self, self._todo, self._on_exit)
        self._pyrustic_app.view = self._view

    def _todo(self):
        for pid, page, category in self._todo_menu_cache:
            self._view.populate_menubar(pid, page, category)
        for pid in self._todo_open_cache:
            self.open(pid)
        self._todo_menu_cache = []
        self._todo_open_cache = []
Пример #7
0
from pyrustic.app import App
import about
import os.path
from tool.sqluna.misc.builder import MainViewBuilder
from tool.sqluna.theme import SQLUNA_THEME

app = App()
app.root.title("Pyrustic Database Editor")
app.theme = SQLUNA_THEME
app.config = os.path.join(about.ROOT_DIR, "tool", "sqluna", "config.ini")
app.view = MainViewBuilder().build(app)
app.start()
Пример #8
0
# 'main.py' generated by Pyrustic Manager
import about
from pyrustic.app import App
import os.path

app = App()
# Set window title
window_title = "{} | Built with Pyrustic".format(about.PROJECT_NAME)
app.root.title(window_title)
# Set config
config_file = os.path.join(about.ROOT_DIR, "config.ini")
app.config = config_file if os.path.exists(config_file) else None
# Set theme
app.theme = None  # feel free to use pyrustic.themes.darkmatter.DARKMATTER_THEME
# Set view
app.view = None  # please assign a View's instance to this property
# Lift off !
app.start()