Skip to content

Instantly share code, notes, and snippets.

@CoutinhoElias
Created August 1, 2020 13:42
Show Gist options
  • Save CoutinhoElias/8c339da831e8fff80c481d9b81a78e31 to your computer and use it in GitHub Desktop.
Save CoutinhoElias/8c339da831e8fff80c481d9b81a78e31 to your computer and use it in GitHub Desktop.
GistProjeto
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty, ObjectProperty
from kivymd.app import MDApp
from kivymd.theming import ThemableBehavior
from kivymd.uix.list import OneLineIconListItem, MDList
# DataTable
from kivymd.uix.datatables import MDDataTable
from kivy.metrics import dp
# Directoryes
import inspect, os, csv
# Databases
import pyodbc
# Import/Export Excel
import xlrd
# My classes
from actions import Actions
KV = '''
#:import Window kivy.core.window.Window
#:set color_shadow [0, 0, 0, .2980392156862745]
# Campos personalizados
<KitchenSinkTextFieldRound@MDTextFieldRound>
size_hint_x: None
normal_color: 255,0,0,1 #app.theme_cls.accent_color
active_color: app.theme_cls.primary_color
# Menu item in the DrawerList list.
<ItemDrawer>:
theme_text_color: "Custom"
on_release: self.parent.set_color_item(self)
IconLeftWidget:
id: icon
icon: root.icon
theme_text_color: "Custom"
text_color: root.text_color
<ContentNavigationDrawer>:
orientation: "vertical"
padding: "8dp"
spacing: "8dp"
AnchorLayout:
anchor_x: "left"
size_hint_y: None
height: avatar.height
Image:
id: avatar
size_hint: None, None
size: "56dp", "56dp"
source: "data/logo/kivy-icon-256.png"
MDLabel:
text: "KivyMD library"
font_style: "Button"
size_hint_y: None
height: self.texture_size[1]
ScrollView:
DrawerList:
id: md_list
MDLabel:
text: "kivydevelopment@gmail.com"
font_style: "Caption"
size_hint_y: None
height: self.texture_size[1]
NavigationLayout:
# Cada Screen representa uma tela
ScreenManager:
id: scrmngr
Screen:
name: "home"
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Home"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state()]]
Widget:
Screen:
name: "screen1"
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "screen1"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state()]]
Widget:
Screen:
name: "screen2"
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "screen2"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state()]]
Widget:
Screen:
name: "screen3"
# Chamo a função que vai mostrar a DataTable
on_enter: app.open_table(self, True)
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Naturezas de Lançamento"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state()]]
ScrollView:
MDBoxLayout:
orientation: 'vertical'
adaptive_height: True
spacing: -40
MDBoxLayout:
# orientation: 'vertical'
adaptive_height: True
size_hint_y: None
height: self.minimum_height
padding: dp(25)
spacing: 30
MDTextField:
hint_text: "Rectangle mode 1"
mode: "rectangle"
MDTextField:
hint_text: "Rectangle mode 2"
mode: "rectangle"
MDTextField:
hint_text: "Rectangle mode 3"
mode: "rectangle"
MDBoxLayout:
# orientation: 'vertical'
adaptive_height: True
size_hint_y: None
height: self.minimum_height
padding: dp(25)
spacing: 40
KitchenSinkTextFieldRound:
icon_left: 'account-circle'
hint_text: 'Field with left icon'
# size_hint_y: 0.85
size_hint_x: 0.75
KitchenSinkTextFieldRound:
icon_left: 'account-box'
hint_text: 'Field with left icon'
# size_hint_y: 0.85
size_hint_x: 0.85
KitchenSinkTextFieldRound:
icon_left: 'email'
hint_text: 'Field with left icon'
# size_hint_y: 0.85
size_hint_x: 0.85
MDBoxLayout:
# orientation: 'vertical'
adaptive_height: True
size_hint_y: None
height: self.minimum_height
padding: dp(25)
spacing: 30
MDTextField:
hint_text: "Rectangle mode 100"
mode: "rectangle"
MDTextField:
hint_text: "Rectangle mode 200"
mode: "rectangle"
MDTextField:
hint_text: "Rectangle mode 300"
mode: "rectangle"
Screen:
name: "screen4"
# Chamo a função que vai mostrar a DataTable
on_enter: app.open_table(self, True)
BoxLayout:
orientation: 'vertical'
MDToolbar:
title: "Naturezas de Lançamento"
elevation: 10
left_action_items: [['menu', lambda x: nav_drawer.set_state()]]
ScrollView:
# Campos texto-------------------------------------------------------------------------------
MDBoxLayout:
orientation: 'vertical'
adaptive_height: True
spacing: -30 # Aproxima os campos de cima para baixo
MDBoxLayout:
size_hint_y: None
height: self.minimum_height
padding: dp(25) # Aproxima ou distancia o widget dos lados
MDTextField:
hint_text: "Nome da Natureza de Lançamento"
mode: "rectangle"
MDBoxLayout:
size_hint_y: None
height: self.minimum_height
padding: dp(25)
MDTextField:
hint_text: "Classificação Ex.: 9.99.99.99.99.999"
mode: "rectangle"
# CheckBoxes-------------------------------------------------------------------------------
MDBoxLayout:
orientation: 'vertical'
adaptive_height: True
spacing: dp(-20) # Aproxima os campos de cima para baixo
MDBoxLayout:
orientation: 'horizontal'
adaptive_height: True
MDCheckbox:
size_hint: None, None
size: dp(48), dp(48)
MDLabel:
size:self.texture_size
font_style: 'Subtitle1'
text: "Texto do md linha 1"
halign: 'left'
MDBoxLayout:
orientation: 'horizontal'
adaptive_height: True
MDCheckbox:
size_hint: None, None
size: dp(48), dp(48)
MDLabel:
size:self.texture_size
font_style: 'Subtitle1'
text: "Texto do md linha 2"
halign: 'left'
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
id: content_drawer
'''
# Source https://github.com/bAcheron/basic_etl/blob/master/DatabaseManager.py
class ContentNavigationDrawer(BoxLayout):
None
class ItemDrawer(OneLineIconListItem):
icon = StringProperty()
# Ao clicar chama a função drawer_action
# na classe TestNavigationDrawer
def on_release(self, *args):
MDApp.get_running_app().drawer_action(self)
class DrawerList(ThemableBehavior, MDList):
def set_color_item(self, instance_item):
"""Called when tap on a menu item."""
# Seta a cor do ícone e texto no menu item
# Set the color of the icon and text for the menu item.
for item in self.children:
if item.text_color == self.theme_cls.primary_color:
item.text_color = self.theme_cls.text_color
break
instance_item.text_color = self.theme_cls.primary_color
class TestNavigationDrawer(MDApp):
navdrawer = ObjectProperty(None)
#actions = Actions()
def build(self):
self.root = Builder.load_string(KV)
self.navdrawer = self.root.ids.nav_drawer
self.scrmngr = self.root.ids.scrmngr
return self.root
# Adicionamos cada ítem do Drawer nesta função
# Nome_do_icone:Descrição_que_quer_aparecer
def on_start(self):
icons_item = {
"home": "Go to home",
"share-variant": "Go to screen 1",
"view-list": "Go to screen 2",
"history": "Go to screen 3",
"all-inclusive": "Normaliza Natureza"
}
for icon_name in icons_item.keys():
self.root.ids.content_drawer.ids.md_list.add_widget(
ItemDrawer(icon=icon_name, text=icons_item[icon_name]))
# Chama os screens queforam criados em KV
def drawer_action(self, item: ItemDrawer):
if item.icon == "home":
self.scrmngr.current = "home"
if item.icon == "share-variant":
self.scrmngr.current = "screen1"
if item.icon == "view-list":
self.scrmngr.current = "screen2"
if item.icon == "history":
self.scrmngr.current = "screen3"
if item.icon == "all-inclusive":
# Actions.update_table()
# Actions.insert_table()
self.scrmngr.current = "screen4"
self.navdrawer.set_state()
def open_table(self, use_checkbox_state, use_pagination_state):
cd = Actions.list_table()
rd = []
for i in cd:
rd.append((str(i[1]), str(i[2]), str(i[7]), str(i[8])))
data_tables = MDDataTable(
pos_hint={'center_x': 0.5, 'center_y': 0.35},
# auto_dismiss=False,
size_hint=(0.9, 0.5),
use_pagination=use_pagination_state,
check=use_checkbox_state,
rows_num=10,
column_data=[
("Cod", dp(30)),
("Descrição", dp(80)),
("Classificaçao", dp(50)),
("A/S", dp(30)),
],
row_data=rd,
)
data_tables.open()
TestNavigationDrawer().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment