-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
276 lines (240 loc) · 8.75 KB
/
functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#import kivy
from kivy.app import App
from functools import partial
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.button import ButtonBehavior
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.gridlayout import GridLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.textinput import TextInput
from kivy.uix.image import AsyncImage
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window
from kivy.base import runTouchApp
from kivy.clock import Clock
from kivy.properties import StringProperty
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
import time
from kivy.clock import Clock
from kivy.uix.screenmanager import FallOutTransition
from kivy.uix.screenmanager import SlideTransition
import kivy.utils
import json
import random
from datetime import datetime
from kivy.graphics import BorderImage
from kivy.lang import Builder
import _markupbase
import unicodedata
from kivy.metrics import dp, sp
#import emoji
import access_my_info
def change_time(date):
date_post = int(date)
dt_obj = datetime.fromtimestamp(date_post).strftime('%d-%m-%y')
return dt_obj
def hex_color(hex_num):
if hex_num == "0":
col = '#000000'
if hex_num == "1":
col = '#7e7e7e'
if hex_num == "2":
col = '#bebebe'
if hex_num == "3":
col = '#ffffff'
if hex_num == "4":
col = '#7e0000'
if hex_num == "5":
col = '#fe0000'
if hex_num == "6":
col = '#047e00'
if hex_num == "7":
col = '#06ff04'
if hex_num == "8":
col = '#7e7e00'
if hex_num == "9":
col = '#ffff04'
if hex_num == "A":
col = '#00007e'
if hex_num == "B":
col = '#0000ff'
if hex_num == "C":
col = '#7e007e'
if hex_num == "D":
col = '#fe00ff'
if hex_num == "E":
col = '#047e7e'
if hex_num == "F":
col = '#06ffff'
return col
class MyButton(Button):
def __init__(self, screen, order_number, background, user, like, date, content, **kwargs):
super(MyButton, self).__init__(**kwargs)
self.markup = True
self.background_normal = get_post_image(background, like)
self.screen = screen
self.order_number = order_number
self.background = background
self.text = f"[size={int(Window.size[0]/25)}]" + str(change_time(date)) + "[/size] " + "\n \n \n" + f"[size={int(Window.size[0]/20)}]" + adapt_text_to_window(content, int(Window.size[0]/20), Window.size[0]) + "[/size]" + " \n \n " + f" [b][size={int(Window.size[0]/20)}]- " + user +"[/b][/size]"
self.color = (0, 0, 0, 1)
#self.font_size = 20
self.shorten = True
#self.split_str = True
self.halign = 'center'
self.size_hint_y = None
self.height = Window.size[1]- Window.size[0] * (1 / 5 + 1 / 5.08)
self.orientation = "vertical"
self.user_name = user
self.last_clicked = 1
def on_touch_up(self, touch):
if self.collide_point(touch.x, touch.y):
print(6)
screen = self.screen
screen.release_post(self)
def on_touch_down(self, touch):
if self.collide_point(touch.x, touch.y):
screen = self.screen
if touch.is_double_tap:
screen = self.screen
print(1)
screen.second_post_press(self)
#screen variable of clicks
#screen.time_pressed *= -1
elif touch.is_triple_tap:
screen = self.screen
print(2)
screen.third_post_press(self)
#screen variable of clicks
#screen.time_pressed *= -1
else:
print(8)
screen = self.screen
screen.first_post_press(self)
#partial(screen.name_press, self)
(print(2))
#screen.name_press(self.order_number, self.background, self)
def build_image(screen, user_image, order_number, width):
image_grid = GridLayout(cols = 8, size_hint_x = None)
image_grid.width = width
for x in range (64):
color_bit = Button(background_normal = '', background_color = kivy.utils.get_color_from_hex(hex_color(user_image[x])), on_release = partial(screen.image_press, order_number))
image_grid.add_widget(color_bit)
return image_grid
def filter_chars(text:str):
invalid_chars = ["\\", "\'", "\"", "\n", "\t", "\r", "\0", "%", "\b", ";", "=", "\u259e"]
for char in invalid_chars:
if char in text:
text = text.split(char)
text = "".join(text)
return text
def get_post_image(num, like):
num = int(num)
like = int(like)
if like == 0:
if num == 1:
return "./images/paper_yellow.png"
elif num == 2:
return "./images/paper_green.png"
elif num == 3:
return "./images/paper_purple.png"
elif num == 4:
return "./images/paper_pink.png"
elif num == 5:
return "./images/paper_blue.png"
elif like == 1:
if num == 1:
return "./images/paper_yellow_heart.png"
elif num == 2:
return "./images/paper_green_heart.png"
elif num == 3:
return "./images/paper_purple_heart.png"
elif num == 4:
return "./images/paper_pink_heart.png"
elif num == 5:
return "./images/paper_blue_heart.png"
elif like == -1:
if num == 1:
return "./images/paper_yellow_noheart.png"
elif num == 2:
return "./images/paper_green_noheart.png"
elif num == 3:
return "./images/paper_purple_noheart.png"
elif num == 4:
return "./images/paper_pink_noheart.png"
elif num == 5:
return "./images/paper_blue_noheart.png"
#def crear botó
def make_post_btn(screen, user_name, text_content, date, like_self, order_number, background):
#post = BoxLayout(size_hint_y = None, height = Window.size[1] * 0.9 - Window.size[0] / 5, orientation = "vertical")
main_btn = MyButton(screen=screen, order_number= order_number, background=background, user = user_name, like = like_self, date=date, content = text_content)
#post.add_widget(main_btn)
#text = str(change_time(date)) + " " + "\n" + adapt_text_to_window(text_content, 30, Window.size[0]) + "\n" + " - " + user_name
#main_btn.text = text
return main_btn
def order_posts_by_timestamp(posts_to_order):
length = len(posts_to_order)
how_big_list = []
final_list = []
for a in range (length):
how_big_list.append(0)
for b in range (length):
#if posts_to_order[a]["time_stamp"] > posts_to_order[b]["time_stamp"]:
# how_big_list[a][1] = how_big_list[a][1] + 1
print(posts_to_order)
print(a, b, posts_to_order[a])
if posts_to_order[a]["time_posted"] > posts_to_order[b]["time_posted"]:
how_big_list[a] = how_big_list[a] + 1
for c in range (length):
for d in range (length):
if how_big_list[c] == d:
final_list.append(posts_to_order[c])
return final_list
def check_new_chat_alarm():
pass
def change_my_description(description):
access_my_info.change_my_description(description)
#enviar a conn
def change_my_profile_image(color_string):
access_my_info.change_my_image(color_string)
#enviar a conn
def adapt_text_to_server(text:str):
text = text.split("\n")
text = " ".join(text)
return text
def adapt_text_to_window(text:str, text_size, window_size):
dpi = Window.dpi
print("dpi_ ", dpi)
print("txt_size_ ", text_size)
print("wind_size_ ", window_size)
text_to_cut_lenght = len(text)
letters_per_line = int(window_size / text_size)
jump_done = 0
final_text = []
words = text.split(" ")
i = 0
while i < len(words):
if len(words[i]) >= letters_per_line:
final_text.append(words[i])
i += 1
else:
working_words = words[i]
j = 1
while not len(working_words) >= letters_per_line:
try:
working_words += " " + words[i+j]
except IndexError:
final_text.append(working_words)
i = len(words)
break
j += 1
else:
final_text.append(working_words)
i += j
print("f_t", final_text)
final_text = "\n".join(final_text)
print("f_t", final_text)
return final_text