summary refs log tree commit diff
path: root/kayleevc
diff options
context:
space:
mode:
authorClayton G. Hobbs <clay@lakeserv.net>2016-05-15 12:18:44 -0400
committerClayton G. Hobbs <clay@lakeserv.net>2016-05-15 12:18:44 -0400
commitbce8ef1763c0a068e30d6302eb7c0568e22ea525 (patch)
tree8704d2783d03bc131563efc767a52f0d611329d9 /kayleevc
parent2611c6dcb64efabbd36c4925175c1533aeddb51e (diff)
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.
Diffstat (limited to 'kayleevc')
-rw-r--r--kayleevc/gui.py8
-rw-r--r--kayleevc/numbers.py19
-rw-r--r--kayleevc/util.py3
3 files changed, 21 insertions, 9 deletions
diff --git a/kayleevc/gui.py b/kayleevc/gui.py
index 3369e33..27085a8 100644
--- a/kayleevc/gui.py
+++ b/kayleevc/gui.py
@@ -10,9 +10,11 @@ from gi.repository import GObject
 gi.require_version('Gtk', '3.0')
 from gi.repository import Gtk, Gdk
 
+
 class GTKTrayInterface(GObject.GObject):
     __gsignals__ = {
-        'command' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,))
+        'command' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
+                     (GObject.TYPE_STRING,))
     }
     idle_text = "Kaylee - Idle"
     listening_text = "Kaylee - Listening"
@@ -106,9 +108,11 @@ class GTKTrayInterface(GObject.GObject):
     def set_icon_inactive(self):
         self.statusicon.set_from_file(self.icon_inactive)
 
+
 class GTKInterface(GObject.GObject):
     __gsignals__ = {
-        'command' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,))
+        'command': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
+                    (GObject.TYPE_STRING,))
     }
 
     def __init__(self, args, continuous):
diff --git a/kayleevc/numbers.py b/kayleevc/numbers.py
index 6d41b63..cb52728 100644
--- a/kayleevc/numbers.py
+++ b/kayleevc/numbers.py
@@ -6,8 +6,10 @@
 
 import re
 
-# Define the mappings from words to numbers
+
 class NumberParser:
+    """Parses integers from English strings"""
+
     zero = {
         'zero': 0
     }
@@ -81,12 +83,7 @@ class NumberParser:
             self.number_words.append(word)
 
     def parse_number(self, text_line):
-        """
-        Parse numbers from natural language into ints
-
-        TODO: Throw more exceptions when invalid numbers are detected.  Only
-        allow certian valueless words within numbers.  Support zero.
-        """
+        """Parse a number from English into an int"""
         value = 0
         partial_value = 0
         last_list = None
@@ -136,6 +133,13 @@ class NumberParser:
         return value
 
     def parse_all_numbers(self, text_line):
+        """
+        Parse all numbers from English to ints
+
+        Returns a tuple whose first element is text_line with all English
+        numbers replaced with "%d", and whose second element is a list
+        containing all the parsed numbers as ints.
+        """
         nums = []
         t_numless = ''
 
@@ -168,6 +172,7 @@ class NumberParser:
 
         return (t_numless.strip(), nums)
 
+
 if __name__ == '__main__':
     np = NumberParser()
     # Get the words to translate
diff --git a/kayleevc/util.py b/kayleevc/util.py
index 5c93b7f..8e33629 100644
--- a/kayleevc/util.py
+++ b/kayleevc/util.py
@@ -13,6 +13,7 @@ import requests
 
 from gi.repository import GLib
 
+
 class Config:
     """Keep track of the configuration of Kaylee"""
     # Name of the program, for later use
@@ -93,6 +94,7 @@ class Config:
             # Make an empty options namespace
             self.options = Namespace()
 
+
 class Hasher:
     """Keep track of hashes for Kaylee"""
 
@@ -123,6 +125,7 @@ class Hasher:
         with open(self.config.hash_file, 'w') as f:
             json.dump(self.hashes, f)
 
+
 class LanguageUpdater:
     """
     Handles updating the language using the online lmtool.