user interface - how to enable/disable multiple TextInput on focusing in kivy in python -


i'm trying enable/disable textinput in kivy. multiple textinput there. (1) when click on textinput, particular textinput editable. (2) default set on disable mode. (3) scrollbar should there, suppose there hundreds of inputs there.(i unable bring that). (4) 1 more problem facing is: text of textinput not visible when there hundreds of inputs. there option set default size not affect whether there 2-3 inputs or 100s of inputs. (5) values @ textinput , label should dynamic, should stored @ variable globally. @palimpalim helped me existing code. thank everyone.

from kivy.app import app kivy.uix.tabbedpanel import tabbedpanel kivy.uix.boxlayout import boxlayout kivy.properties import stringproperty kivy.uix.textinput import textinput kivy.lang import builder kivy.uix.scrollview import scrollview kivy.properties import stringproperty  rows = ['ac', 'asd', 'kjhgf', 'b' ,'bn', 'sdf', 'ytrwd', 'hfs' ,'erf', ...]  builder.load_string("""  <test>:     do_default_tab: false      tabbedpanelitem:         text: 'page1'         scrollview:             size_hint: (none, none)             size: (400, 400)             table:                 padding: 50, 50, 50, 50                 orientation: 'vertical'  <row>:     spacing: 50     size_hint: 1, .9     txt: txtinpt.text     label:         text: root.txt     textinput:         id: txtinpt         text: root.txt      button:         text: 'save'  """) class table(boxlayout):     def __init__(self, **kwargs):         super(table, self).__init__(**kwargs)         row in rows:             self.add_widget(row(row))    class row(boxlayout):     txt = stringproperty()     def __init__(self, row, **kwargs):         super(row, self).__init__(**kwargs)         self.txt = row  class scrollablelabel(scrollview):     text = stringproperty('')  class test(tabbedpanel):     pass  class myapp(app):      def build(self):         test = test()         return test   if __name__ == '__main__':     myapp().run() 

kivy gui

ok, first, want make number of rows dynamic, , potentially big, don't want create , manage rows yourself, slow both @ populate time , when scrolling, want use recyclevview.

recycleview takes list of dictionaries, containing data widgets, , class display them, create of these needed fill visible part of scrollview (which manages), , feed right data right line when scroll, positionning them give illusion of infinite stream, allows effortlessly manage hundreds of thousands of rows, while current way becomes unusable after few hundreds of items.

usage simple, have list of items, text inside, let's convert list of dicts, , put in app easy reference kv.

class myapp(app):     data = listproperty()      def build(self):         self.data = [{'row_id': i, 'text': x} i, x in enumerate(rows)]         test = test()         return test 

now, let's replace scrollview recycleview

#:import factory kivy.factory.factory  <test>:     do_default_tab: false      tabbedpanelitem:         text: 'page1'         recycleview:             size_hint: (none, none)             size: (400, 400)             data: app.data             viewclass: factory.row             recycleboxlayout:                 padding: 50, 50, 50, 50                 size_hint_y: none                 size: self.minimum_size                 default_size_hint: 1, none                 default_size: 0, dp(36)  # width overriden size_hint_x                 orientation: 'vertical' 

we size things automatically, here recycleview takes available space (you can resize window give less/more space), , recycleboxlayout inside big needs to, computing size of rows, defined statically, avoid effect described in (4). scrollbar appears when needed, i.e, when recycleboxlayout bigger recycleview.

now, fix row class usable proper sizing , usage in recycleview.

<row>:     spacing: 50     text: txtinpt.text     label:         text: root.text      textinput:         id: txtinpt         text: root.text      button:         text: 'save'         on_press:             app.data[root.row_id]['text'] = root.text 

and

class row(boxlayout):     text = stringproperty()     row_id = numericproperty() 

here idea saving edit source data in app, using row id know put it, pretty straightforward.

now, didn't bit disabling textinput, mean focused/unfocused? because if disable textinputs, touching them won't give them focus, , (1) won't realised, if disable textinputs, need give user way enable them.

full program

from kivy.app import app kivy.uix.tabbedpanel import tabbedpanel kivy.uix.boxlayout import boxlayout kivy.properties import stringproperty, listproperty, numericproperty kivy.lang import builder kivy.uix.scrollview import scrollview  rows = ['ac', 'asd', 'kjhgf', 'b', 'bn', 'sdf', 'ytrwd', 'hfs', 'erf', 'boo'] # make lot more of them, see performances, yep, 100k items... rows = rows * 10000  builder.load_string(""" #:import factory kivy.factory.factory #:import dp kivy.metrics.dp  <test>:     do_default_tab: false      tabbedpanelitem:         text: 'page1'         recycleview:             # size_hint: (none, none)             # size: (400, 400)             data: app.data             viewclass: factory.row             recycleboxlayout:                 padding: 50, 50, 50, 50                 orientation: 'vertical'                 size_hint: 1, none                 size: self.minimum_size                 default_size_hint: 1, none                 default_size: 0, dp(36)  <row>:     spacing: 50     text: txtinpt.text     label:         text: root.text      textinput:         id: txtinpt         text: root.text      button:         text: 'save'         on_press:             app.data[root.row_id]['text'] = root.text  """)   class row(boxlayout):     text = stringproperty()     row_id = numericproperty()   class test(tabbedpanel):     pass   class myapp(app):     data = listproperty()      def build(self):         self.data = [{'row_id': i, 'text': x} i, x in enumerate(rows)]         test = test()         return test   if __name__ == '__main__':     myapp().run() 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -