Browse Source

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 years ago
parent
commit
bce8ef1763
3 changed files with 21 additions and 9 deletions
  1. 6
    2
      kayleevc/gui.py
  2. 12
    7
      kayleevc/numbers.py
  3. 3
    0
      kayleevc/util.py

+ 6
- 2
kayleevc/gui.py View File

@@ -10,9 +10,11 @@ from gi.repository import GObject
10 10
 gi.require_version('Gtk', '3.0')
11 11
 from gi.repository import Gtk, Gdk
12 12
 
13
+
13 14
 class GTKTrayInterface(GObject.GObject):
14 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 19
     idle_text = "Kaylee - Idle"
18 20
     listening_text = "Kaylee - Listening"
@@ -106,9 +108,11 @@ class GTKTrayInterface(GObject.GObject):
106 108
     def set_icon_inactive(self):
107 109
         self.statusicon.set_from_file(self.icon_inactive)
108 110
 
111
+
109 112
 class GTKInterface(GObject.GObject):
110 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 118
     def __init__(self, args, continuous):

+ 12
- 7
kayleevc/numbers.py View File

@@ -6,8 +6,10 @@
6 6
 
7 7
 import re
8 8
 
9
-# Define the mappings from words to numbers
9
+
10 10
 class NumberParser:
11
+    """Parses integers from English strings"""
12
+
11 13
     zero = {
12 14
         'zero': 0
13 15
     }
@@ -81,12 +83,7 @@ class NumberParser:
81 83
             self.number_words.append(word)
82 84
 
83 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 87
         value = 0
91 88
         partial_value = 0
92 89
         last_list = None
@@ -136,6 +133,13 @@ class NumberParser:
136 133
         return value
137 134
 
138 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 143
         nums = []
140 144
         t_numless = ''
141 145
 
@@ -168,6 +172,7 @@ class NumberParser:
168 172
 
169 173
         return (t_numless.strip(), nums)
170 174
 
175
+
171 176
 if __name__ == '__main__':
172 177
     np = NumberParser()
173 178
     # Get the words to translate

+ 3
- 0
kayleevc/util.py View File

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

Loading…
Cancel
Save