88
99counter = 0
1010class Text :
11- def __init__ (self , text = "" , color = "#FFFFFF" , size = 12 , positon = [0 ,0 ]):
11+ def __init__ (self , text = "" , color = "#FFFFFF" , font_size = 12 , position = [0 ,0 ]):
1212 self .create ()
1313
14- text = utils . sanitize_string (text )
15- self . text = text
16- client . sio . emit ( 'SetTextText' ,{ self .id : text } )
14+ self . set_text (text )
15+
16+ self .set_font_size ( font_size )
1717
1818 color = utils .sanitize_color (color )
1919 self .color = color
@@ -92,7 +92,7 @@ def set_color(self,text_color):
9292 self .color = text_color
9393 client .sio .emit ('SetTextColors' ,{self .id : text_color })
9494
95- def set_size (self ,text_size ):
95+ def set_font_size (self ,text_size ):
9696 """Set the font size of a set of text objects
9797
9898 Parameters
@@ -129,3 +129,95 @@ def set_position(self,text_pos):
129129 position = utils .sanitize_list (position )
130130 self .position = position
131131 client .sio .emit ('SetTextPositions' ,{self .id : position })
132+
133+
134+ def create (n ):
135+ """Create n text objects with default parameters
136+
137+ Parameters
138+ ----------
139+ n : int
140+ number of text objects
141+ """
142+ text_list = []
143+ for i in range (n ):
144+ text_list .append (Text ())
145+ return text_list
146+
147+ def set_texts (text_list , str_list ):
148+ """Set the string value of multiple text objects
149+
150+ Parameters
151+ ----------
152+ text_list : list of Text
153+ Text objects
154+ str_list : _type_
155+ _description_
156+ """
157+ text_list = utils .sanitize_list (text_list )
158+ str_list = utils .sanitize_list (str_list , len (text_list ))
159+
160+ text_strs = {}
161+ for i , text in enumerate (text_list ):
162+ text_strs [text .id ] = str_list [i ]
163+
164+ client .sio .emit ('SetTextText' ,text_strs )
165+
166+ def set_positions (text_list , pos_list ):
167+ """Set the positions of multiple text objects
168+
169+ Positions are [0,1] relative to the edges of the screen
170+
171+ Parameters
172+ ----------
173+ text_list : list of Text
174+ Text objects
175+ pos_list : list of float
176+ [0,0] top left [1,1] bottom right
177+ """
178+ text_list = utils .sanitize_list (text_list )
179+ pos_list = utils .sanitize_list (pos_list , len (text_list ))
180+
181+ text_poss = {}
182+ for i , text in enumerate (text_list ):
183+ text_poss [text .id ] = pos_list [i ]
184+
185+ client .sio .emit ('SetTextPositions' ,text_poss )
186+
187+ def set_font_sizes (text_list , font_size_list ):
188+ """_summary_
189+
190+ Parameters
191+ ----------
192+ text_list : list of Text
193+ Text objects
194+ font_size_list : _type_
195+ _description_
196+ """
197+ text_list = utils .sanitize_list (text_list )
198+ font_size_list = utils .sanitize_list (font_size_list , len (text_list ))
199+
200+ text_font_sizes = {}
201+ for i , text in enumerate (text_list ):
202+ text_font_sizes [text .id ] = font_size_list [i ]
203+
204+ client .sio .emit ('SetTextSizes' ,text_font_sizes )
205+
206+ def set_colors (text_list , color_list ):
207+ """_summary_
208+
209+ Parameters
210+ ----------
211+ text_list : list of Text
212+ Text objects
213+ color_list : _type_
214+ _description_
215+ """
216+ text_list = utils .sanitize_list (text_list )
217+ color_list = utils .sanitize_list (color_list , len (text_list ))
218+
219+ text_colors = {}
220+ for i , text in enumerate (text_list ):
221+ text_colors [text .id ] = color_list [i ]
222+
223+ client .sio .emit ('SetTextColors' ,text_colors )
0 commit comments