Преглед на файлове

Formatting and documentation

Added some blank lines and wrapped some long lines to be closer to PEP 8
compliance.

Improved docstrings in NumberParser class.  Added docstrings for
undocumented code and removed a TODO message that no longer applies.
Clara Hobbs преди 8 години
родител
ревизия
bce8ef1763
променени са 3 файла, в които са добавени 21 реда и са изтрити 9 реда
  1. 6
    2
      kayleevc/gui.py
  2. 12
    7
      kayleevc/numbers.py
  3. 3
    0
      kayleevc/util.py

+ 6
- 2
kayleevc/gui.py Целия файл

10
 gi.require_version('Gtk', '3.0')
10
 gi.require_version('Gtk', '3.0')
11
 from gi.repository import Gtk, Gdk
11
 from gi.repository import Gtk, Gdk
12
 
12
 
13
+
13
 class GTKTrayInterface(GObject.GObject):
14
 class GTKTrayInterface(GObject.GObject):
14
     __gsignals__ = {
15
     __gsignals__ = {
15
-        'command' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,))
16
+        'command' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
17
+                     (GObject.TYPE_STRING,))
16
     }
18
     }
17
     idle_text = "Kaylee - Idle"
19
     idle_text = "Kaylee - Idle"
18
     listening_text = "Kaylee - Listening"
20
     listening_text = "Kaylee - Listening"
106
     def set_icon_inactive(self):
108
     def set_icon_inactive(self):
107
         self.statusicon.set_from_file(self.icon_inactive)
109
         self.statusicon.set_from_file(self.icon_inactive)
108
 
110
 
111
+
109
 class GTKInterface(GObject.GObject):
112
 class GTKInterface(GObject.GObject):
110
     __gsignals__ = {
113
     __gsignals__ = {
111
-        'command' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,))
114
+        'command': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
115
+                    (GObject.TYPE_STRING,))
112
     }
116
     }
113
 
117
 
114
     def __init__(self, args, continuous):
118
     def __init__(self, args, continuous):

+ 12
- 7
kayleevc/numbers.py Целия файл

6
 
6
 
7
 import re
7
 import re
8
 
8
 
9
-# Define the mappings from words to numbers
9
+
10
 class NumberParser:
10
 class NumberParser:
11
+    """Parses integers from English strings"""
12
+
11
     zero = {
13
     zero = {
12
         'zero': 0
14
         'zero': 0
13
     }
15
     }
81
             self.number_words.append(word)
83
             self.number_words.append(word)
82
 
84
 
83
     def parse_number(self, text_line):
85
     def parse_number(self, text_line):
84
-        """
85
-        Parse numbers from natural language into ints
86
-
87
-        TODO: Throw more exceptions when invalid numbers are detected.  Only
88
-        allow certian valueless words within numbers.  Support zero.
89
-        """
86
+        """Parse a number from English into an int"""
90
         value = 0
87
         value = 0
91
         partial_value = 0
88
         partial_value = 0
92
         last_list = None
89
         last_list = None
136
         return value
133
         return value
137
 
134
 
138
     def parse_all_numbers(self, text_line):
135
     def parse_all_numbers(self, text_line):
136
+        """
137
+        Parse all numbers from English to ints
138
+
139
+        Returns a tuple whose first element is text_line with all English
140
+        numbers replaced with "%d", and whose second element is a list
141
+        containing all the parsed numbers as ints.
142
+        """
139
         nums = []
143
         nums = []
140
         t_numless = ''
144
         t_numless = ''
141
 
145
 
168
 
172
 
169
         return (t_numless.strip(), nums)
173
         return (t_numless.strip(), nums)
170
 
174
 
175
+
171
 if __name__ == '__main__':
176
 if __name__ == '__main__':
172
     np = NumberParser()
177
     np = NumberParser()
173
     # Get the words to translate
178
     # Get the words to translate

+ 3
- 0
kayleevc/util.py Целия файл

13
 
13
 
14
 from gi.repository import GLib
14
 from gi.repository import GLib
15
 
15
 
16
+
16
 class Config:
17
 class Config:
17
     """Keep track of the configuration of Kaylee"""
18
     """Keep track of the configuration of Kaylee"""
18
     # Name of the program, for later use
19
     # Name of the program, for later use
93
             # Make an empty options namespace
94
             # Make an empty options namespace
94
             self.options = Namespace()
95
             self.options = Namespace()
95
 
96
 
97
+
96
 class Hasher:
98
 class Hasher:
97
     """Keep track of hashes for Kaylee"""
99
     """Keep track of hashes for Kaylee"""
98
 
100
 
123
         with open(self.config.hash_file, 'w') as f:
125
         with open(self.config.hash_file, 'w') as f:
124
             json.dump(self.hashes, f)
126
             json.dump(self.hashes, f)
125
 
127
 
128
+
126
 class LanguageUpdater:
129
 class LanguageUpdater:
127
     """
130
     """
128
     Handles updating the language using the online lmtool.
131
     Handles updating the language using the online lmtool.

Loading…
Отказ
Запис