#python #android #python-3.x #kivy #kivymd
#python #Android #python-3.x #kivy #kivymd
Вопрос:
кнопка «Назад» при 1-й загрузке не работает на singin_screen, но она работает на option_screen (при 1-й загрузке), и после этого, если выбрать любую опцию из опций и перейти к экрану этой опции, а затем вернуться к экрану опций, задняя часть не работает, она ничего не делает
sign_screen(back closes the app)
--> option_screen(back button works on 1st load but not after that)
--> body_screen
--> RemoveStock_screen
--> Stoploss_ip
(on these three screens there no problem with back button it works fine)
.py код
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.popup import Popup
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.gridlayout import MDGridLayout
from kivymd.uix.button import MDFlatButton
import sys, time, threading
import pyrebase
from kivymd.uix.screen import MDScreen
from kivy.uix.screenmanager import ScreenManager, Screen
from datetime import datetime,timedelta
import pandas_datareader.data as web
from kivymd.theming import ThemeManager
import pandas as pd
from kivymd.icon_definitions import md_icons
from kivy.utils import get_color_from_hex
import webbrowser
from kivymd.uix.screen import Screen
from kivymd.uix.list import MDList,ThreeLineListItem,ThreeLineAvatarIconListItem,OneLineListItem
from kivymd.uix.list import IconLeftWidget,ImageLeftWidget
from kivy.uix.scrollview import ScrollView
from kivy.uix.button import Button
from kivymd.uix.card import MDCardSwipe
from kivy.properties import ObjectProperty
import csv
from os import path
from kivy.uix.image import Image
from kivy.app import App
from kivy.uix.textinput import TextInput
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import NumericProperty, ListProperty, BooleanProperty, ObjectProperty, StringProperty
from kivy.uix.recycleview import RecycleView
from kivy.uix.recyclegridlayout import RecycleGridLayout
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.label import Label
import re
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
import pandas as pd
from kivy.clock import Clock
from functools import partial
from kivymd.uix.dialog import MDDialog
from kivymd.uix.textfield import MDTextField,MDTextFieldRound
from kivymd.uix.label import MDLabel
from kivymd.toast import toast
from kivy.core.window import Window
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
username =''
fg = BooleanProperty(False)
class Signin(MDScreen):
user_name = ObjectProperty(None)
def hook_keyboard(self, Window, key, *largs):
if key == 27:
button_yes = MDFlatButton(text="Yes", text_color=(98 / 255, 0, 238 / 255, 1),
on_press=self.quit_appp)
button_No = MDFlatButton(text="No", text_color=(98 / 255, 0, 238 / 255, 1),
on_press=self.close_dialog1)
self.signin_dialog = MDDialog(title='Are you sure?', text="This action will close the App",
size_hint=(.9, .5), buttons=[button_No, button_yes])
self.signin_dialog.open()
return True
def quit_appp(self, dl):
run1().stop()
def open_link(instance, link):
webbrowser.open(link)
def build(self):
Window.bind(on_keyboard=self.hook_keyboard)
def check(self, email):
regex = '^[a-z0-9] [._]?[a-z0-9] [@]w [.]w{2,3}
.kv код
ScreenManager:
Signin:
Option:
Body:
id:body
Remove_stock:
ListApp:
<Remove_stock>:
name: 'RemoveStock_screen'
on_enter:root.build()
BoxLayout:
orientation: "vertical"
spacing: "10dp"
MDToolbar:
title:'List of shares'
type: "top"
size_hint_y:0.1
pos_hint: {'top':1.0}
left_action_items: [["arrow-left", lambda x: root.back()]]
md_bg_color:152/255,87/255,189/255,1
elevation:10
ScrollView:
scroll_type:["content"]
MDList:
id: md_list
padding: 0
pos_hint: {'center_x': .5, 'center_y': .5}
MDLabel:
text:'I am Remove_stock'
halign:'center'
<Body>:
name: 'body_screen'
canvas.before:
Color:
rgba: 155/255, 159/255, 250/255, 1
Rectangle:
pos: self.pos
size: self.size
MDLabel:
text:"I am Body class"
halign:'center'
<Signin>:
canvas.before:
Color:
rgba: 239/255, 235/255, 216/255, 1
Rectangle:
pos: self.pos
size: self.size
name: 'signin_screen'
user_name: user_name
orientation:'vertical'
MDTextField:
id: user_name
hint_text:'Email'
icon_right: "email"
icon_right_color:0,0,0,1
required: True
color_active: 0, 0, 0, 1
helper_text: "Invalid email id"
helper_text_mode: "on_error"
halign:'center'
pos_hint: {'center_x': .5, 'center_y': .5}
size_hint_x: 0.9
width:300
color_mode: 'custom'
line_color_normal: 0,0,0,1
MDRoundFlatIconButton:
icon: "arrow-right"
text:"Submit"
text_color:1,1,1,1
font_size: 20
pos_hint: {'center_x': .5, 'center_y': .4}
halign:'center'
md_bg_color:36/255,76/255,100/255,1
elevation:10
background_color: (1,1,1,1)
on_press :
root.btn()
NavigationLayout:
ScreenManager:
Screen:
BoxLayout:
orientation: 'vertical'
MDToolbar:
title:'SignIn'
type: "top"
size_hint_y:0.1
pos_hint: {'top':1.0}
left_action_items: [["menu", lambda x: nav_drawer.toggle_nav_drawer()]]
right_action_items: [["exit-to-app", lambda x: app.stop()]]
md_bg_color:152/255,87/255,189/255,1
elevation:10
Widget:
MDNavigationDrawer:
id: nav_drawer
MDBoxLayout:
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'crop1.jpg'
orientation:'vertical'
spacing: '10dp'
padding: '10dp'
pos_hint: {'center_x': .5}
MDLabel:
text:'Developer'
bold: True
user_font_size: "20dp"
theme_text_color: "Custom"
text_color: 1, 0, .5, 1
halign:'center'
size_hint_y:None
height: 20
MDFloatingActionButton:
icon:'me.png'
elevation:12
pos_hint: {'center_x': .5,'center_y': .8}
user_font_size: "20dp"
MDLabel:
size_hint_y:None
height: 10
MDLabel:
text:'Rushabh Patil'
font_style:'Subtitle1'
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
bold: True
pos_hint: {'center_x': .5}
size_hint_y:None
height: self.texture_size[1]
halign:'center'
MDLabel:
text:'rushabhpatil.rdp@gmail.com'
font_style:'Caption'
bold: True
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
size_hint_y:None
height: self.texture_size[1]
halign:'center'
MDLabel:
size_hint_y:None
height: 230
ScrollView:
MDList:
OneLineIconListItem:
text:'Github Profile'
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
bold: True
on_press: root.open_link('https://github.com/rushbhpatil')
IconLeftWidget:
icon:"Github-icon.png"
user_font_size: "7dp"
pos_hint: {'center_x': .5, 'center_y': .5}
MDLabel:
size_hint_y:None
height: 60
OneLineIconListItem:
text:'Linkedin Profile'
theme_text_color: "Custom"
text_color: 1, 1, 1, 1
bold: True
on_press: root.open_link('https://www.linkedin.com/in/rushbh-patil-77313062/')
IconLeftWidget:
icon:'Linkedin-icon.png'
user_font_size: "7dp"
pos_hint: {'center_x': .5, 'center_y': .5}
MDCard:
md_bg_color:0, 0, 0, 0
orientation:'vertical'
size_hint:None,None
pos_hint: {'center_x': .5, 'center_y': .1}
height:100
width:80
elevation:0
MDLabel:
text:'Made For'
theme_text_color: "Custom"
text_color:176/255,176/255,176/255,1
font_size: "9dp"
pos_hint: {'center_x': .55, 'center_y': .5}
halign:'center'
size_hint:1,None
height:10
MDIconButton:
md_bg_color:0, 0, 0, 0
icon: "absys_logo.png"
user_font_size: "18dp"
halign:'center'
size_hint:None,None
pos_hint: {'center_x': .5, 'center_y': .5}
<Option>:
canvas:
Color:
rgba: 138/255,43/255,226/255,.4
Rectangle:
size: self.size
pos: self.pos
name: 'option_screen'
orientation:'vertical'
spacing: '20dp'
# on_enter:root.build()
MDToolbar:
title:'Choose Option'
type: "top"
md_bg_color:152/255,87/255,189/255,1
left_action_items: [["arrow-left", lambda x: root.back()]]
size_hint_y:0.1
pos_hint: {'top':1.0}
elevation:10
MDCard:
md_bg_color:138/255,43/255,226/255,1
orientation:'vertical'
size_hint:None,None
pos_hint: {'center_x': .5, 'center_y': .74}
height:110
width:60
elevation:8
MDIconButton:
md_bg_color:138/255,43/255,226/255,1
icon: "beaker-plus"
user_font_size: "40dp"
halign:'center'
size_hint:None,None
pos_hint: {'center_x': .5, 'center_y': .6}
elevation:6
on_press :
root.manager.transition.direction = 'left'
root.manager.current = 'body_screen'
MDLabel:
text:'Add Stock'
theme_text_color: "Custom"
text_color:1,1,1,1
font_size: "15dp"
pos_hint: {'center_x': .5, 'center_y': .4}
halign:'center'
MDCard:
md_bg_color:138/255,43/255,226/255,1
orientation:'vertical'
size_hint:None,None
pos_hint: {'center_x': .5, 'center_y': .454}
height:110
width:60
elevation:8
MDIconButton:
md_bg_color:138/255,43/255,226/255,1
icon: "beaker-minus"
user_font_size: "40dp"
halign:'center'
size_hint:None,None
pos_hint: {'center_x': .5, 'center_y': .6}
# disabled : True if root.flag_dis==True else False
on_press :
root.manager.transition.direction = 'left'
root.manager.current = 'RemoveStock_screen'
MDLabel:
text:'Remove Stock'
theme_text_color: "Custom"
text_color:1,1,1,1
pos_hint: {'center_x': .5, 'center_y': .4}
font_size: "15dp"
halign:'center'
MDCard:
md_bg_color:138/255,43/255,226/255,1
orientation:'vertical'
size_hint:None,None
pos_hint: {'center_x': .5, 'center_y': .17}
height:110
width:60
elevation:8
MDIconButton:
icon: "check"
user_font_size: "40dp"
halign:'center'
size_hint:None,None
pos_hint: {'center_x': .5, 'center_y': .6}
# disabled : False if root.flag_dis==False else True
on_press :
root.manager.transition.direction = 'left'
root.manager.current = 'Stoploss_ip'
MDLabel:
text:'Check Stoploss'
theme_text_color: "Custom"
text_color:1,1,1,1
font_size: "15dp"
pos_hint: {'center_x': .5, 'center_y': .4}
halign:'center'
<ListApp>:
name: 'Stoploss_ip'
on_enter:root.build()
MDBoxLayout:
orientation:'vertical'
MDToolbar:
title:'Stoploss'
type: "top"
md_bg_color:152/255,87/255,189/255,1
left_action_items: [["arrow-left", lambda x: root.back()]]
# right_action_items: [["reload", lambda x: root.update()]]
size_hint_y:0.1
pos_hint: {'top':1.0}
elevation:10
ScrollView:
MDList:
id: list_view
pos_hint: {'y':3.0}
MDLabel:
text:'I am ListApp'
halign:'center'
после входа в систему открывается экран опций, и вы нажимаете клавишу Esc, он возвращается к signin_screen, но на экране входа Esc не работает
но если вы не нажмете Esc и не выберете любой вариант из трех, откроется следующий экран, и при нажатии Esc он вернется к option_screen
и теперь option_screen загружается 2-й раз, и если я нажимаю Esc, он также не работает, если вы хотите вернуться к signin_screen, нажмите back_arrow на панели инструментов.. it takes you to signin_screen.. but when you press Esc on signin_screen now it will take you to option_screen directly
каждый раз, когда он ведет себя по-разному
Комментарии:
1.
android
Уместен ли здесь тег?2. Опубликуйте минимальный исполняемый пример. Если кнопка возврата ведет себя по-разному на разных экранах, предположительно, в вашем коде есть что-то, о чем мы не можем догадаться.
3. @inclument Я обновил минимальный доступный пример.. пожалуйста, взгляните
# pass the regular expression
# and the string in search() method
if (re.search(regex, email)):
return True
else:
return False
def btn(self):
global username
global fg
un = self.user_name.text
if self.check(un):
username, u = un.split('@')
print(username)
fg = True
threading.Thread(target=self.check_fb_file()).start()
else:
button_ok = MDFlatButton(text="Ok", text_color=(98 / 255, 0, 238 / 255, 1),
on_press=self.close_dialog)
self.signin_dialog = MDDialog(title='Error', text="That doesn't appear to be a valid email address",
size_hint=(.9, .5), buttons=[button_ok])
self.signin_dialog.open()
def check_fb_file(self):
# down = Firebaseupdown()
# down.fire_download()
self.user_name.text = ''
MDApp.get_running_app().root.transition.direction = 'left'
MDApp.get_running_app().root.current = 'option_screen'
# self.popup.dismiss()
def close_dialog(self, obj):
self.signin_dialog.dismiss()
self.user_name.text = ''
def close_dialog1(self, obj):
self.dialog.dismiss()
counter = 1
class Option(MDScreen):
global username
flag_dis = BooleanProperty(False)
def hook_keyboard(self, Window, key, *largs):
if key == 27:
self.back()
return True
def on_pre_enter(self, *args):
global counter
Window.bind(on_keyboard=self.hook_keyboard)
file_name = username "_stoploss.csv"
if path.exists(file_name) and counter == 1:
toast("The data has been synchronized with cloud")
counter = 1
elif not path.exists(file_name):
self.flag_dis = True
toast('Please Go to Add Stock')
else:
self.flag_dis = False
print('All good')
pass
def back(self):
MDApp.get_running_app().root.transition.direction = 'right'
MDApp.get_running_app().root.current = 'signin_screen'
class Body(MDScreen):
def back(self):
MDApp.get_running_app().root.transition.direction = 'right'
MDApp.get_running_app().root.current = 'option_screen'
def hook_keyboard(self, Window, key, *largs):
if key == 27:
self.back()
return True
def on_pre_enter(self):
Window.bind(on_keyboard=self.hook_keyboard)
def back(self):
MDApp.get_running_app().root.transition.direction = 'right'
MDApp.get_running_app().root.current = 'option_screen'
class Remove_stock(MDScreen):
def hook_keyboard(self, Window, key, *largs):
if key == 27:
self.back()
return True
def build(self):
Window.bind(on_keyboard=self.hook_keyboard)
def back(self):
MDApp.get_running_app().root.transition.direction = 'right'
MDApp.get_running_app().root.current = 'option_screen'
class ListApp(MDScreen):
def hook_keyboard(self, Window, key, *largs):
if key == 27:
self.back()
return True
def build(self):
Window.bind(on_keyboard=self.hook_keyboard)
def back(self):
MDApp.get_running_app().root.transition.direction = 'right'
MDApp.get_running_app().root.current = 'option_screen'
sm = ScreenManager()
sm.add_widget(Signin(name='signin_screen'))
sm.add_widget(Option(name='option_screen'))
sm.add_widget(ListApp(name='Stoploss_ip'))
sm.add_widget(Body(name='body_screen'))
sm.add_widget(Remove_stock(name='RemoveStock_screen'))
class run1(MDApp):
def build(self):
kv = Builder.load_file("min.kv")
return kv
if __name__ == "__main__":
run1().run()
.kv код
после входа в систему открывается экран опций, и вы нажимаете клавишу Esc, он возвращается к signin_screen, но на экране входа Esc не работает
но если вы не нажмете Esc и не выберете любой вариант из трех, откроется следующий экран, и при нажатии Esc он вернется к option_screen
и теперь option_screen загружается 2-й раз, и если я нажимаю Esc, он также не работает, если вы хотите вернуться к signin_screen, нажмите back_arrow на панели инструментов.. it takes you to signin_screen.. but when you press Esc on signin_screen now it will take you to option_screen directly
каждый раз, когда он ведет себя по-разному
Комментарии:
1.
android
Уместен ли здесь тег?2. Опубликуйте минимальный исполняемый пример. Если кнопка возврата ведет себя по-разному на разных экранах, предположительно, в вашем коде есть что-то, о чем мы не можем догадаться.
3. @inclument Я обновил минимальный доступный пример.. пожалуйста, взгляните