Skip to content

Commit

Permalink
ui.Swipper removed definitivly
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Sep 23, 2024
1 parent 821f87f commit f6ee62d
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
poetry.lock
htagui/swipers2.py

15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,21 +337,6 @@ This component should be embbeded in an element which have a constraint on its h
Note that the list is a list of lambda (`List[Callable[[], Tag]]`) to create the rendering on-demand.


## Object Swipper

**IMPORTANT** : not included in default (`ui.ALL`). If you want to use it, you must include it, or `imports=ui.FULL` (because +170ko). TODO: need to find a clever soluce ;-)

A component to use a Swiper (https://swiperjs.com/).

```python

ll=[lambda i=i: MyObject(i) for i in range(1,200_000)] # slide created on demand
# or ll=[MyObject(i) for i in range(1,20)] # concrete slides
self <= ui.Swiper(ll, default=0)

```


## Object View

A view component which handle the browser navigation mechanism (go back)
Expand Down
3 changes: 1 addition & 2 deletions htagui/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from .fileupload import FileUpload
from .containers import VScroll,VScrollPager, View, Grid
from .sortables import Sortable
from .swipers import Swiper
from .javascripts import JSKEYABLE
class App(Tag.body):
_ui=None
Expand All @@ -35,4 +34,4 @@ def ui(self):
# Swiper not inluded by default !!!!!

ALL=[JSKEYABLE, App,Form,Tabs,Dialog,HSplit,VSplit,IText,ITextarea,IRange,IBool,ISelect,IRadios,FileUpload,Sortable,VScroll,VScrollPager,View,Grid]
FULL=ALL+[Swiper] # Swiper not inluded by default !!!!! (coz +170ko)

129 changes: 0 additions & 129 deletions htagui/swipers.py

This file was deleted.

62 changes: 62 additions & 0 deletions if_you_want_swiper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from htag import Tag,expose,Runner
from htagui import shoelace as ui

DOC = """Versions 0.6.1 to 0.6.4 provided an object ui.Swiper(). But it was a bad idea ;-)
So it was removed for versions > 0.6.4, because it's easy (using shoelace) to provide
this kind of component... Here is an example, which provide exactly the same features.
"""

class SLSwiper(Tag.sl_carousel):
def init(self,ll:list,default=0,**a):
isAllRealTags = all([isinstance(i,Tag) for i in ll])
self["mouse-dragging"]=True
self["--slide-gap"]="30px"
self["pagination"]=True
self["navigation"]=True

if isAllRealTags:
for i in ll:
self <= Tag.sl_carousel_item() <= i
self.js=""
else:
for idx,i in enumerate(ll):
self <= Tag.sl_carousel_item( ui.Spinner(), create=i)
self._activate(default)
self.js = """self.addEventListener('sl-slide-change', function (e) {self._activate( e.detail.index ) });"""

self.js+="""
if(self.goToSlide)
self.goToSlide(%s);
else
window.customElements.whenDefined('sl-carousel').then( function() {
self.goToSlide(%s);
});
""" % (default,default)

@expose
def _activate(self,idx):
if self.childs[idx].create:
self.childs[idx].clear( self.childs[idx].create() )
self.childs[idx].create=None



class App(Tag.div):
def init(self):

class Item(Tag.img):
def init(self,i):
self["src"]=f"https://loremflickr.com/400/400/colors?random={i}"

self<= Tag.h3("""A swipper (using shoelace)""")
self<= Tag.p(DOC)

self<= Tag.b("A static use:")
self<= SLSwiper([Item(i) for i in range(50)],_style="height:300px")

self<= Tag.b("A dynamic use (tags created on-demand):")
self<= SLSwiper([lambda i=i: Item(i) for i in range(50)],_style="height:300px")


if __name__ == "__main__":
Runner(App).run()
21 changes: 1 addition & 20 deletions manual_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,24 +265,6 @@ def init(self,x):

#=====================================================================

class TestSwiper(Tag.div):
def init(self,root):
self.output=root.output

class Item(Tag.img):
def init(self,i):
self["src"]=f"https://loremflickr.com/400/400/colors?random={i}"
self["style"]="width:100px;height:100px"
self["onclick"] = self.cc

def cc(self,ev):
print(ev)

self<= ui.Swiper([Item(i) for i in range(50)])
self<= ui.Swiper([lambda i=i: Item(i) for i in range(50)])





class TestView(Tag.div):
Expand All @@ -305,7 +287,7 @@ class App(ui.App):
hr {padding:0px !important;margin:4px !important;}
"""

imports=ui.FULL
imports=ui.ALL
def init(self):
self["class"]="content" # for bulma

Expand Down Expand Up @@ -333,7 +315,6 @@ def setter(o,testobject):
menu <= Tag.my("others",_onclick=lambda ev: setter(ev.target,TestOthers(self)) )
menu <= Tag.my("Sortable",_onclick=lambda ev: setter(ev.target,TestSortable(self)) )
menu <= Tag.my("VScroll",_onclick=lambda ev: setter(ev.target,TestVscroll(self)) )
menu <= Tag.my("Swiper",_onclick=lambda ev: setter(ev.target,TestSwiper(self)) )
menu <= Tag.my("View",_onclick=lambda ev: setter(ev.target,TestView(self)) )
self <= menu
self <= Tag.hr()
Expand Down

0 comments on commit f6ee62d

Please sign in to comment.