Browse Source

default value handling added

master
Dirk Alders 1 year ago
parent
commit
c9d7f78f6d
1 changed files with 12 additions and 2 deletions
  1. 12
    2
      __init__.py

+ 12
- 2
__init__.py View File

1
 import bottombar as bb
1
 import bottombar as bb
2
+import os
2
 import readchar
3
 import readchar
3
 import string
4
 import string
4
 
5
 
34
         self.__bb_args__['__info__'] = (args, kwargs)
35
         self.__bb_args__['__info__'] = (args, kwargs)
35
 
36
 
36
     def add_entry(self, name, f_key, function, *args, **kwargs):
37
     def add_entry(self, name, f_key, function, *args, **kwargs):
38
+        try:
39
+            default = kwargs.pop('default')
40
+        except KeyError:
41
+            default = None
37
         if len(args) == 0:
42
         if len(args) == 0:
38
             args = ("", )
43
             args = ("", )
39
         # store data for entry
44
         # store data for entry
40
         if function in [self.FUNC_BOOL]:
45
         if function in [self.FUNC_BOOL]:
41
-            self.__bb_data__[name] = False
46
+            self.__bb_data__[name] = default or False
42
         elif function in [self.FUNC_TEXT]:
47
         elif function in [self.FUNC_TEXT]:
43
-            self.__bb_data__[name] = ""
48
+            self.__bb_data__[name] = default or ""
44
         elif function in [self.FUNC_INFO]:
49
         elif function in [self.FUNC_INFO]:
45
             self.__bb_data__[name] = kwargs.pop('infotext')
50
             self.__bb_data__[name] = kwargs.pop('infotext')
46
         # store function and name for key
51
         # store function and name for key
100
                         self.edit_active = name
105
                         self.edit_active = name
101
                     elif DEBUG:
106
                     elif DEBUG:
102
                         print("unused keystroke in run method:", repr(data))
107
                         print("unused keystroke in run method:", repr(data))
108
+                else:
109
+                    if data in ['c', ]:
110
+                        os.system('clear')
111
+                    elif data in ['q', ]:
112
+                        break

Loading…
Cancel
Save