Skip to content

Commit

Permalink
Dev flet gui (#53)
Browse files Browse the repository at this point in the history
* minimal test

* experimentation with flet

* minor

* MVC example

* MVC example

* WIP: UI components

* removed requirement fints to make pyinstaller work

* rename app main file

* demo content

* displaying demo objects

* WIP: desktop app layout

* WIP: app layout

* WIP: app layout

* WIP: app layout

* WIP: invoicing page

* prepare for merge
  • Loading branch information
clstaudt authored Sep 11, 2022
1 parent f9883da commit 016cc20
Show file tree
Hide file tree
Showing 30 changed files with 2,671 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"python.formatting.provider": "black"
}
302 changes: 302 additions & 0 deletions app/Tuttle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
from loguru import logger

import flet
from flet import (
Page,
Row,
Column,
Container,
Text,
Card,
NavigationRailDestination,
UserControl,
ElevatedButton,
TextButton,
Icon,
Dropdown,
dropdown,
)
from flet import icons, colors

from layout import DesktopAppLayout

import views
from views import (
ContactView,
ContactView2,
)

from tuttle.controller import Controller
from tuttle.model import (
Contact,
Contract,
Project,
Client,
)

from tuttle_tests import demo


class App:
def __init__(
self,
controller: Controller,
page: Page,
):
self.con = controller
self.page = page


class AppPage(UserControl):
def __init__(
self,
app: App,
):
super().__init__()
self.app = app

def build(self):
self.main_column = Column(
scroll="auto",
)
# self.view = Row([self.main_column])

return self.main_column

def update_content(self):
pass


class DemoPage(AppPage):
def __init__(
self,
app: App,
):
super().__init__(app)

def update(self):
super().update()

def add_demo_data(self, event):
"""Install the demo data on button click."""
demo.add_demo_data(self.app.con)
self.main_column.controls.clear()
self.main_column.controls.append(
Text("Demo data installed ☑️"),
)
self.update()

def build(self):
self.main_column = Column(
[
ElevatedButton(
"Install demo data",
icon=icons.TOYS,
on_click=self.add_demo_data,
),
],
)
return self.main_column


class ContactsPage(AppPage):
def __init__(
self,
app: App,
):
super().__init__(app)

def update(self):
super().update()

def update_content(self):
super().update_content()
self.main_column.controls.clear()

contacts = self.app.con.query(Contact)

for contact in contacts:
self.main_column.controls.append(
views.make_contact_view(contact),
)
self.update()


class ContractsPage(AppPage):
def __init__(
self,
app: App,
):
super().__init__(app)

def update(self):
super().update()

def update_content(self):
super().update_content()
self.main_column.controls.clear()

contracts = self.app.con.query(Contract)

for contract in contracts:
self.main_column.controls.append(
# TODO: replace with view class
views.make_contract_view(contract)
)
self.update()


class ProjectsPage(AppPage):
def __init__(
self,
app: App,
):
super().__init__(app)

def update(self):
super().update()

def update_content(self):
super().update_content()
self.main_column.controls.clear()

projects = self.app.con.query(Project)

for project in projects:
self.main_column.controls.append(
# TODO: replace with view class
views.make_project_view(project)
)
self.update()


class InvoicingPage(AppPage):
def __init__(
self,
app: App,
):
super().__init__(app)

def update(self):
super().update()

def update_content(self):
super().update_content()

self.main_column.controls.clear()

projects = self.app.con.query(Project)

project_select = Dropdown(
label="Project",
hint_text="Select the project",
options=[dropdown.Option(project.title) for project in projects],
autofocus=True,
)

self.main_column.controls.append(
Row(
[
project_select,
]
)
)
self.update()


def main(page: Page):

con = Controller(
in_memory=True,
verbose=False,
)

app = App(
controller=con,
page=page,
)

pages = [
(
NavigationRailDestination(
icon=icons.TOYS_OUTLINED,
selected_icon=icons.TOYS,
label="Demo",
),
DemoPage(app),
),
(
NavigationRailDestination(
icon=icons.SPEED_OUTLINED,
selected_icon=icons.SPEED,
label="Dashboard",
),
AppPage(app),
),
(
NavigationRailDestination(
icon=icons.WORK,
label="Projects",
),
ProjectsPage(app),
),
(
NavigationRailDestination(
icon=icons.DATE_RANGE,
label="Time",
),
AppPage(app),
),
(
NavigationRailDestination(
icon=icons.CONTACT_MAIL,
label="Contacts",
),
ContactsPage(app),
),
(
NavigationRailDestination(
icon=icons.HANDSHAKE,
label="Clients",
),
AppPage(app),
),
(
NavigationRailDestination(
icon=icons.HISTORY_EDU,
label="Contracts",
),
ContractsPage(app),
),
(
NavigationRailDestination(
icon=icons.OUTGOING_MAIL,
label="Invocing",
),
InvoicingPage(app),
),
(
NavigationRailDestination(
icon=icons.SETTINGS,
label_content=Text("Settings"),
),
AppPage(app),
),
]

layout = DesktopAppLayout(
page=page,
pages=pages,
title="Tuttle",
window_size=(1280, 720),
)

page.add(
layout,
)


if __name__ == "__main__":
flet.app(
target=main,
)
Loading

0 comments on commit 016cc20

Please sign in to comment.