Skip to content

Commit

Permalink
Merge pull request #61 from ChicoState/navigation_drawer
Browse files Browse the repository at this point in the history
Added navigation bar and drawer to most Screens, closes issue #43
  • Loading branch information
VicaWorth authored Oct 14, 2024
2 parents fd67ce3 + 05cbbec commit c36df02
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 15 deletions.
20 changes: 18 additions & 2 deletions src/help_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from kivy.uix.button import Button
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.uix.gridlayout import GridLayout
from kivymd.uix.toolbar import MDTopAppBar
from kivy.core.window import Window
from kivy.graphics import Color, Rectangle

Expand All @@ -13,8 +14,17 @@
class HelpCenterScreen(Screen):
def __init__(self, **kwargs):
super(HelpCenterScreen, self).__init__(**kwargs)
from homePage import NavDrawer

layout = BoxLayout(orientation='vertical', padding=10, spacing=20)

nav_drawer = NavDrawer(self)
# nav_bar handles nav_drawer
nav_bar = MDTopAppBar(title="StitchNiche Help Center",md_bg_color=(0.5, 0, 0.5, 1))
# opens nav_drawer on click
nav_bar.left_action_items = [["menu", lambda x: nav_drawer.set_state("toggle")]]
layout.add_widget(nav_bar)

# Adjusting banner size
banner = BoxLayout(size_hint=(1, 0.15))
with banner.canvas.before:
Expand Down Expand Up @@ -44,7 +54,13 @@ def __init__(self, **kwargs):
layout.add_widget(scroll_view)

self.add_widget(layout)

self.add_widget(nav_drawer)
def calc_screen(self, *args):
self.manager.current='stitch_calc'
def help_screen(self, *args):
self.manager.current='help'
def home_screen(self, *args):
self.manager.current='home'
def load_pattern(self, filename):
# Switch to the pattern screen and load content from the selected file
self.manager.current = 'pattern'
Expand Down Expand Up @@ -114,7 +130,7 @@ class StitchNicheApp(App):
def build(self):
sm = ScreenManager()
sm.add_widget(HelpCenterScreen(name='help'))
sm.add_widget(PatternScreen(name='pattern'))
sm.add_widget(PatternScreen(name='pattern'))
return sm

if __name__ == '__main__':
Expand Down
61 changes: 53 additions & 8 deletions src/homePage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,79 @@
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen
from help_page import HelpCenterScreen
from kivymd.uix.toolbar import MDTopAppBar
from kivymd.uix.navigationdrawer import MDNavigationDrawer
from kivymd.app import MDApp
from kivymd.uix.list import OneLineIconListItem, IconLeftWidget
from help_page import HelpCenterScreen, PatternScreen
from stitchniche_gui import Stitch_Calc

# Set the background color to white
Window.clearcolor = (1, 1, 1, 1) # RGBA

def MakeList(title,icon_name,press_action):
list = OneLineIconListItem(text=title)
list.add_widget(IconLeftWidget(icon=icon_name))
list.on_press = press_action
return list

def NavDrawer(s):
# create nav_drawer
nav_drawer= MDNavigationDrawer(size_hint_x=.3,md_bg_color=(0.5, 0, 0.5, 1))
nav_layout = BoxLayout(orientation='vertical')

# start of items in nav_drawer
list = MakeList("Home", "home",s.home_screen)
nav_layout.add_widget(list)

list = MakeList("Help", "help-box",s.help_screen)
nav_layout.add_widget(list)

list = MakeList("Calculator", "calculator",s.calc_screen)
nav_layout.add_widget(list)
# end of items in nav_drawer

# without this the list starts from bottom
nav_layout.add_widget(Label())
nav_drawer.add_widget(nav_layout)
return nav_drawer

class Home(Screen):
def __init__(self,**kwargs):
super(Home, self).__init__(**kwargs)
# parent
layout = BoxLayout(orientation='vertical')

# creates NavDrawer and fills it Screens
nav_drawer = NavDrawer(self)
# nav_bar handles nav_drawer
nav_bar = MDTopAppBar(title="Home",md_bg_color=(0.5, 0, 0.5, 1))
# opens nav_drawer on click
nav_bar.left_action_items = [["menu", lambda x: nav_drawer.set_state("toggle")]]
layout.add_widget(nav_bar)

welcome_message = Label(text="Welcome to StitchNiche!",font_size='50sp',color=(0.5, 0, 0.5, 1))
layout.add_widget(welcome_message)
button_title = Label(text="I want help with ...", size_hint=(1,.1), font_size='25sp',color=(0.5, 0, 0.5, 1))
layout.add_widget(button_title)

