<s> import kivy <EOL> import urllib2 <EOL> import json <EOL> import pprint <EOL> import functools <EOL> kivy . require ( '<STR_LIT>' ) <EOL> from kivy . app import App <EOL> from kivy . lang import Builder <EOL> from kivy . properties import ListProperty <EOL> from kivy . uix . widget import Widget <EOL> from kivy . uix . label import Label <EOL> from kivy . uix . button import Button <EOL> from kivy . uix . togglebutton import ToggleButton <EOL> from kivy . uix . gridlayout import GridLayout <EOL> from kivy . uix . boxlayout import BoxLayout <EOL> from kivy . uix . listview import ListView <EOL> from functools import partial <EOL> from kivy . core . window import Window <EOL> from kivy . uix . scrollview import ScrollView <EOL> from kivy . uix . modalview import ModalView <EOL> from kivy . uix . textinput import TextInput <EOL> Builder . load_string ( '''<STR_LIT>''' <EOL> ) <EOL> class CLabel ( ToggleButton ) : <EOL> bgcolor = ListProperty ( [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] ) <EOL> class HeaderLabel ( Label ) : <EOL> bgcolor = ListProperty ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> data_json = open ( '<STR_LIT>' ) <EOL> data = json . load ( data_json ) <EOL> header = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> col_size = [ <NUM_LIT:0.1> , <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> ] <EOL> body_alignment = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> products_list = [ ] <EOL> counter = <NUM_LIT:0> <EOL> class DataGrid ( GridLayout ) : <EOL> def add_row ( self , row_data , row_align , cols_size , instance , ** kwargs ) : <EOL> global counter <EOL> self . rows += <NUM_LIT:1> <EOL> def change_on_press ( self ) : <EOL> childs = self . parent . children <EOL> for ch in childs : <EOL> if ch . id == self . id : <EOL> print ch . id <EOL> print len ( ch . id ) <EOL> row_n = <NUM_LIT:0> <EOL> if len ( ch . id ) == <NUM_LIT:11> : <EOL> row_n = ch . id [ <NUM_LIT:4> : <NUM_LIT:5> ] <EOL> else : <EOL> row_n = ch . id [ <NUM_LIT:4> : <NUM_LIT:6> ] <EOL> for c in childs : <EOL> if ( '<STR_LIT>' + str ( row_n ) + '<STR_LIT>' ) == c . id : <EOL> if c . state == "<STR_LIT>" : <EOL> c . state = "<STR_LIT>" <EOL> else : <EOL> c . state = "<STR_LIT>" <EOL> if ( '<STR_LIT>' + str ( row_n ) + '<STR_LIT>' ) == c . id : <EOL> if c . state == "<STR_LIT>" : <EOL> c . state = "<STR_LIT>" <EOL> else : <EOL> c . state = "<STR_LIT>" <EOL> if ( '<STR_LIT>' + str ( row_n ) + '<STR_LIT>' ) == c . id : <EOL> if c . state == "<STR_LIT>" : <EOL> c . state = "<STR_LIT>" <EOL> else : <EOL> c . state = "<STR_LIT>" <EOL> if ( '<STR_LIT>' + str ( row_n ) + '<STR_LIT>' ) == c . id : <EOL> if c . state == "<STR_LIT>" : <EOL> c . state = "<STR_LIT>" <EOL> else : <EOL> c . state = "<STR_LIT>" <EOL> def change_on_release ( self ) : <EOL> if self . state == "<STR_LIT>" : <EOL> self . state = "<STR_LIT>" <EOL> else : <EOL> self . state = "<STR_LIT>" <EOL> n = <NUM_LIT:0> <EOL> for item in row_data : <EOL> cell = CLabel ( text = ( '<STR_LIT>' + item + '<STR_LIT>' ) , <EOL> background_normal = "<STR_LIT>" , <EOL> background_down = "<STR_LIT>" , <EOL> halign = row_align [ n ] , <EOL> markup = True , <EOL> on_press = partial ( change_on_press ) , <EOL> on_release = partial ( change_on_release ) , <EOL> text_size = ( <NUM_LIT:0> , None ) , <EOL> size_hint_x = cols_size [ n ] , <EOL> size_hint_y = None , <EOL> height = <NUM_LIT> , <EOL> id = ( "<STR_LIT>" + str ( counter ) + "<STR_LIT>" + str ( n ) ) ) <EOL> cell_width = Window . size [ <NUM_LIT:0> ] * cell . size_hint_x <EOL> cell . text_size = ( cell_width - <NUM_LIT:30> , None ) <EOL> cell . texture_update ( ) <EOL> self . add_widget ( cell ) <EOL> n += <NUM_LIT:1> <EOL> counter += <NUM_LIT:1> <EOL> def remove_row ( self , n_cols , instance , ** kwargs ) : <EOL> childs = self . parent . children <EOL> selected = <NUM_LIT:0> <EOL> for ch in childs : <EOL> for c in reversed ( ch . children ) : <EOL> if c . id != "<STR_LIT>" : <EOL> if c . state == "<STR_LIT>" : <EOL> self . remove_widget ( c ) <EOL> print str ( c . id ) + '<STR_LIT>' + str ( c . state ) <EOL> selected += <NUM_LIT:1> <EOL> if selected == <NUM_LIT:0> : <EOL> for ch in childs : <EOL> count_01 = n_cols <EOL> count_02 = <NUM_LIT:0> <EOL> count = <NUM_LIT:0> <EOL> while ( count < n_cols ) : <EOL> if n_cols != len ( ch . children ) : <EOL> for c in ch . children : <EOL> if c . id != "<STR_LIT>" : <EOL> print "<STR_LIT>" + str ( len ( ch . children ) ) <EOL> print "<STR_LIT>" + str ( n_cols + <NUM_LIT:1> ) <EOL> self . remove_widget ( c ) <EOL> count += <NUM_LIT:1> <EOL> break <EOL> else : <EOL> break <EOL> else : <EOL> break <EOL> def select_all ( self , instance , ** kwargs ) : <EOL> childs = self . parent . children <EOL> for ch in childs : <EOL> for c in ch . children : <EOL> if c . id != "<STR_LIT>" : <EOL> c . state = "<STR_LIT>" <EOL> def unselect_all ( self , instance , ** kwargs ) : <EOL> childs = self . parent . children <EOL> for ch in childs : <EOL> for c in ch . children : <EOL> if c . id != "<STR_LIT>" : <EOL> c . state = "<STR_LIT>" <EOL> def show_log ( self , instance , ** kwargs ) : <EOL> childs = self . parent . children <EOL> for ch in childs : <EOL> for c in ch . children : <EOL> if c . id != "<STR_LIT>" : <EOL> print str ( c . id ) + '<STR_LIT>' + str ( c . state ) + '<STR_LIT>' + str ( c . text ) <EOL> def __init__ ( self , header_data , body_data , b_align , cols_size , ** kwargs ) : <EOL> super ( DataGrid , self ) . __init__ ( ** kwargs ) <EOL> self . size_hint_y = None <EOL> self . bind ( minimum_height = self . setter ( '<STR_LIT>' ) ) <EOL> self . cols = len ( header_data ) <EOL> self . rows = len ( body_data ) + <NUM_LIT:1> <EOL> self . spacing = [ <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> n = <NUM_LIT:0> <EOL> for hcell in header_data : <EOL> header_str = "<STR_LIT>" + str ( hcell ) + "<STR_LIT>" <EOL> self . add_widget ( HeaderLabel ( text = header_str , <EOL> markup = True , <EOL> size_hint_y = None , <EOL> height = <NUM_LIT> , <EOL> id = "<STR_LIT>" , <EOL> size_hint_x = cols_size [ n ] ) ) <EOL> n += <NUM_LIT:1> <EOL> grid = DataGrid ( header , data , body_alignment , col_size ) <EOL> grid . rows = <NUM_LIT:10> <EOL> scroll = ScrollView ( size_hint = ( <NUM_LIT:1> , <NUM_LIT:1> ) , size = ( <NUM_LIT> , <NUM_LIT> ) , scroll_y = <NUM_LIT:0> , pos_hint = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } ) <EOL> scroll . add_widget ( grid ) <EOL> scroll . do_scroll_y = True <EOL> scroll . do_scroll_x = False <EOL> pp = partial ( grid . add_row , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , body_alignment , col_size ) <EOL> add_row_btn = Button ( text = "<STR_LIT>" , on_press = pp ) <EOL> del_row_btn = Button ( text = "<STR_LIT>" , on_press = partial ( grid . remove_row , len ( header ) ) ) <EOL> upt_row_btn = Button ( text = "<STR_LIT>" ) <EOL> slct_all_btn = Button ( text = "<STR_LIT>" , on_press = partial ( grid . select_all ) ) <EOL> unslct_all_btn = Button ( text = "<STR_LIT>" , on_press = partial ( grid . unselect_all ) ) <EOL> show_grid_log = Button ( text = "<STR_LIT>" , on_press = partial ( grid . show_log ) ) <EOL> def modal_insert ( self ) : <EOL> lbl1 = Label ( text = '<STR_LIT>' , id = "<STR_LIT>" ) <EOL> lbl2 = Label ( text = '<STR_LIT>' , id = "<STR_LIT>" ) <EOL> lbl3 = Label ( text = '<STR_LIT>' , id = "<STR_LIT>" ) <EOL> lbl4 = Label ( text = '<STR_LIT>' , id = "<STR_LIT>" ) <EOL> txt1 = TextInput ( text = '<STR_LIT>' , id = "<STR_LIT>" ) <EOL> txt2 = TextInput ( text = '<STR_LIT>' , id = "<STR_LIT>" ) <EOL> txt3 = TextInput ( text = '<STR_LIT>' , id = "<STR_LIT>" ) <EOL> txt4 = TextInput ( text = '<STR_LIT>' , id = "<STR_LIT>" ) <EOL> insertion_grid = GridLayout ( cols = <NUM_LIT:2> ) <EOL> insertion_grid . add_widget ( lbl1 ) <EOL> insertion_grid . add_widget ( txt1 ) <EOL> insertion_grid . add_widget ( lbl2 ) <EOL> insertion_grid . add_widget ( txt2 ) <EOL> insertion_grid . add_widget ( lbl3 ) <EOL> insertion_grid . add_widget ( txt3 ) <EOL> insertion_grid . add_widget ( lbl4 ) <EOL> insertion_grid . add_widget ( txt4 ) <EOL> content = Button ( text = '<STR_LIT>' ) <EOL> modal_layout = BoxLayout ( orientation = "<STR_LIT>" ) <EOL> modal_layout . add_widget ( insertion_grid ) <EOL> def insert_def ( self ) : <EOL> input_list = [ ] <EOL> for text_inputs in reversed ( self . parent . children [ <NUM_LIT:2> ] . children ) : <EOL> if text_inputs . id == "<STR_LIT>" : <EOL> input_list . append ( text_inputs . text ) <EOL> print input_list <EOL> grid . add_row ( input_list , body_alignment , col_size , self ) <EOL> insert_btn = Button ( text = "<STR_LIT>" , on_press = insert_def ) <EOL> modal_layout . add_widget ( insert_btn ) <EOL> modal_layout . add_widget ( content ) <EOL> view = ModalView ( auto_dismiss = False ) <EOL> view . add_widget ( modal_layout ) <EOL> content . bind ( on_press = view . dismiss ) <EOL> insert_btn . bind ( on_release = view . dismiss ) <EOL> view . open ( ) <EOL> add_custom_row = Button ( text = "<STR_LIT>" , on_press = modal_insert ) <EOL> def json_fill ( self ) : <EOL> for d in data : <EOL> print d <EOL> grid . add_row ( d , body_alignment , col_size , self ) <EOL> json_fill_btn = Button ( text = "<STR_LIT>" , on_press = partial ( json_fill ) ) <EOL> btn_grid = BoxLayout ( orientation = "<STR_LIT>" ) <EOL> btn_grid . add_widget ( json_fill_btn ) <EOL> btn_grid . add_widget ( add_row_btn ) <EOL> btn_grid . add_widget ( del_row_btn ) <EOL> btn_grid . add_widget ( upt_row_btn ) <EOL> btn_grid . add_widget ( slct_all_btn ) <EOL> btn_grid . add_widget ( unslct_all_btn ) <EOL> btn_grid . add_widget ( show_grid_log ) <EOL> btn_grid . add_widget ( add_custom_row ) <EOL> root = BoxLayout ( orientation = "<STR_LIT>" ) <EOL> root . add_widget ( scroll ) <EOL> root . add_widget ( btn_grid ) <EOL> class MainApp ( App ) : <EOL> def build ( self ) : <EOL> return root <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> MainApp ( ) . run ( ) </s>
