This code implements a simple appointment booking application using the...
This code implements a simple appointment booking application using the Kivy framework for the user interface and SQLite for data storage. Here's what the code does in detail:
1. Database Setup and Functions
-
init_db()
: Initializes an SQLite database (app.db
) with two tables:users
for storing user information (including an admin account by default) andappointments
for storing appointment details. If the admin user doesn't already exist, it creates one with the usernameadmin
and passwordadmin123
. -
add_user(username, password, is_admin=0)
: Adds a new user to theusers
table. ReturnsTrue
if the user was added successfully; otherwise, it handles the integrity error (e.g., if the username is already taken) and returnsFalse
. -
check_user(username, password)
: Checks if a user with the givenusername
andpassword
exists in the database. Returns the user record if it exists, orNone
otherwise. -
add_appointment(service, date, time, username)
: Adds a new appointment associated with a specificusername
to theappointments
table. -
get_appointments(username=None)
: Retrieves appointments from the database. If ausername
is provided, it filters appointments for that user; otherwise, it retrieves all appointments. -
show_popup(title, message)
: A helper function to show a message to the user using a small popup.
2. User Interface Screens
-
LoginScreen
: Handles user login and registration.- Users can log in or sign up using a username and password.
- After a successful login, users are redirected to either the admin or the home screen based on their user type (
is_admin
).
-
HomeScreen
: The main screen for regular users.- "📅 Zakaži" Tab: Allows logged-in users to book an appointment by providing the service name, date, and time. Appointments are saved to the database.
- "🗂️ Termini" Tab: Displays the logged-in user's appointments in a scrollable list.
- "ℹ️ O nama" Tab: Displays some "about us" information hard-coded into the app.
-
AdminScreen
: The admin view, which displays all appointments across users. It allows the admin to monitor bookings made by all users, but it does not provide any functionality for modifying or canceling the appointments.
3. Application Setup and Navigation
-
Kivy Components: The application uses several Kivy UI components such as
ScreenManager
,BoxLayout
,Label
,Button
,TextInput
,Popup
, andTabbedPanel
to design and transition between different screens in the application. -
ScreenManager:
LoginScreen
: The initial screen where users log in or register.HomeScreen
: Displayed for regular users after a successful login.AdminScreen
: Displayed for admin users after a successful login.
-
Transitions: The screen transitions are animated using a
FadeTransition
effect.
4. Application Workflow
- Initializes the app database (
init_db()
). - Starts the application with the
LoginScreen
. - Users can:
- Log in with valid credentials. Depending on whether the user is an admin (
is_admin=1
), they are redirected to either theAdminScreen
orHomeScreen
. - Register a new account by providing a username and password.
- Log in with valid credentials. Depending on whether the user is an admin (
- Regular users can:
- Book new appointments through the "📅 Zakaži" tab.
- View their own appointments in the "🗂️ Termini" tab.
- Admin users can:
- View all appointments in the
AdminScreen
.
- View all appointments in the
5. Visual Customizations
- The background color of the window is set to black (
(0, 0, 0, 1)
). - The application uses colors like ORANGE (
(1, 0.5, 0, 1)
) and WHITE ((1, 1, 1, 1)
). - Fonts are styled with bold text and larger sizes in key areas (e.g., heading).
Purpose and Functionality:
This application provides a basic system for booking and managing appointments for a studio. It supports:
- User authentication (login and registration).
- Appointment booking and viewing for regular users.
- Admin-level access to view all user appointments.
This kind of app could be used in small businesses, such as studios or service-based companies, to schedule and manage appointments.