Skip to content

Commit 72decb3

Browse files
authored
Merge pull request #86 from Tkd-Alex/2.0/mainscreen
2.0/mainscreen: left panel & nodes list
2 parents 80a3a40 + a097e13 commit 72decb3

File tree

3 files changed

+580
-0
lines changed

3 files changed

+580
-0
lines changed

tests/v2/main_screen.py

Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
from kivy.lang import Builder
2+
from kivymd.app import MDApp
3+
from kivy.core.window import Window
4+
from kivy.utils import get_color_from_hex
5+
from kivymd.uix.boxlayout import MDBoxLayout
6+
from kivy.uix.screenmanager import ScreenManager, Screen
7+
8+
9+
from kivy.lang import Builder
10+
from kivy.metrics import dp
11+
12+
from kivymd.uix.list import ImageLeftWidget
13+
14+
from kivymd.uix.datatables import MDDataTable
15+
16+
# meil uix from tests
17+
from uix.expansionpanel import MDExpansionPanelRoundIcon, MDExpansionPanelTwoLineSmall
18+
19+
KV = """
20+
#:import get_color_from_hex kivy.utils.get_color_from_hex
21+
22+
WindowManager:
23+
24+
<Content>
25+
adaptive_height: True
26+
orientation: 'vertical'
27+
28+
OneLineListItem:
29+
text: "Node1"
30+
text_color: "white"
31+
theme_text_color: "Custom"
32+
font_style: "Overline"
33+
bg_color: "black"
34+
35+
OneLineListItem:
36+
text: "Node 2"
37+
text_color: "white"
38+
theme_text_color: "Custom"
39+
font_style: "Overline"
40+
bg_color: "black"
41+
42+
OneLineListItem:
43+
text: "Node 3"
44+
text_color: "white"
45+
theme_text_color: "Custom"
46+
font_style: "Overline"
47+
bg_color: "black"
48+
49+
<MainScreen>:
50+
name: "main"
51+
MDGridLayout:
52+
md_bg_color: get_color_from_hex("#121212")
53+
rows: 2
54+
55+
MDBoxLayout:
56+
md_bg_color: get_color_from_hex("#212221")
57+
size_hint_y: None
58+
height: 50
59+
60+
MDLabel:
61+
padding: 10
62+
text: "Meile"
63+
font_style: "H4"
64+
text_color: "white"
65+
theme_text_color: "Custom"
66+
67+
MDGridLayout:
68+
cols: 2
69+
md_bg_color: get_color_from_hex("#212221")
70+
71+
MDGridLayout:
72+
rows: 4
73+
padding: 10
74+
size_hint_x: None
75+
width: 250
76+
md_bg_color: get_color_from_hex("#060606")
77+
align: "center"
78+
79+
MDRectangleFlatIconButton:
80+
size_hint_y: None
81+
82+
text: "Connect"
83+
text_color: "black"
84+
icon: "lightning-bolt"
85+
icon_color: "black"
86+
md_bg_color: get_color_from_hex("#FCB70C")
87+
line_color: 0, 0, 0, 0
88+
font_size: "16sp"
89+
size_hint: 1, 0
90+
91+
MDTextField:
92+
icon_left: "magnify"
93+
line_color_normal: get_color_from_hex("#FCB70C")
94+
line_color_focus: get_color_from_hex("#FCB70C")
95+
icon_left_color_normal: get_color_from_hex("#FCB70C")
96+
icon_left_color_focus: get_color_from_hex("#FCB70C")
97+
text_color_normal: get_color_from_hex("#FCB70C")
98+
text_color_focus: get_color_from_hex("#FCB70C")
99+
100+
MDScrollView:
101+
MDList:
102+
id: countries_list
103+
spacing: 3
104+
padding: 10
105+
106+
MDBoxLayout:
107+
orientation: 'horizontal'
108+
# padding: [20, 0, 0, 0]
109+
size_hint_y: None
110+
height: 50
111+
spacing: 10
112+
113+
canvas:
114+
# draw a background of red. This will be the border
115+
Color:
116+
rgba: get_color_from_hex("#453103")
117+
RoundedRectangle:
118+
pos: self.pos
119+
size: self.size
120+
121+
# draw over the above except for 1 pixels around edges, leaving the orange border showing
122+
Color:
123+
rgba: get_color_from_hex("#212221")
124+
RoundedRectangle:
125+
pos: self.x+1, self.y+1
126+
size: self.width-2, self.height-2
127+
128+
MDIconButton:
129+
icon: "wallet-outline"
130+
theme_text_color: "Custom"
131+
text_color: "white"
132+
133+
MDIconButton:
134+
icon: "book-open-outline"
135+
theme_text_color: "Custom"
136+
text_color: "white"
137+
138+
MDIconButton:
139+
icon: "cog-outline"
140+
theme_text_color: "Custom"
141+
text_color: "white"
142+
143+
MDIconButton:
144+
icon: "help-circle-outline"
145+
theme_text_color: "Custom"
146+
text_color: "white"
147+
148+
AnchorLayout:
149+
orientation: "horizontal"
150+
md_bg_color: get_color_from_hex("#131313")
151+
id: servers_datatable
152+
153+
"""
154+
155+
156+
class WindowManager(ScreenManager):
157+
pass
158+
159+
160+
class Content(MDBoxLayout):
161+
pass
162+
163+
164+
class MainScreen(Screen):
165+
def __init__(self, **kwargs):
166+
super().__init__()
167+
self.build()
168+
169+
def build(self):
170+
import random, string
171+
172+
countries = [
173+
"France",
174+
"Italy",
175+
"Brasil",
176+
"Egypt",
177+
"Belgium",
178+
"Deutschland",
179+
"Canada",
180+
]
181+
for _ in range(0, 10):
182+
country = random.choice(countries)
183+
184+
# item = TwoLineAvatarListItem(
185+
# radius = [10, 10, 10, 10],
186+
# bg_color = get_color_from_hex("#212221"),
187+
# text = country,
188+
# text_color = "white",
189+
# theme_text_color = "Custom",
190+
# font_style = "Subtitle1",
191+
# secondary_text = f"{random.randint(1, 100)} servers",
192+
# secondary_text_color = "white",
193+
# secondary_theme_text_color = "Custom",
194+
# secondary_font_style = "Caption",
195+
# )
196+
# item.add_widget(ImageLeftWidget(source=f"../../src/imgs/{country[:2].lower()}.png"))
197+
198+
item = MDExpansionPanelRoundIcon(
199+
icon=f"../../src/imgs/{country[:2].lower()}.png",
200+
icon_size=(25, 25),
201+
content=Content(),
202+
panel_cls=MDExpansionPanelTwoLineSmall(
203+
radius=[10, 10, 10, 10],
204+
bg_color=get_color_from_hex("#212221"),
205+
text=country,
206+
text_color="white",
207+
theme_text_color="Custom",
208+
font_style="Subtitle1",
209+
secondary_text=f"{random.randint(1, 100)} servers",
210+
secondary_text_color="white",
211+
secondary_theme_text_color="Custom",
212+
secondary_font_style="Caption",
213+
),
214+
)
215+
self.ids.countries_list.add_widget(item)
216+
217+
218+
self.data_tables = MDDataTable(
219+
use_pagination=True,
220+
check=False,
221+
column_data=[
222+
("Moniker", dp(45)),
223+
("Location", dp(20)),
224+
("Speed", dp(50)),
225+
("Status", dp(20)),
226+
("Price", dp(40)),
227+
("Protocol", dp(20)),
228+
("Type", dp(20)),
229+
],
230+
sorted_on="Moniker",
231+
sorted_order="ASC",
232+
elevation=2,
233+
rows_num=10
234+
)
235+
236+
row_data = []
237+
for _ in range(0, 150):
238+
upload = random.uniform(100, 900)
239+
download = random.uniform(100, 900)
240+
bandwith = "speedometer-medium"
241+
if upload + download > 1200:
242+
bandwith = "speedometer"
243+
elif upload + download < 400:
244+
bandwith = "speedometer-slow"
245+
246+
healthcheck = random.choice([True, False])
247+
248+
row_data.append(
249+
(
250+
''.join(random.choices(string.printable[:-6], k=random.randint(5, 15))), # Moniker
251+
random.choice(countries),
252+
(bandwith, [1, 1, 1, 1] ,f"[size=12][color=#00FF00]up[/color] {round(upload, 2)}mb/s[color=#f44336]down[/color] {round(download, 2)}mb/s[/size]"),
253+
("shield-plus", [39 / 256, 174 / 256, 96 / 256, 1], "Health") if healthcheck is True else ("emoticon-sick", [1, 0, 0, 1], "Sick"),
254+
f"[size=12]{random.randint(1, 100)}dvpn, {random.randint(1, 100)}atom, {random.randint(1, 100)}osmo, {random.randint(1, 100)}srct, {random.randint(1, 100)}dec[/size]",
255+
random.choice(["Wireguard", "V2RAY"]),
256+
random.choice(["Residential", "Datacenter", "Unknown"])
257+
)
258+
)
259+
260+
self.data_tables.row_data = row_data
261+
262+
self.data_tables.bind(on_row_press=self.on_row_press)
263+
self.ids.servers_datatable.add_widget(self.data_tables)
264+
265+
def on_row_press(self, instance_table, instance_row):
266+
'''Called when a table row is clicked.'''
267+
268+
print(instance_table, instance_row)
269+
270+
def on_check_press(self, instance_table, current_row):
271+
'''Called when the check box in the table row is checked.'''
272+
273+
print(instance_table, current_row)
274+
275+
# Sorting Methods:
276+
# since the https://github.com/kivymd/KivyMD/pull/914 request, the
277+
# sorting method requires you to sort out the indexes of each data value
278+
# for the support of selections.
279+
#
280+
# The most common method to do this is with the use of the builtin function
281+
# zip and enumerate, see the example below for more info.
282+
#
283+
# The result given by these funcitons must be a list in the format of
284+
# [Indexes, Sorted_Row_Data]
285+
286+
def sort_on_signal(self, data):
287+
return zip(*sorted(enumerate(data), key=lambda l: l[1][2]))
288+
289+
def sort_on_schedule(self, data):
290+
return zip(
291+
*sorted(
292+
enumerate(data),
293+
key=lambda l: sum(
294+
[
295+
int(l[1][-2].split(":")[0]) * 60,
296+
int(l[1][-2].split(":")[1]),
297+
]
298+
),
299+
)
300+
)
301+
302+
def sort_on_team(self, data):
303+
return zip(*sorted(enumerate(data), key=lambda l: l[1][-1]))
304+
305+
Builder.load_string(KV)
306+
307+
308+
class Test(MDApp):
309+
title = "MainScreen v2"
310+
311+
def build(self):
312+
Window.size = (1280, 720)
313+
314+
# TODO: review this values
315+
self.theme_cls.theme_style = "Dark" # (?)
316+
self.theme_cls.primary_palette = "Orange" # (?)
317+
318+
manager = WindowManager()
319+
manager.add_widget(MainScreen())
320+
return manager
321+
322+
323+
if __name__ == "__main__":
324+
Test().run()

tests/v2/uix/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)