18
18
from .. import common
19
19
from .. import contextmenu
20
20
from .. import images
21
+ from .. import log
21
22
from ..tokens import tokens
22
23
23
24
@@ -49,28 +50,28 @@ class TaskItemViewDelegate(delegate.ItemDelegate):
49
50
50
51
def paint (self , painter , option , index ):
51
52
"""The main paint method.
52
-
53
+
53
54
"""
54
55
args = self .get_paint_arguments (painter , option , index )
55
56
self .paint_background (* args )
56
57
self .paint_name (* args )
57
58
58
59
def get_description_rect (self , * args , ** kwargs ):
59
60
"""Get description rectangle.
60
-
61
+
61
62
"""
62
63
return QtCore .QRect ()
63
64
64
65
def get_text_segments (self , * args , ** kwargs ):
65
66
"""Get text segments.
66
-
67
+
67
68
"""
68
69
return []
69
70
70
71
@delegate .save_painter
71
72
def paint_background (self , * args ):
72
73
"""Paints the background.
73
-
74
+
74
75
"""
75
76
rectangles , painter , option , index , selected , focused , active , archived , \
76
77
favourite , hover , font , metrics , cursor_position = args
@@ -117,7 +118,7 @@ def paint_background(self, *args):
117
118
def paint_name (self , * args ):
118
119
"""Paints the name and the number of files available for the given
119
120
task item.
120
-
121
+
121
122
"""
122
123
rectangles , painter , option , index , selected , focused , active , archived , \
123
124
favourite , hover , font , metrics , cursor_position = args
@@ -163,7 +164,6 @@ def paint_name(self, *args):
163
164
rect = rect .marginsRemoved (QtCore .QMargins (o * 2 , 0 , o , 0 ))
164
165
165
166
text = index .data (QtCore .Qt .DisplayRole )
166
- width = 0
167
167
width = common .draw_aliased_text (
168
168
painter , font , rect , text , QtCore .Qt .AlignVCenter | QtCore .Qt .AlignLeft ,
169
169
color
@@ -235,6 +235,24 @@ def data_type(self):
235
235
"""
236
236
return common .FileItem
237
237
238
+ def item_generator (self , path ):
239
+ try :
240
+ it = os .scandir (path )
241
+ except OSError as e :
242
+ log .error (e )
243
+ return
244
+
245
+ # Get folders from the root of the bookmark item
246
+ for entry in it :
247
+ if self ._interrupt_requested :
248
+ return
249
+ if entry .name .startswith ('.' ):
250
+ continue
251
+ if not entry .is_dir ():
252
+ continue
253
+
254
+ yield entry
255
+
238
256
@common .status_bar_message ('Loading task folders...' )
239
257
@models .initdata
240
258
@common .error
@@ -243,23 +261,29 @@ def init_data(self):
243
261
"""Collects the data needed to populate the task item model.
244
262
245
263
"""
264
+ p = self .source_path ()
265
+ k = self .task ()
266
+ t = self .data_type ()
267
+
268
+ if not p or not all (p ) or not k or t is None :
269
+ return
270
+
271
+ data = common .get_data (p , k , t )
272
+ source = '/' .join (p )
273
+
246
274
flags = (
247
275
QtCore .Qt .ItemIsSelectable |
248
276
QtCore .Qt .ItemIsEnabled
249
277
)
250
- data = self . model_data ()
278
+
251
279
source_path = self .source_path ()
252
280
if not source_path or not all (source_path ):
253
281
return
254
282
_source_path = '/' .join (source_path )
255
283
256
284
config = tokens .get (* source_path [0 :3 ])
257
285
258
- entries = sorted (
259
- ([f for f in os .scandir (_source_path )]), key = lambda x : x .name
260
- )
261
-
262
- for entry in entries :
286
+ for entry in self .item_generator (source ):
263
287
if entry .name .startswith ('.' ):
264
288
continue
265
289
if not entry .is_dir ():
@@ -269,6 +293,7 @@ def init_data(self):
269
293
270
294
idx = len (data )
271
295
description = config .get_description (entry .name )
296
+
272
297
data [idx ] = common .DataDict (
273
298
{
274
299
QtCore .Qt .DisplayRole : entry .name ,
@@ -300,9 +325,9 @@ def init_data(self):
300
325
common .ThumbnailLoaded : True ,
301
326
#
302
327
common .SortByNameRole : entry .name .lower (),
303
- common .SortByLastModifiedRole : 0 ,
304
- common .SortBySizeRole : 0 ,
305
- common .SortByTypeRole : entry .name ,
328
+ common .SortByLastModifiedRole : entry . name . lower () ,
329
+ common .SortBySizeRole : entry . name . lower () ,
330
+ common .SortByTypeRole : entry .name . lower () ,
306
331
#
307
332
common .IdRole : idx ,
308
333
#
@@ -343,43 +368,6 @@ def file_count(self, source):
343
368
break
344
369
return count
345
370
346
- @classmethod
347
- def item_generator (cls , path ):
348
- """Used to iterate over all files in a given folder.
349
-
350
- Yields:
351
- DirEntry: A DirEntry instance.
352
-
353
- """
354
- try :
355
- it = os .scandir (path )
356
- except :
357
- return
358
-
359
- n = 0
360
- while True :
361
- n += 1
362
- if n > 999 :
363
- return
364
-
365
- try :
366
- entry = next (it )
367
-
368
- if entry .name .startswith ('.' ):
369
- continue
370
-
371
- if entry .is_symlink ():
372
- continue
373
-
374
- if not entry .is_dir ():
375
- yield entry
376
- except OSError :
377
- continue
378
- except StopIteration :
379
- return
380
-
381
- yield from cls .item_generator (entry .path )
382
-
383
371
384
372
class TaskItemView (views .ThreadedItemView ):
385
373
"""The view responsible for displaying the available data-keys.
@@ -512,10 +500,10 @@ def eventFilter(self, widget, event):
512
500
513
501
if event .type () == QtCore .QEvent .Paint :
514
502
painter = QtGui .QPainter ()
515
- painter .begin (self )
503
+ painter .begin (widget )
516
504
painter .setPen (QtCore .Qt .NoPen )
517
505
painter .setBrush (common .color (common .color_separator ))
518
- painter .drawRect (self .rect ())
506
+ painter .drawRect (widget .rect ())
519
507
painter .end ()
520
508
return super ().eventFilter (widget , event )
521
509
0 commit comments