ソースを参照

default value handling added

master
Dirk Alders 1年前
コミット
c9d7f78f6d
1個のファイルの変更12行の追加2行の削除
  1. 12
    2
      __init__.py

+ 12
- 2
__init__.py ファイルの表示

@@ -1,4 +1,5 @@
1 1
 import bottombar as bb
2
+import os
2 3
 import readchar
3 4
 import string
4 5
 
@@ -34,13 +35,17 @@ class BottomBar(object):
34 35
         self.__bb_args__['__info__'] = (args, kwargs)
35 36
 
36 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 42
         if len(args) == 0:
38 43
             args = ("", )
39 44
         # store data for entry
40 45
         if function in [self.FUNC_BOOL]:
41
-            self.__bb_data__[name] = False
46
+            self.__bb_data__[name] = default or False
42 47
         elif function in [self.FUNC_TEXT]:
43
-            self.__bb_data__[name] = ""
48
+            self.__bb_data__[name] = default or ""
44 49
         elif function in [self.FUNC_INFO]:
45 50
             self.__bb_data__[name] = kwargs.pop('infotext')
46 51
         # store function and name for key
@@ -100,3 +105,8 @@ class BottomBar(object):
100 105
                         self.edit_active = name
101 106
                     elif DEBUG:
102 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

読み込み中…
キャンセル
保存