Good Evening all Members, Please help me,I want to ask about my syntax kivymd. I want to MDTextField Employee autofill with code employee from QRCode after scanning barcode finish.
Here's my code: Here Main.py
from kivy.lang import Builder
from kivymd.uix.button.button import MDRectangleFlatIconButton
from kivymd.uix.boxlayout import MDBoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.camera import Camera
from kivymd.uix.dialog import MDDialog
from pyzbar.pyzbar import ZBarSymbol
from kivy_garden.zbarcam import ZBarCam
from kivymd.uix.snackbar import Snackbar
from kivymd.app import MDApp
from kivymd.uix.button import MDFlatButton
from kivy.metrics import dp
from kivy.uix.screenmanager import ScreenManager, Screen,FadeTransition,SwapTransition
from kivymd.uix.screenmanager import MDScreenManager
from kivymd.uix.transition.transition import MDFadeSlideTransition,MDTransitionBase
from kivymd.uix.screen import MDScreen
from kivy.properties import (DictProperty,ListProperty,NumericProperty,ObjectProperty,OptionProperty,StringProperty,)
from kivy.core.window import Window
Builder.load_file("main_screen.kv")
Builder.load_file("molding_screen.kv")
# Builder.load_file("kvs/page/punching_screen.kv")
# Builder.load_file("kvs/page/oy_screen.kv")
Window.size=(360,640)
class CameraPopup(MDBoxLayout):
def build(self):
"""Initializes the Application and returns the root widget"""
# pass
class WindowManager(MDScreenManager):
"""A window manager to manage switching between sceens."""
class MainScreen(MDScreen):
"""A screen that display the form scanning Molding Process."""
def build(self):
"""Initializes the Application and returns the root widget"""
self.theme_cls.theme_style = "Light"
class MoldingScreen(MDScreen):
"""A screen that display the form scanning Molding Process."""
judul="MOLDING PROCESS"
def build(self):
"""Initializes the Application and returns the root widget"""
self.theme_cls.theme_style = "Light"
def show_camera_popup(self):
isi = CameraPopup()
self.dialog = MDDialog(
title="QRCODE SCAN",
auto_dismiss=False,
text="Isi dari camera scan.",
type="custom",
content_cls=isi,
buttons=[
MDRectangleFlatIconButton(
text="CLOSE CAMERA",
theme_text_color="Custom",
text_color="white",
size_hint_x=1,
theme_bg_color="Custom",
md_bg_color="blue",
# md_bg_color=0,0,0,1
font_size=22,
padding=10,
on_release=self.close_scanner
),
],
)
self.dialog.open()
# self.ids.text_id_employee.text = self.isiqr
# self.close_scanner()
def close_scanner(self,obj):
self.dialog.dismiss()
# pass
class MainApp(MDApp):
def build(self):
"""Initializes the Application and returns the root widget"""
self.theme_cls.theme_style = "Light"
self.title = "SCANNING PROCESS"
self.wm = WindowManager(transition=MDFadeSlideTransition())
screens = [
MainScreen(name="main"),
MoldingScreen(name="molding"),
]
for screen in screens:
self.wm.add_widget(screen)
return self.wm
def change_screen(self, screen):
"""Change screen using the window manager."""
self.wm.current = screen
def on_symbols(self,instance,symbols):
if not symbols == "":
for symbol in symbols:
self.lblqrcode = symbol.data.decode()
print("QRCode is :",symbol.data.decode())
Snackbar(
text="Your QR Is {}".format(symbol.data.decode()),
md_bg_color="green",
font_size=20
).open()
# self.isiqr = self.lblqrcode
# self.ids.id_hasil.text = self.lblqrcode
def capture_image(self):
pass
def show_result(self):
pass
if __name__ == "__main__":
MainApp().run()
Here main_screen.kv
<MainScreen>:
MDTopAppBar:
title: "PROCESS MAIN MENU"
# elevation: 4
elevation_normal_color: (0, 0, 0, 0) # Set elevation normal color to transparent
elevation_pressed_color: (0, 0, 0, 0) # Set elevation pressed color to transparent
pos_hint: {"top": 1}
theme_bg_color:"Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
left_action_items: [["menu", lambda x:x]]
GridLayout:
id: grid_layout
cols: 3
adaptive_height: True
spacing: dp(8)
padding: dp(0),dp(45),dp(0),dp(0)
MDRectangleFlatIconButton:
text: "MOLDING"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color:211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.35
padding: dp(12)
on_press: app.change_screen('molding')
MDRectangleFlatIconButton:
text: "OVEN"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color: 211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.35
padding: dp(12)
MDRectangleFlatIconButton:
text: "PUNCHING"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color: 211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.35
padding: dp(12)
MDRectangleFlatIconButton:
text: "PREPUSH"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color:211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.3
padding: dp(12)
MDRectangleFlatIconButton:
text: "PATAGUN"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color: 211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.3
padding: dp(12)
MDRectangleFlatIconButton:
text: "CLEANING"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color: 211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.3
padding: dp(12)
MDRectangleFlatIconButton:
text: "OY"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color:211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.3
padding: dp(12)
MDRectangleFlatIconButton:
text: "FINISHING"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color: 211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.3
padding: dp(12)
MDRectangleFlatIconButton:
text: "MIP"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color: 211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.3
padding: dp(12)
MDRectangleFlatIconButton:
text: "RESISTANCE"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color:211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.3
padding: dp(12)
MDRectangleFlatIconButton:
text: "INSPECTION"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color: 211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.3
padding: dp(12)
MDRectangleFlatIconButton:
text: "GI INSPECTION"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color: 211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.3
padding: dp(12)
MDRectangleFlatIconButton:
text: "PACKING"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color: 211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.3
padding: dp(12)
MDRectangleFlatIconButton:
text: "STORE IN"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color: 211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.3
padding: dp(12)
MDRectangleFlatIconButton:
text: "STORE OUT"
size_hint_y:None
height:dp(100)
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(12)
line_color: 211/255, 215/255, 250/255, 0.8
theme_icon_color: "Custom"
size_hint_x:0.3
padding: dp(12)
MDBottomAppBar:
elevation_normal_color: (0, 0, 0, 0) # Set elevation normal color to transparent
elevation_pressed_color: (0, 0, 0, 0) # Set elevation pressed color to transparent
theme_bg_color:"Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
MDTopAppBar:
icon: "home"
font_size: dp(10)
icon_color:35/255, 122/255, 255/255, 0.89
type: "bottom"
left_action_items: [["clipboard-search-outline", lambda x: x]]
right_action_items: [["account", lambda x:x]]
elevation_normal_color: (0, 0, 0, 0) # Set elevation normal color to transparent
elevation_pressed_color: (0, 0, 0, 0) # Set elevation pressed color to transparent
Here Molding_screen.kv
#:import ZBarCam kivy_garden.zbarcam.ZBarCam
#:import ZBarSymbol pyzbar.pyzbar.ZBarSymbol
<CameraPopup@MDBoxLayout>:
orientation: "vertical"
size_hint_y:None
height:dp(500)
line_color:35/255, 122/255, 255/255, 0.89
line_width:1
ZBarCam:
id:zbarcam
size_hint_y:1
pos_hint_y:1
# line_color:0,1,0,1
# line_width:5
code_types:ZBarSymbol.QRCODE.value,ZBarSymbol.EAN13.value,ZBarSymbol.CODE128.value,ZBarSymbol.CODE39.value,ZBarSymbol.CODE93.value,ZBarSymbol.EAN8.value,ZBarSymbol.EAN5.value,ZBarSymbol.EAN2.value,ZBarSymbol.EAN13.value,ZBarSymbol.I25.value,ZBarSymbol.UPCA.value,ZBarSymbol.UPCE.value,ZBarSymbol.CODABAR.value
on_symbols:app.on_symbols(*args)
<MoldingScreen>:
BoxLayout:
orientation: 'vertical'
MDTopAppBar:
title: root.judul
elevation_normal_color: (0, 0, 0, 0) # Set elevation normal color to transparent
elevation_pressed_color: (0, 0, 0, 0) # Set elevation pressed color to transparent
# pos_hint: {"top": 1}
theme_bg_color:"Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
# spacing: dp(2)
MDGridLayout:
cols: 2
padding: "10dp"
spacing: "10dp"
MDTextField:
id: id_employee
hint_text: "EMPLOYEE"
helper_text: "Scan ID Employee"
helper_text_mode: "on_focus"
input_filter: "str"
multiline: False
MDIconButton:
icon: "qrcode-scan"
icon_size: "38sp"
opacity: 0.5
on_release:root.show_camera_popup()
MDTextField:
id: text_field
hint_text: "MACHINE"
helper_text: "Scan ID Employee"
helper_text_mode: "on_focus"
input_filter: "str"
multiline: False
MDIconButton:
icon: "qrcode-scan"
icon_size: "38sp"
opacity: 0.5
# on_release:app.show_camera_popup()
MDTextField:
id: text_field
hint_text: "JOBNUMBER"
helper_text: "Scan ID Employee"
helper_text_mode: "on_focus"
input_filter: "str"
multiline: False
MDIconButton:
icon: "qrcode-scan"
icon_size: "38sp"
opacity: 0.5
# on_release:app.show_camera_popup()
MDTextField:
id: text_field
hint_text: "QTY"
helper_text: "Add Quantity Product"
helper_text_mode: "on_focus"
input_filter: "str"
multiline: False
MDIconButton:
icon: "calculator-variant"
icon_size: "38sp"
opacity: 0.5
# on_release:app.show_camera_popup()
MDBoxLayout:
orientation: 'vertical'
adaptive_height: True
spacing: dp(2)
# padding: dp(0),dp(20),dp(0),dp(0)
MDRectangleFlatIconButton:
text: "SUBMIT"
size_hint_y:None
theme_bg_color: "Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
theme_text_color: "Custom"
text_color: "white"
font_size: dp(18)
line_color:211/255, 215/255, 250/255, 0.8
size_hint_x:0.5
padding: dp(15)
post_hint_x:0.5
MDBoxLayout:
orientation: 'vertical'
adaptive_height: True
spacing: dp(2)
padding: dp(0),dp(20),dp(0),dp(0)
MDBottomAppBar:
theme_bg_color:"Custom"
md_bg_color: 35/255, 122/255, 255/255, 0.89
MDTopAppBar:
icon:"home"
theme_icon_color: "Custom"
icon_color: "white"
font_size: dp(10)
icon_color:35/255, 122/255, 255/255, 0.89
type: "bottom"
left_action_items: [["home", lambda x: app.change_screen('main')]]
right_action_items: [["account", lambda x:x]]
I have tried to parsing variable symbol.data.decode() to MDTextField ID Employee but failure. I have tried for 3 days but no result or solved.
I Hope all members can teach me or make solve this problem and i will learn from this case.