@@ -52,7 +52,7 @@ def __init__(self, parent) -> None:
5252 lambda value : self .listWidget .verticalScrollBar ().setValue (value )
5353 )
5454 self .back_btn .clicked .connect (self .reset_dir )
55-
55+
5656 self .entry_delegate .item_selected .connect (self ._on_item_selected )
5757
5858 @QtCore .pyqtSlot (ListItem , name = "on-item-selected" )
@@ -69,50 +69,32 @@ def _on_item_selected(self, item: ListItem) -> None:
6969
7070 @QtCore .pyqtSlot (name = "reset-dir" )
7171 def reset_dir (self ) -> None :
72- """Reset current directory"""
7372 self .curr_dir = ""
7473 self .request_dir_info [str ].emit (self .curr_dir )
7574
7675 def showEvent (self , a0 : QtGui .QShowEvent ) -> None :
77- """Re-implemented method, handle widget show event"""
7876 self ._build_file_list ()
7977 return super ().showEvent (a0 )
8078
8179 @QtCore .pyqtSlot (list , name = "on-file-list" )
8280 def on_file_list (self , file_list : list ) -> None :
83- """Handle receiving files list from websocket"""
8481 self .files_data .clear ()
8582 self .file_list = file_list
86- < << << << HEAD
87- < << << << HEAD
88- == == == =
89- # if self.isVisible(): # Only build the list when directories come
83+ # if self.isVisible(): # Only build the list when directories come
9084 # self._build_file_list()
91- >> >> >> > 342 be69 (FilesPage : Refactor almost complete missing passing the directory by itemclick )
92- == == == =
93- if self .isVisible (): # Only build the list when directories come
94- self ._build_file_list ()
95- > >> >> >> 44841 b3 (filesPage .py : refactor concluded , scrollbar bugfix )
9685
9786 @QtCore .pyqtSlot (list , name = "on-dirs" )
9887 def on_directories (self , directories_data : list ) -> None :
99- """Handle receiving available directories from websocket"""
10088 self .directories = directories_data
10189 if self .isVisible ():
10290 self ._build_file_list ()
10391
10492 @QtCore .pyqtSlot (str , name = "on-delete-file" )
105- def on_delete_file (self , filename : str ) -> None :
106- """Handle file deleted"""
107- ...
93+ def on_delete_file (self , filename : str ) -> None : ...
10894
10995 @QtCore .pyqtSlot (dict , name = "on-fileinfo" )
11096 def on_fileinfo (self , filedata : dict ) -> None :
111- < << << << HEAD
112- """Handle receive file information/metadata"""
113- == == == =
11497 """Method called per file to contruct file entry to the list"""
115- >> >> >> > a5ed680 (filesPage .py : code cleanup , small docstring generation and add missing commented lines )
11698 if not filedata or not self .isVisible ():
11799 return
118100 filename = filedata .get ("filename" , "" )
@@ -139,40 +121,23 @@ def on_fileinfo(self, filedata: dict) -> None:
139121 time_str = f"{ hours } h { minutes } m"
140122 else :
141123 time_str = f"{ minutes } m"
142- < << << << HEAD
143-
144124
145- < << << << HEAD
146- list_items = [self .listWidget .item (i ) for i in range (self .listWidget .count ())]
147- if not list_items :
148- return
149- for list_item in list_items :
150- item_widget = self .listWidget .itemWidget (list_item )
151- if item_widget .text () in filename :
152- item_widget .setRightText (f"{ filament_type } - { time_str } " )
153- == == == =
154-
155- == == == =
156-
157- >> >> >> > a5ed680 (filesPage .py : code cleanup , small docstring generation and add missing commented lines )
158125 name = helper_methods .get_file_name (filename )
159126 item = ListItem (
160127 text = name [:- 6 ],
161128 right_text = f"{ filament_type } - { time_str } " ,
162129 right_icon = QtGui .QPixmap (":/arrow_icons/media/btn_icons/right_arrow.svg" ),
163130 left_icon = None ,
164- callback = lambda namelam = filename : self ._fileItemClicked (namelam ),
131+ callback = lambda : self ._fileItemClicked (filename ),
165132 selected = False ,
166133 allow_check = False ,
167134 _lfontsize = 17 ,
168135 _rfontsize = 12 ,
169136 height = 80 ,
170- notificate = False
137+ notificate = False ,
171138 )
172-
173- self .model .add_item (item )
174- > >> >> >> 342 be69 (FilesPage : Refactor almost complete missing passing the directory by itemclick )
175139
140+ self .model .add_item (item )
176141
177142 @QtCore .pyqtSlot (str , name = "file-item-clicked" )
178143 def _fileItemClicked (self , filename : str ) -> None :
@@ -181,45 +146,13 @@ def _fileItemClicked(self, filename: str) -> None:
181146 Args:
182147 filename (str): Clicked item path
183148 """
184- < << << << HEAD
185- if item :
186- for file in self .file_list :
187- path = (
188- file .get ("path" ) if "path" in file .keys () else file .get ("filename" )
189- )
190- if not path :
191- return
192- if item .text in path :
193- file_path = (
194- path if not self .curr_dir else str (self .curr_dir + "/" + path )
195- )
196- self .file_selected .emit (
197- str (file_path .removeprefix ("/" )),
198- == == == =
199149 self .file_selected .emit (
200- str (filename .removeprefix ("/" )),
201- >> >> >> > 44841 b3 (filesPage .py : refactor concluded , scrollbar bugfix )
202- self .files_data .get (
203- filename .removeprefix ("/" )
204- ), # Defaults to Nothing
205- )
206-
207- < << << << HEAD
208- < << << << HEAD
209- @QtCore .pyqtSlot (QtWidgets .QListWidgetItem , str , name = "dir-item-clicked" )
210- def _dirItemClicked (self , item : QtWidgets .QListWidgetItem , directory : str ) -> None :
211- == == == =
212- == == == =
213-
214- >> >> >> > 44841 b3 (filesPage .py : refactor concluded , scrollbar bugfix )
215- def _dirItemClicked (
216- self , directory : str
217- ) -> None :
218- < << << << HEAD
219- > >> >> >> 342 be69 (FilesPage : Refactor almost complete missing passing the directory by itemclick )
220- == == == =
221- """Method that changes the current view in the list """
222- >> >> >> > a5ed680 (filesPage .py : code cleanup , small docstring generation and add missing commented lines )
150+ str (filename .removeprefix ("/" )),
151+ self .files_data .get (filename .removeprefix ("/" )), # Defaults to Nothing
152+ )
153+
154+ def _dirItemClicked (self , directory : str ) -> None :
155+ """Method that changes the current view in the list"""
223156 self .curr_dir = self .curr_dir + directory
224157 self .request_dir_info [str ].emit (self .curr_dir )
225158
@@ -228,10 +161,14 @@ def _build_file_list(self) -> None:
228161 self .listWidget .blockSignals (True )
229162 self .model .clear ()
230163 self .entry_delegate .clear ()
231- if not self .file_list and not self .directories and os .path .islink (self .curr_dir ):
164+ if (
165+ not self .file_list
166+ and not self .directories
167+ and os .path .islink (self .curr_dir )
168+ ):
232169 self ._add_placeholder ()
233170 return
234-
171+
235172 if self .directories or self .curr_dir != "" :
236173 if self .curr_dir != "" and self .curr_dir != "/" :
237174 self ._add_back_folder_entry ()
@@ -242,43 +179,16 @@ def _build_file_list(self) -> None:
242179 sorted_list = sorted (self .file_list , key = lambda x : x ["modified" ], reverse = True )
243180 for item in sorted_list :
244181 self ._add_file_list_item (item )
245-
182+
246183 self ._setup_scrollbar ()
247184 self .listWidget .blockSignals (False )
248185 self .listWidget .repaint ()
249186
250187 def _add_directory_list_item (self , dir_data : dict ) -> None :
251- """Method that adds directories to the list """
188+ """Method that adds directories to the list"""
252189 dir_name = dir_data .get ("dirname" , "" )
253190 if not dir_name :
254191 return
255- < << << << HEAD
256- button = ListCustomButton ()
257- button .setText (str (dir_data .get ("dirname" )))
258- button .setSecondPixmap (QtGui .QPixmap (":/ui/media/btn_icons/folderIcon.svg" ))
259- button .setMinimumSize (600 , 80 )
260- button .setMaximumSize (700 , 80 )
261- button .setLeftFontSize (17 )
262- button .setRightFontSize (12 )
263- list_item = QtWidgets .QListWidgetItem ()
264- list_item .setSizeHint (button .sizeHint ())
265- self .listWidget .addItem (list_item )
266- self .listWidget .setItemWidget (list_item , button )
267- button .clicked .connect (lambda : self ._dirItemClicked (list_item , "/" + dir_name ))
268-
269- def _add_back_folder_entry (self ) -> None :
270- button = ListCustomButton ()
271- button .setText ("Go Back" )
272- button .setSecondPixmap (QtGui .QPixmap (":/ui/media/btn_icons/back_folder.svg" ))
273- button .setMinimumSize (600 , 80 )
274- button .setMaximumSize (700 , 80 )
275- button .setLeftFontSize (17 )
276- button .setRightFontSize (12 )
277- list_item = QtWidgets .QListWidgetItem ()
278- list_item .setSizeHint (button .sizeHint ())
279- self .listWidget .addItem (list_item )
280- self .listWidget .setItemWidget (list_item , button )
281- == == == =
282192 item = ListItem (
283193 text = str (dir_name ),
284194 left_icon = QtGui .QPixmap (":/ui/media/btn_icons/folderIcon.svg" ),
@@ -288,32 +198,28 @@ def _add_back_folder_entry(self) -> None:
288198 allow_check = False ,
289199 _lfontsize = 17 ,
290200 _rfontsize = 12 ,
291- height = 80
201+ height = 80 ,
292202 )
293203 self .model .add_item (item )
294204
295205 def _add_back_folder_entry (self ) -> None :
296- << << << < HEAD
297- > >> >> >> 342 be69 (FilesPage : Refactor almost complete missing passing the directory by itemclick )
298- == == == =
299- """Method to insert in the list the "Go back" item """
300- >> >> >> > a5ed680 (filesPage .py : code cleanup , small docstring generation and add missing commented lines )
206+ """Method to insert in the list the "Go back" item"""
301207 go_back_path = os .path .dirname (self .curr_dir )
302208 if go_back_path == "/" :
303209 go_back_path = ""
304-
210+
305211 item = ListItem (
306212 text = "Go Back" ,
307213 right_text = "" ,
308214 right_icon = None ,
309215 left_icon = QtGui .QPixmap (":/ui/media/btn_icons/back_folder.svg" ),
310- callback = lambda : self ._on_goback_dir (go_back_path ),
216+ callback = lambda : self ._on_goback_dir (go_back_path ),
311217 selected = False ,
312218 allow_check = False ,
313219 _lfontsize = 17 ,
314220 _rfontsize = 12 ,
315221 height = 80 ,
316- notificate = False
222+ notificate = False ,
317223 )
318224 self .model .add_item (item )
319225
@@ -334,77 +240,28 @@ def _add_file_list_item(self, file_data_item) -> None:
334240 if not name .endswith (".gcode" ):
335241 # Only list .gcode files, all else ignore
336242 return
337- < << << << HEAD
338- button = ListCustomButton ()
339- button .setText (name [:- 6 ])
340- button .setPixmap (QtGui .QPixmap (":/arrow_icons/media/btn_icons/right_arrow.svg" ))
341- button .setMinimumSize (600 , 80 )
342- button .setMaximumSize (700 , 80 )
343- button .setLeftFontSize (17 )
344- button .setRightFontSize (12 )
345- list_item = QtWidgets .QListWidgetItem ()
346- list_item .setSizeHint (button .sizeHint ())
347- self .listWidget .addItem (list_item )
348- self .listWidget .setItemWidget (list_item , button )
349- button .clicked .connect (lambda : self ._fileItemClicked (list_item ))
350- == == == =
351- >> >> >> > 342 be69 (FilesPage : Refactor almost complete missing passing the directory by itemclick )
352243 file_path = (
353244 name if not self .curr_dir else str (self .curr_dir + "/" + name )
354245 ).removeprefix ("/" )
355-
246+
356247 self .request_file_metadata .emit (file_path .removeprefix ("/" ))
357248 self .request_file_info .emit (file_path .removeprefix ("/" ))
358249
359250 def _add_placeholder (self ) -> None :
360- < << << << HEAD
361- self .listWidget .setSpacing (- 1 )
362- placeholder_label = QtWidgets .QLabel ("No Files found" )
363- font = QtGui .QFont ()
364- font .setPointSize (25 )
365- placeholder_label .setFont (font )
366- placeholder_label .setStyleSheet ("color: gray;" )
367- placeholder_label .setAlignment (
368- QtCore .Qt .AlignmentFlag .AlignHCenter | QtCore .Qt .AlignmentFlag .AlignVCenter
369- )
370- placeholder_label .setMinimumSize (
371- QtCore .QSize (self .listWidget .width (), self .listWidget .height ())
372- )
373- == == == =
374- >> >> >> > 342 be69 (FilesPage : Refactor almost complete missing passing the directory by itemclick )
375251 self .scrollbar .hide ()
376252 self .listWidget .hide ()
377253 self .label .show ()
378254
379-
380255 def _handle_scrollbar (self , value ):
381256 # Block signals to avoid recursion
382257 self .scrollbar .blockSignals (True )
383258 self .scrollbar .setValue (value )
384259 self .scrollbar .blockSignals (False )
385260
386261 def _setup_scrollbar (self ) -> None :
387- < << << << HEAD
388- < << << << HEAD
389262 self .scrollbar .setMinimum (self .listWidget .verticalScrollBar ().minimum ())
390263 self .scrollbar .setMaximum (self .listWidget .verticalScrollBar ().maximum ())
391264 self .scrollbar .setPageStep (self .listWidget .verticalScrollBar ().pageStep ())
392- == == == =
393- idx = self .model .index (0 , 0 )
394-
395- rect = self .listWidget .rectForIndex (idx )
396- == == == =
397- >> >> >> > e8b88d5 (filesPage .py : remove unused lines of code )
398- self .scrollbar .setMinimum (
399- self .listWidget .verticalScrollBar ().minimum ()
400- )
401- self .scrollbar .setMaximum (
402- self .listWidget .verticalScrollBar ().maximum ()
403- )
404- self .scrollbar .setPageStep (
405- self .listWidget .verticalScrollBar ().pageStep ()
406- )
407- > >> >> >> 44841 b3 (filesPage .py : refactor concluded , scrollbar bugfix )
408265 self .scrollbar .show ()
409266
410267 def _setupUI (self ):
@@ -507,7 +364,7 @@ def _setupUI(self):
507364 QtWidgets .QScroller .scroller (self .listWidget ).setScrollerProperties (
508365 scroller_props
509366 )
510-
367+
511368 font = QtGui .QFont ()
512369 font .setPointSize (25 )
513370 self .label = QtWidgets .QLabel ("No Files found" )
@@ -517,8 +374,7 @@ def _setupUI(self):
517374 QtCore .QSize (self .listWidget .width (), self .listWidget .height ())
518375 )
519376 self .label .setAlignment (
520- QtCore .Qt .AlignmentFlag .AlignHCenter
521- | QtCore .Qt .AlignmentFlag .AlignVCenter
377+ QtCore .Qt .AlignmentFlag .AlignHCenter | QtCore .Qt .AlignmentFlag .AlignVCenter
522378 )
523379
524380 self .fp_content_layout .addWidget (self .listWidget )
@@ -528,5 +384,3 @@ def _setupUI(self):
528384 self .verticalLayout_5 .addLayout (self .fp_content_layout )
529385 self .scrollbar .show ()
530386 self .label .hide ()
531-
532-
0 commit comments