Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python file:
- from kivy.app import App
- from kivy.clock import Clock
- from kivy.lang import Builder
- from kivy.uix.behaviors import FocusBehavior
- from kivy.uix.boxlayout import BoxLayout
- from kivy.uix.carousel import Carousel
- from kivy.uix.image import Image
- from kivy.uix.label import Label
- from kivy.uix.popup import Popup
- from kivy.uix.screenmanager import ScreenManager, Screen
- from kivy.properties import ObjectProperty, StringProperty, ListProperty, BooleanProperty
- import os
- from kivy.uix.recyclegridlayout import RecycleGridLayout
- from kivy.uix.recycleboxlayout import RecycleBoxLayout
- from kivy.uix.recycleview.layout import LayoutSelectionBehavior
- from kivy.uix.recycleview.views import RecycleDataViewBehavior
- from kivy.uix.behaviors import FocusBehavior
- from kivy.uix.recycleview import RecycleView
- import gspread
- from oauth2client.service_account import ServiceAccountCredentials
- from openpyxl import load_workbook
- class SecondScreen(Screen):
- def __init__(self, **kwargs):
- super(SecondScreen, self).__init__(**kwargs)
- Clock.schedule_once(self.post_init,0.1)
- def post_init(self, *args):
- path = r"xxx"
- wb = load_workbook(path)
- ws = wb.active
- product_list = []
- for cell in ws['B']:
- product_list.append(cell.value)
- self.ids.rv.data = [{'text': str(i)} for i in product_list]
- wb.close()
- wb.save(filename=path)
- def add_to_excel(self):
- path = r"xxx"
- wb = load_workbook(path)
- ws = wb.active
- ws.cell(column=2, row=ws.max_row + 1, value=self.add_item.text)
- wb.close()
- wb.save(filename=path)
- def refresh_rv_data(self):
- SecondScreen.post_init(self)
- class testApp(App):
- def build(self):
- return SecondScreen()
- def update_index(self, data_index, index):
- print('update data index: {}: {}'.format(data_index, index))
- self.data[data_index]['index'] = index
- def delete(self, data_index):
- print("delete {}".format(data_index))
- self._remove(data_index)
- def _remove(self, data_index):
- self.data.pop(data_index)
- self.data = [{
- 'data_index': i,
- 'index': d['index'],
- 'height': d['height'],
- 'text': d['text']
- }
- for i, d in enumerate(self.data)
- ]
- testApp().run()
- Kivy file:
- #:import C kivy.utils.get_color_from_hex
- <SwipeButton@Carousel>:
- text: ''
- size_hint_y: None
- height: 48
- ignore_perpendicular_swipes: True
- data_index: 0
- min_move: 20 / self.width
- on__offset: app.update_index(root.data_index, self.index)
- canvas.before:
- Color:
- rgba: C('FFFFFF33')
- Rectangle:
- pos: self.pos
- size: self.size
- Line:
- rectangle: self.pos + self.size
- Button:
- text: 'delete ({}:{})'.format(root.text, root.data_index)
- on_press: app.delete(root.data_index)
- Label:
- text: root.text
- Button:
- text: 'archive'
- on_press: app.archive(root.data_index)
- #########
- <SecondScreen>:
- add_item:add_item
- BoxLayout:
- orientation:'vertical'
- RecycleView:
- id: rv
- viewclass: 'SwipeButton'
- RecycleGridLayout:
- cols:1
- key_selection: 'selectable'
- default_size: None, dp(40)
- default_size_hint: 1, None
- size_hint_y: None
- height: self.minimum_height
- multiselect: True
- touch_multiselect: True
- BoxLayout:
- TextInput:
- id: add_item
- Button:
- text:'Add item'
- on_release:
- root.add_to_excel()
- root.refresh_rv_data()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement