3232from kivymd .uix .behaviors .elevation import RectangularElevationBehavior
3333from kivy_garden .mapview import MapMarkerPopup , MapView , MapSource
3434from kivymd .toast import toast
35+ from kivy .uix .carousel import Carousel
36+ from kivymd .uix .boxlayout import MDBoxLayout
3537
3638
3739import requests
@@ -337,6 +339,8 @@ class MainWindow(Screen):
337339 clock = None
338340 PersistentBandwidth = {}
339341 ConnectedDict = {'v2ray_pid' : None , 'result' : False }
342+ NodeWidget = None
343+ Markers = []
340344
341345
342346 def __init__ (self , node_tree , ** kwargs ):
@@ -372,31 +376,33 @@ def build(self, dt):
372376
373377 for name_tab in OurWorld .CONTINENTS :
374378 tab = Tab (tab_label_text = name_tab )
375- self .manager . get_screen ( WindowNames . MAIN_WINDOW ). ids .android_tabs .add_widget (tab )
379+ self .ids .android_tabs .add_widget (tab )
376380
377381 self .get_ip_address (None )
378382
379383 self .on_tab_switch (
380384 None ,
381385 None ,
382386 None ,
383- self .manager . get_screen ( WindowNames . MAIN_WINDOW ). ids .android_tabs .ids .layout .children [- 1 ].text
387+ self .ids .android_tabs .ids .layout .children [- 1 ].text
384388 )
385389
386390
387391 def build_meile_map (self ):
388- if not self .MeileMapBuilt :
392+
393+ if not self .MeileMapBuilt :
389394 self .MeileMap = MapView (lat = 50.6394 , lon = 3.057 , zoom = 2 )
390395 source = MapSource (url = "https://server.arcgisonline.com/arcgis/rest/services/Canvas/World_Dark_Gray_Base/MapServer/tile/{z}/{y}/{x}.png" ,
391- cache_key = "meile-map-canvas-dark-grey-base" ,
396+ cache_key = "meile-map-canvas-dark-grey-base" ,
392397 tile_size = 512 ,
393398 image_ext = "png" ,
394399 attribution = "@ Meile" ,
395400 size_hint = (.7 ,1 ))
396401 #self.MeileMap.map_source = "osm"
397402 self .MeileMap .map_source = source
398-
399- self .ids .country_map .add_widget (self .MeileMap )
403+ self .carousel = Carousel (direction = 'right' )
404+ self .ids .country_map .add_widget (self .carousel )
405+ self .carousel .add_widget (self .MeileMap )
400406 self .AddCountryNodePins (False )
401407 self .MeileMapBuilt = True
402408
@@ -407,23 +413,32 @@ def get_font(self):
407413 def AddCountryNodePins (self , clear ):
408414 Config = MeileGuiConfig ()
409415 try :
416+
417+ if clear :
418+ for m in self .Makers :
419+ self .MeileMap .remove_marker (m )
420+ self .Markers .clear ()
421+
410422 for continent in self .MeileLand .CONTINENTS :
411423 for ncountry in self .NodeTree .NodeTree .children (continent ):
412- loc = self .MeileLand .CountryLatLong [ncountry .tag ]
413- marker = MapMarkerPopup (lat = loc [0 ], lon = loc [1 ], source = Config .resource_path (MeileColors .MAP_MARKER ))
414- marker .add_widget (MDMapCountryButton (text = '%s - %s' % (ncountry .tag , len (self .NodeTree .NodeTree .children (ncountry .tag ))),
415- theme_text_color = "Custom" ,
416- md_bg_color = get_color_from_hex (MeileColors .DIALOG_BG_COLOR ),
417- text_color = (1 ,1 ,1 ,1 ),
418- on_release = partial (self .load_country_nodes , ncountry .tag )
419- ))
420- if not clear :
424+ try :
425+ loc = self .MeileLand .CountryLatLong [ncountry .tag ]
426+ marker = MapMarkerPopup (lat = loc [0 ], lon = loc [1 ], source = Config .resource_path (MeileColors .MAP_MARKER ))
427+ marker .add_widget (MDMapCountryButton (text = '%s - %s' % (ncountry .tag , len (self .NodeTree .NodeTree .children (ncountry .tag ))),
428+ theme_text_color = "Custom" ,
429+ md_bg_color = get_color_from_hex (MeileColors .DIALOG_BG_COLOR ),
430+ text_color = (1 ,1 ,1 ,1 ),
431+ on_release = partial (self .load_country_nodes , ncountry .tag )
432+ ))
433+
434+ self .Markers .append (marker )
421435 self .MeileMap .add_marker (marker )
422- else :
423- self . MeileMap . remove_marker ( marker )
436+ except :
437+ continue
424438 except Exception as e :
425439 print (str (e ))
426440 pass
441+
427442 self .get_continent_coordinates (self .MeileLand .CONTINENTS [0 ])
428443
429444 def set_item (self , text_item ):
@@ -745,8 +760,9 @@ def refresh_nodes_and_subs(self):
745760 def Refresh (self , latency , * kwargs ):
746761 self .remove_loading_widget (None )
747762 self .AddCountryNodePins (True )
763+ yield 0.314
748764 self .add_loading_popup ("Reloading Nodes..." )
749- yield 0.5
765+ yield 0.314
750766 try :
751767 self .NodeTree .NodeTree = None
752768 thread = ThreadWithResult (target = self .NodeTree .get_nodes , args = (latency .return_latency (),))
@@ -764,7 +780,7 @@ def Refresh(self, latency, *kwargs):
764780
765781 @mainthread
766782 def on_tab_switch (self , instance_tabs , instance_tab , instance_tabs_label , tab_text ):
767- self .manager . get_screen ( WindowNames . MAIN_WINDOW ). ids .rv .data = []
783+ self .ids .rv .data = []
768784 if not tab_text :
769785 tab_text = OurWorld .CONTINENTS [0 ]
770786
@@ -848,24 +864,29 @@ def switch_window(self, window):
848864 Meile .app .root .current = window
849865
850866 def switch_to_sub_window (self ):
851- Meile .app .root .add_widget (SubscriptionScreen (name = WindowNames .SUBSCRIPTIONS , node_tree = self .NodeTree ))
852- Meile .app .root .transition = SlideTransition (direction = "left" )
853- Meile .app .root .current = WindowNames .SUBSCRIPTIONS
867+ try :
868+ self .carousel .remove_widget (self .NodeWidget )
869+ except Exception as e :
870+ print (str (e ))
871+ self .NodeWidget = SubscriptionScreen (name = WindowNames .SUBSCRIPTIONS , node_tree = self .NodeTree )
872+ self .carousel .add_widget (self .NodeWidget )
873+ self .carousel .load_slide (self .NodeWidget )
854874
855875 def load_country_nodes (self , country , * kwargs ):
876+ mw = Meile .app .root .get_screen (WindowNames .MAIN_WINDOW )
856877 NodeTree = NodeTreeData (Meile .app .root .get_screen (WindowNames .MAIN_WINDOW ).NodeTree .NodeTree )
857878 try :
858- Meile . app . root . remove_widget (Meile . app . root . get_screen ( WindowNames . NODES ) )
879+ mw . carousel . remove_widget (self . NodeWidget )
859880 except Exception as e :
860881 print (str (e ))
861882 pass
862- Meile . app . root . add_widget ( NodeScreen ( name = "nodes" ,
863- node_tree = NodeTree ,
864- country = country ,
865- sort = Meile . app . root . get_screen ( WindowNames . MAIN_WINDOW ). Sort ))
866-
867- Meile . app . root . transition = SlideTransition ( direction = "up" )
868- Meile . app . root . current = WindowNames . NODES
883+
884+ self . NodeWidget = NodeScreen ( name = "nodes" ,
885+ node_tree = NodeTree ,
886+ country = country ,
887+ sort = self . Sort )
888+ self . carousel . add_widget ( self . NodeWidget )
889+ self . carousel . load_slide ( self . NodeWidget )
869890
870891
871892class WalletScreen (Screen ):
@@ -1038,7 +1059,7 @@ def set_previous_screen(self):
10381059 Meile .app .root .current = WindowNames .MAIN_WINDOW
10391060
10401061
1041- class SubscriptionScreen (Screen ):
1062+ class SubscriptionScreen (MDBoxLayout ):
10421063 SubResult = None
10431064
10441065 def __init__ (self , node_tree , ** kwargs ):
@@ -1057,7 +1078,7 @@ def __init__(self, node_tree, **kwargs):
10571078 return
10581079
10591080 def GetSubscriptions (self ):
1060- mw = self . manager .get_screen (WindowNames .MAIN_WINDOW )
1081+ mw = Meile . app . root .get_screen (WindowNames .MAIN_WINDOW )
10611082 try :
10621083 thread = ThreadWithResult (target = self .NodeTree .get_subscriptions , args = (self .address ,))
10631084 thread .start ()
@@ -1071,7 +1092,7 @@ def GetSubscriptions(self):
10711092 def subs_callback (self , dt ):
10721093 floc = "../imgs/"
10731094 yield 0.314
1074- mw = self . manager .get_screen (WindowNames .MAIN_WINDOW )
1095+ mw = Meile . app . root .get_screen (WindowNames .MAIN_WINDOW )
10751096
10761097 if not mw .SubResult :
10771098 self .GetSubscriptions ()
@@ -1201,12 +1222,15 @@ def sub_address_error(self):
12011222 self .dialog .open ()
12021223
12031224 def set_previous_screen (self ):
1204- Meile .app .root .remove_widget (self )
1205- Meile .app .root .transistion = SlideTransition (direction = "right" )
1206- Meile .app .root .current = WindowNames .MAIN_WINDOW
1207-
1208-
1209- class NodeScreen (Screen ):
1225+ mw = Meile .app .root .get_screen (WindowNames .MAIN_WINDOW )
1226+ mw .carousel .remove_widget (mw .NodeWidget )
1227+ mw .carousel .load_previous ()
1228+
1229+ '''
1230+ Main widget of country cards in carousel.
1231+ Contains: widgets.RecyclerViewRow, RecyclerViewCountryRow
1232+ '''
1233+ class NodeScreen (MDBoxLayout ):
12101234 NodeTree = None
12111235 Country = None
12121236 MeileConfig = None
@@ -1428,42 +1452,41 @@ def add_rv_data(self, node, flagloc):
14281452 )
14291453
14301454 def set_previous_screen (self ):
1455+ mw = Meile .app .root .get_screen (WindowNames .MAIN_WINDOW )
1456+ mw .carousel .remove_widget (mw .NodeWidget )
1457+ mw .carousel .load_previous ()
14311458
1432- Meile .app .root .remove_widget (self )
1433- Meile .app .root .transistion = SlideTransition (direction = "down" )
1434- Meile .app .root .current = WindowNames .MAIN_WINDOW
1435-
1436-
1459+ '''
1460+ This is the card class of the country cards on the left panel
1461+ '''
14371462class RecycleViewCountryRow (MDCard ,RectangularElevationBehavior ,ThemableBehavior , HoverBehavior ):
14381463 text = StringProperty ()
14391464
14401465 def on_enter (self , * args ):
1441- self .md_bg_color = get_color_from_hex ("#200c3a" )
1466+ self .md_bg_color = get_color_from_hex (MeileColors . ROW_HOVER )
14421467 Window .set_system_cursor ('hand' )
14431468
14441469 def on_leave (self , * args ):
14451470 self .md_bg_color = get_color_from_hex (MeileColors .DIALOG_BG_COLOR )
14461471 Window .set_system_cursor ('arrow' )
14471472
1448- def show_country_nodes (self , country ):
1449- print (country )
1450- self .switch_window (country )
1451-
14521473 def switch_window (self , country ):
1474+ print (country )
14531475 NodeTree = NodeTreeData (Meile .app .root .get_screen (WindowNames .MAIN_WINDOW ).NodeTree .NodeTree )
1476+ mw = Meile .app .root .get_screen (WindowNames .MAIN_WINDOW )
1477+
14541478 try :
1455- Meile . app . root . remove_widget (Meile . app . root . get_screen ( WindowNames . NODES ) )
1479+ mw . carousel . remove_widget (mw . NodeWidget )
14561480 except Exception as e :
14571481 print (str (e ))
14581482 pass
1459- Meile .app .root .add_widget (NodeScreen (name = "nodes" ,
1460- node_tree = NodeTree ,
1461- country = country ,
1462- sort = Meile .app .root .get_screen (WindowNames .MAIN_WINDOW ).Sort ))
1463-
1464- Meile .app .root .transition = SlideTransition (direction = "up" )
1465- Meile .app .root .current = WindowNames .NODES
1466-
1483+
1484+ mw .NodeWidget = NodeScreen (name = "nodes" ,
1485+ node_tree = NodeTree ,
1486+ country = country ,
1487+ sort = mw .Sort )
1488+ mw .carousel .add_widget (mw .NodeWidget )
1489+ mw .carousel .load_next ()
14671490
14681491class HelpScreen (Screen ):
14691492
0 commit comments