#[Copyright 2023 ITwrx.
This file is part of EZ-Bkup.
EZ-Bkup is released under the General Public License 3.0.
See COPYING or for details.]#
import owlkettle
import "models/routine", "shared"
import views/[edit_routine_dialog, routine_list, app_menu_button]
const APP_NAME = "EZ-Bkup"
let databasePath = appPath & "/ez-bkup.sqlite"
viewable App:
## The main application
routineModel: RoutineModel ## The RoutineModel that stores all routines.
method view(app: AppState): Widget {.locks: "unknown".} =
result = gui:
Window:
title = APP_NAME
defaultSize = (1024, 768)
HeaderBar {.addTitlebar.}:
Icon {.addLeft.}:
name = "EZ-Bkup-icon"
pixelSize = 40
margin = 4
# Button to open the main menu
AppMenuButton {.addRight.}:
routineModel = app.routineModel
Box:
orient = OrientY
spacing = 6
#don't use available vertical space from parent. Only what's needed for children.
Box(orient = OrientX) {.expand: false.}:
Label:
text = "Bkup Routines"
xAlign = 0.05
useMarkup = true
#expand horizontally to push buttons to the right.
Box(orient = OrientX) {.expand: true.}
#expanding box containing buttons would fight the previous box for available horiz space placing buttons in the middle.
Box(orient = OrientX, spacing = 6, margin = 6) {.expand: false.}:
# Button to create a new routine
Button:
style = [ButtonSuggested]
text = "+ Routine"
proc clicked() =
## Opens the EditRoutineDialog for creating a new routine
let (res, state) = app.open: gui:
EditRoutineDialog(mode = EditRoutineCreate)
if res.kind == DialogAccept:
# The "Create" button was clicked
app.routineModel.add(EditRoutineDialogState(state).routine)
# Main content of the window: Contains the list of all routines.
Box:
orient = OrientY
margin = 6
spacing = 12
Frame:
RoutineList:
routineModel = app.routineModel
when isMainModule:
# Entry point for the application.
# Loads the model from the database and starts the application.
let model = newRoutineModel(databasePath)
brew("org.itwrx.EZ-Bkup", gui(App(routineModel = model)), icons=["icons/"], stylesheets=[loadStylesheet("styles.css")])