# child: makes row for buttons
container = BoxLayout(orientation='horizontal', spacing='100sp', padding='100sp')
container.add_widget(Button(text='Crocheting',font_size='25sp', background_color=(0.5, 0, 0.5, 1),on_press=self.switch_screen))
container.add_widget(Button(text='Knitting',font_size='25sp',background_color=(0.5, 0, 0.5, 1),on_press=self.switch_screen))
container.add_widget(Button(text='Crocheting',font_size='25sp', background_color=(0.5, 0, 0.5, 1),on_press=self.calc_screen))
container.add_widget(Button(text='Knitting',font_size='25sp',background_color=(0.5, 0, 0.5, 1),on_press=self.calc_screen))

layout.add_widget(container)
layout.add_widget(Label())

self.add_widget(layout)

def switch_screen(self, *args):
self.manager.current = 'stitch_calc'
self.add_widget(nav_drawer)

def calc_screen(self, *args):
self.manager.current='stitch_calc'
def help_screen(self, *args):
self.manager.current='help'
def home_screen(self, *args):
self.manager.current='home'

""" in order to create a new Screen you need to (in a new .py file):
1. include
Expand All @@ -55,9 +100,9 @@ def __init__(self, **kwargs):
self.add_widget(Home(name='home'))
self.add_widget(Stitch_Calc(name='stitch_calc'))
self.add_widget(HelpCenterScreen(name='help'))
self.add_widget(PatternScreen(name='pattern'))


class StitchNicheApp(App):
class StitchNicheApp(MDApp):
def build(self):
return Screens()

Expand Down
40 changes: 35 additions & 5 deletions src/stitchniche_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,37 @@
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
from kivy.uix.screenmanager import Screen
from kivymd.uix.navigationdrawer import MDNavigationDrawer
from kivymd.uix.toolbar import MDTopAppBar
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.uix.navigationdrawer import MDNavigationDrawer
from kivymd.app import MDApp

# Import the StitchCalculator class
from utils import StitchCalculator
from help_page import HelpCenterScreen

# Set the background color to white
Window.clearcolor = (1, 1, 1, 1) # RGBA

class Stitch_Calc(Screen):
def __init__(self, **kwargs):
super(Stitch_Calc,self).__init__(**kwargs)
from homePage import NavDrawer # placing imports here avoid circular dependencies
self.sc = StitchCalculator()
# Main layout for the form
layout = BoxLayout(orientation='vertical',spacing=30, size_hint=(1, 1))

nav_drawer = NavDrawer(self)
# nav_bar handles nav_drawer
nav_bar = MDTopAppBar(title="Rectangle Calculator",md_bg_color=(0.5, 0, 0.5, 1))
# opens nav_drawer on click
nav_bar.left_action_items = [["menu", lambda x: nav_drawer.set_state("toggle")]]
layout.add_widget(nav_bar)

# Title
#GenerateFormKivy.form({"input 1" : 0.0, "input 2" : "inches",}, styles = )
title_label = Label(text="Stitch Niche", font_size='32sp', color=(0.5, 0, 0.5, 1))
title_label = Label(text="Rectangle Calculator", font_size='32sp', color=(0.5, 0, 0.5, 1))
layout.add_widget(title_label)

# Sub Title
Expand Down Expand Up @@ -86,6 +99,7 @@ def __init__(self, **kwargs):
layout.add_widget(submit_button)

self.add_widget(layout)
self.add_widget(nav_drawer)

def submit(self, instance):
# Capture all inputs into a dictionary
Expand Down Expand Up @@ -118,10 +132,26 @@ def submit(self, instance):


self.result_label.text = str(result);

class StitchNicheApp(App):

def calc_screen(self, *args):
self.manager.current='stitch_calc'
def help_screen(self, *args):
self.manager.current='help'
def home_screen(self, *args):
self.manager.current = 'home'

class Screens(ScreenManager):
def __init__(self, **kwargs):
super(Screens, self).__init__(**kwargs)
# first Screen added is set as the current Screen
self.add_widget(Home(name='home'))
self.add_widget(Stitch_Calc(name='stitch_calc'))
self.add_widget(HelpCenterScreen(name='help'))
self.add_widget(PatternScreen(name='pattern'))
class StitchNicheApp(MDApp):
def build(self):
return Stitch_Calc()
# return Stitch_Calc()
return Screens()


if __name__ == "__main__":
Expand Down

0 comments on commit c36df02

Please sign in to comment.