Skip to content

Instantly share code, notes, and snippets.

@onslauth
Created August 22, 2019 13:10
Show Gist options
  • Save onslauth/be747b627bb484d009df1fe2f848c268 to your computer and use it in GitHub Desktop.
Save onslauth/be747b627bb484d009df1fe2f848c268 to your computer and use it in GitHub Desktop.
main.py
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
from openpyxl import load_workbook
class SecondScreen(Screen):
data = ListProperty( )
def __init__(self, **kwargs):
super(SecondScreen, self).__init__(**kwargs)
Clock.schedule_once(self.post_init,0.1)
def post_init(self, *args):
path = r"input.xlsx"
wb = load_workbook(path)
print( "Sheets: {}".format( wb.sheetnames ) )
ws = wb.active
print( "ws: {}".format( ws ) )
product_list = []
for cell in ws['A']:
print( " cell: {}".format( cell ) )
print( " value: {}".format( cell.value ) )
product_list.append(cell.value)
print( "product_list: {}".format( product_list ) )
self.data = [{
'data_index': i,
'index': 1,
'height': 48,
'text': str( j )
}
for i,j in enumerate( product_list )
]
self.ids.rv.data = self.data
wb.close()
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):
second_screen = None
def build(self):
self.second_screen = SecondScreen( )
return self.second_screen
def update_index(self, data_index, index):
print('update data index: {}: {}'.format(data_index, index))
self.second_screen.data[data_index]['index'] = index
def delete(self, data_index):
print("delete {}".format(data_index))
self._remove(data_index)
def archive(self,data_index):
print("archive: {}".format(data_index))
self._remove(data_index)
def _remove(self, data_index):
self.second_screen.data.pop(data_index)
self.second_screen.data = [{
'data_index': i,
'index': d['index'],
'height': d['height'],
'text': d['text']
}
for i, d in enumerate(self.second_screen.data)
]
self.second_screen.ids.rv.data = self.second_screen.data
testApp().run()
#: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'
do_scroll_x: False
scroll_timeout: 100
#RecycleBoxLayout:
# orientation: "vertical"
# size_hint_y: None
# height: self.minimum_height
# default_size_hint: 1, None
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment