@@ -238,6 +238,32 @@ def keypress(char):
238
238
239
239
240
240
class SimpleCursesString (SimpleCursesWidget ):
241
+ ''' A class to provide a String value
242
+
243
+ Parameters
244
+ ==========
245
+ Y, X, window
246
+ Coordinates and parent window
247
+ caption
248
+ preffix string
249
+ string
250
+ the string to display (variable)
251
+ color
252
+ text color
253
+ color_focused
254
+ counter color when enabled and focused
255
+ color_not_focused
256
+ counter color when enabled but not focused
257
+ color_disabled
258
+ counter color when disabled
259
+ full_slection
260
+ if not None, it should be a tuple:
261
+ (go left from self._X, numbder of chars to print)
262
+ draw selection cursor as a full line
263
+ '''
264
+
265
+
266
+ _max_string = 0
241
267
242
268
def __init__ (
243
269
self ,
@@ -248,19 +274,23 @@ def __init__(
248
274
color_not_focused ,
249
275
color_disabled ,
250
276
right_arrow_selects = True ,
251
- callback_function_on_activation = None
277
+ callback_function_on_activation = None ,
278
+ full_selection = None
252
279
):
253
280
self ._Y = Y
254
281
self ._X = X
255
282
self ._win = self ._parent = parent
256
283
self ._string = string
284
+ if cjklen (self ._string ) > self ._max_string :
285
+ self ._max_string = cjklen (self ._string )
257
286
self ._caption = caption
258
287
self ._color = color
259
288
self ._color_focused = color_focused
260
289
self ._color_not_focused = color_not_focused
261
290
self ._color_disabled = color_disabled
262
291
self ._right_arrow_selects = right_arrow_selects
263
292
self ._callback_function_on_activation = callback_function_on_activation
293
+ self ._full_selection = full_selection
264
294
265
295
@property
266
296
def caption (self ):
@@ -277,6 +307,8 @@ def string(self):
277
307
@string .setter
278
308
def string (self , value ):
279
309
self ._string = value
310
+ if cjklen (self ._string ) > self ._max_string :
311
+ self ._max_string = cjklen (self ._string )
280
312
281
313
@property
282
314
def string_len (self ):
@@ -315,11 +347,36 @@ def keypress(self, char):
315
347
self ._callback_function_on_activation ()
316
348
return ret
317
349
350
+ def _print_full_line (self , col ):
351
+ tmp = self ._full_selection [0 ] * ' ' + self .caption + self ._string
352
+ self ._win .addstr (
353
+ self ._Y ,
354
+ self ._X - self ._full_selection [0 ],
355
+ tmp .ljust (self ._full_selection [1 ]),
356
+ col
357
+ )
318
358
def show (self , parent = None ):
319
359
if parent :
320
360
self ._win = self_parent = parent
321
- self ._win .addstr (self ._Y , self ._X , self ._caption , self ._color )
322
- self ._win .addstr (self ._string , self ._color_not_focused )
361
+ if self ._full_selection and self ._enabled and self ._focused :
362
+ self ._print_full_line (self ._color_focused )
363
+ else :
364
+ if self ._full_selection :
365
+ self ._win .addstr (
366
+ self ._Y ,
367
+ self ._X - self ._full_selection [0 ],
368
+ (self ._full_selection [1 ] ) * ' ' ,
369
+ self ._color
370
+ )
371
+ if self ._enabled :
372
+ self ._win .addstr (self ._Y , self ._X , self ._caption , self ._color )
373
+ if self ._focused :
374
+ self ._win .addstr (self ._string .ljust (self ._max_string ), self ._color_focused )
375
+ else :
376
+ self ._win .addstr (self ._string .ljust (self ._max_string ), self ._color_not_focused )
377
+ else :
378
+ self ._win .addstr (self ._Y , self ._X , self ._caption , self ._color_disabled )
379
+ self ._win .addstr (self ._string .ljust (self ._max_string ), self ._color_disabled )
323
380
324
381
class SimpleCursesCounter (SimpleCursesWidget ):
325
382
''' A class to provide a counter
@@ -344,6 +401,10 @@ class SimpleCursesCounter(SimpleCursesWidget):
344
401
counter color when enabled but not focused
345
402
color_disabled
346
403
counter color when disabled
404
+ full_slection
405
+ if not None, it should be a tuple:
406
+ (go left from self._X, numbder of chars to print)
407
+ draw selection cursor as a full line
347
408
'''
348
409
def __init__ (
349
410
self , Y , X , window ,
@@ -352,7 +413,8 @@ def __init__(
352
413
color_disabled ,
353
414
minimum = 0 , maximum = 100 ,
354
415
step = 1 , big_step = 5 , value = 1 ,
355
- number_length = 3 , string = '{0}'
416
+ number_length = 3 , string = '{0}' ,
417
+ full_selection = None
356
418
):
357
419
self ._Y = Y
358
420
self ._X = X
@@ -375,6 +437,7 @@ def __init__(
375
437
self ._color_focused = color_focused
376
438
self ._color_not_focused = color_not_focused
377
439
self ._color_disabled = color_disabled
440
+ self ._full_selection = full_selection
378
441
379
442
def refresh (self ):
380
443
self .show (self ._win )
@@ -457,6 +520,15 @@ def move(self, newY=-1, newX=-1, parent=None):
457
520
if parent :
458
521
self ._win = self ._parent = parent
459
522
523
+ def _print_full_line (self , col ):
524
+ tmp = self ._full_selection [0 ] * ' ' + self ._prefix + str (self ._value ).rjust (self ._len ) + self ._suffix
525
+ self ._win .addstr (
526
+ self ._Y ,
527
+ self ._X - self ._full_selection [0 ],
528
+ tmp .ljust (self ._full_selection [1 ]),
529
+ col
530
+ )
531
+
460
532
def show (self , window , opening = False ):
461
533
if window :
462
534
self ._win = self ._parent = window
@@ -467,14 +539,24 @@ def show(self, window, opening=False):
467
539
col = self ._color_not_focused
468
540
else :
469
541
col = self ._color_disabled
470
- self ._win .move (self ._Y , self ._X )
471
- if self ._prefix :
472
- self ._win .addstr (self ._prefix , self ._color )
473
- self ._win .addstr (self ._number .format (str (self ._value ).rjust (self ._len )), col )
474
- if self ._suffix :
475
- self ._win .addstr (self ._suffix , self ._color )
476
- ''' overwrite last self._len characters '''
477
- self ._win .addstr (' ' * self ._len , self ._color )
542
+ if self ._full_selection and self ._enabled and self ._focused :
543
+ self ._print_full_line (col )
544
+ else :
545
+ if self ._full_selection :
546
+ self ._win .addstr (
547
+ self ._Y ,
548
+ self ._X - self ._full_selection [0 ],
549
+ (self ._full_selection [1 ] ) * ' ' ,
550
+ self ._color
551
+ )
552
+ self ._win .move (self ._Y , self ._X )
553
+ if self ._prefix :
554
+ self ._win .addstr (self ._prefix , self ._color )
555
+ self ._win .addstr (self ._number .format (str (self ._value ).rjust (self ._len )), col )
556
+ if self ._suffix :
557
+ self ._win .addstr (self ._suffix , self ._color )
558
+ ''' overwrite last self._len characters '''
559
+ self ._win .addstr (' ' * self ._len , self ._color )
478
560
self ._showed = True
479
561
480
562
def keypress (self , char ):
@@ -2929,14 +3011,19 @@ class SimpleCursesBoolean(SimpleCursesCounter):
2929
3011
counter color when enabled but not focused
2930
3012
color_disabled
2931
3013
counter color when disabled
3014
+ full_slection
3015
+ if not None, it should be a tuple:
3016
+ (go left from self._X, numbder of chars to print)
3017
+ draw selection cursor as a full line
2932
3018
'''
2933
3019
2934
3020
def __init__ (
2935
3021
self , Y , X , window ,
2936
3022
color , color_focused ,
2937
3023
color_not_focused ,
2938
3024
color_disabled ,
2939
- string = '{0}' , value = False
3025
+ string = '{0}' , value = False ,
3026
+ full_selection = None
2940
3027
):
2941
3028
self ._Y = Y
2942
3029
self ._X = X
@@ -2947,6 +3034,16 @@ def __init__(
2947
3034
self ._color_focused = color_focused
2948
3035
self ._color_not_focused = color_not_focused
2949
3036
self ._color_disabled = color_disabled
3037
+ self ._full_selection = full_selection
3038
+
3039
+ def _print_full_line (self , col ):
3040
+ tmp = self ._full_selection [0 ] * ' ' + self ._prefix + str (self ._value ).rjust (5 ) + self ._suffix
3041
+ self ._win .addstr (
3042
+ self ._Y ,
3043
+ self ._X - self ._full_selection [0 ],
3044
+ tmp .ljust (self ._full_selection [1 ]),
3045
+ col
3046
+ )
2950
3047
2951
3048
def show (self , window = None ):
2952
3049
if window :
@@ -2958,14 +3055,24 @@ def show(self, window=None):
2958
3055
col = self ._color_not_focused
2959
3056
else :
2960
3057
col = self ._color_disabled
2961
- self ._win .move (self ._Y , self ._X )
2962
- if self ._prefix :
2963
- self ._win .addstr ( self ._prefix , self ._color )
2964
- self ._win .addstr (str (self ._value ), col )
2965
- if self ._suffix :
2966
- self ._win .addstr (self ._suffix , self ._color )
2967
- ''' overwrite last self._len characters '''
2968
- self ._win .addstr (' ' * 2 , self ._color )
3058
+ if self ._full_selection and self ._enabled and self ._focused :
3059
+ self ._print_full_line (col )
3060
+ else :
3061
+ if self ._full_selection :
3062
+ self ._win .addstr (
3063
+ self ._Y ,
3064
+ self ._X - self ._full_selection [0 ],
3065
+ (self ._full_selection [1 ] ) * ' ' ,
3066
+ self ._color
3067
+ )
3068
+ self ._win .move (self ._Y , self ._X )
3069
+ if self ._prefix :
3070
+ self ._win .addstr ( self ._prefix , self ._color )
3071
+ self ._win .addstr (str (self ._value ).ljust (5 ), col )
3072
+ if self ._suffix :
3073
+ self ._win .addstr (self ._suffix , self ._color )
3074
+ ''' overwrite last self._len characters '''
3075
+ self ._win .addstr (' ' * 2 , self ._color )
2969
3076
self ._showed = True
2970
3077
2971
3078
def keypress (self , char ):
0 commit comments