[hamster-applet] utf8 fixes



commit 53de6e407fdf5a42be1e8ab6a4c4fd70700b7af1
Author: Toms Bauģis <toms baugis gmail com>
Date:   Mon Dec 7 22:30:11 2009 +0000

    utf8 fixes

 hamster/applet.py                |   13 ++-----------
 hamster/edit_activity.py         |    4 ++--
 hamster/preferences.py           |    2 +-
 hamster/standalone.py            |    3 ++-
 hamster/widgets/activityentry.py |   11 ++++++-----
 hamster/widgets/tags.py          |    4 ++--
 6 files changed, 15 insertions(+), 22 deletions(-)
---
diff --git a/hamster/applet.py b/hamster/applet.py
index 920feef..32b02a2 100755
--- a/hamster/applet.py
+++ b/hamster/applet.py
@@ -516,16 +516,6 @@ class HamsterApplet(object):
     def on_toggle(self, widget):
         self.__show_toggle(None, self.button.get_active())
 
-    def on_activity_entered(self, component):
-        """fires, when user writes activity by hand"""
-        activity_name = self.new_name.get_text().decode('utf8', 'replace')
-        
-        if activity_name == "":
-            return
-        
-        runtime.storage.add_fact(activity_name)
-        runtime.dispatcher.dispatch('panel_visible', False)
-
     """listview events"""
     def on_todays_keys(self, tree, event):
         if (event.keyval == gtk.keysyms.Delete):
@@ -684,7 +674,8 @@ Now, start tracking!
         self.get_widget("switch_activity").set_sensitive(widget.get_text() != "")
 
     def on_switch_activity_clicked(self, widget):
-        runtime.storage.add_fact(self.new_name.get_text().encode("utf-8"), self.new_tags.get_text())
+        runtime.storage.add_fact(self.new_name.get_text().decode("utf8", "replace"),
+                                 self.new_tags.get_text().decode("utf8", "replace"))
         self.new_name.set_text("")
         self.new_tags.set_text("")
         runtime.dispatcher.dispatch('panel_visible', False)
diff --git a/hamster/edit_activity.py b/hamster/edit_activity.py
index 8602d29..176b24b 100644
--- a/hamster/edit_activity.py
+++ b/hamster/edit_activity.py
@@ -163,7 +163,7 @@ class CustomFactController:
         if not activity:
             return False
 
-        tags = self.new_tags.get_text()
+        tags = self.new_tags.get_text().decode('utf8', 'replace')
         
         start_time = self._get_datetime("start")
 
@@ -226,7 +226,7 @@ class CustomFactController:
         self.get_widget("end_date_label").set_text(some_date.strftime("%x"))
     
     def validate_fields(self, widget = None):
-        activity_text = self.new_name.get_text()
+        activity_text = self.new_name.get_text().decode('utf8', 'replace')
         start_time = self._get_datetime("start")
 
         end_time = self._get_datetime("end")
diff --git a/hamster/preferences.py b/hamster/preferences.py
index 1b2673c..858fbab 100755
--- a/hamster/preferences.py
+++ b/hamster/preferences.py
@@ -666,7 +666,7 @@ class PreferencesEditor:
         self.get_widget("notify_on_idle").set_sensitive(value <= 120)
     
     def on_keybinding_changed(self, textbox):
-        self.config.set_keybinding(textbox.get_text())
+        self.config.set_keybinding(textbox.get_text().decode('utf8', 'replace'))
 
     def on_day_start_changed(self, widget):
         day_start = self.day_start.get_time()
diff --git a/hamster/standalone.py b/hamster/standalone.py
index 152268a..4efe90e 100755
--- a/hamster/standalone.py
+++ b/hamster/standalone.py
@@ -167,7 +167,8 @@ class MainWindow(object):
         self.get_widget("switch_activity").set_sensitive(widget.get_text() != "")
 
     def on_switch_activity_clicked(self, widget):
-        runtime.storage.add_fact(self.new_name.get_text().encode("utf-8"), self.new_tags.get_text())
+        runtime.storage.add_fact(self.new_name.get_text().decode('utf8', 'replace'),
+                                 self.new_tags.get_text().decode('utf8', 'replace'))
         self.new_name.set_text("")
         self.new_tags.set_text("")
 
diff --git a/hamster/widgets/activityentry.py b/hamster/widgets/activityentry.py
index 17634ba..dfde725 100644
--- a/hamster/widgets/activityentry.py
+++ b/hamster/widgets/activityentry.py
@@ -173,14 +173,14 @@ class ActivityEntry(gtk.Entry):
         else:
             cursor = self.get_position()
             
-        if self.activities and self.categories and self.filter == self.get_text()[:cursor]:
+        if self.activities and self.categories and self.filter == self.get_text().decode('utf8', 'replace')[:cursor]:
             return #same thing, no need to repopulate
 
         self.activities = self.activities or runtime.storage.get_autocomplete_activities()
         self.categories = self.categories or runtime.storage.get_category_list()
 
         
-        self.filter = self.get_text()[:cursor]
+        self.filter = self.get_text().decode('utf8', 'replace')[:cursor]
         
         input_activity = stuff.parse_activity_input(self.filter)
         
@@ -198,14 +198,15 @@ class ActivityEntry(gtk.Entry):
         store.clear()
 
         if self.filter.find("@") > 0:
-            key = self.filter[self.filter.find("@")+1:].lower()
+            key = self.filter[self.filter.find("@")+1:].decode('utf8', 'replace').lower()
             for category in self.categories:
-                if key in category['name'].lower():
+                if key in category['name'].decode('utf8', 'replace').lower():
                     fillable = (self.filter[:self.filter.find("@") + 1] + category['name'])
                     store.append([fillable, category['name'], fillable, time])
         else:
+            key = input_activity.activity_name.decode('utf8', 'replace').lower()
             for activity in self.activities:
-                if input_activity.activity_name == "" or activity['name'].startswith(input_activity.activity_name): #self.filter in activity['name']:
+                if input_activity.activity_name == "" or activity['name'].decode('utf8', 'replace').lower().startswith(key):
                     fillable = activity['name']
                     if activity['category']:
                         fillable += "@%s" % activity['category']
diff --git a/hamster/widgets/tags.py b/hamster/widgets/tags.py
index 2de2752..3b9db0b 100644
--- a/hamster/widgets/tags.py
+++ b/hamster/widgets/tags.py
@@ -67,7 +67,7 @@ class TagsEntry(gtk.Entry):
 
     def get_tags(self):
         # splits the string by comma and filters out blanks
-        return [tag.strip() for tag in self.get_text().split(",") if tag.strip()]
+        return [tag.strip() for tag in self.get_text().decode('utf8', 'replace').split(",") if tag.strip()]
 
     def on_tag_selected(self, tag_box, tag):
         tags = self.get_tags()
@@ -171,7 +171,7 @@ class TagsEntry(gtk.Entry):
         else:
             cursor = self.get_position()
 
-        text = self.get_text()
+        text = self.get_text().decode('utf8', 'replace')
 
         return text[text.rfind(",", 0, cursor)+1:max(text.find(",", cursor+1)+1, len(text))].strip()
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]