diff --git a/fah/util/EntryValidator.py b/fah/util/EntryValidator.py
index acf9c78..d29f3ff 100644
--- a/fah/util/EntryValidator.py
+++ b/fah/util/EntryValidator.py
@@ -1,29 +1,30 @@
-################################################################################
-# #
-# Folding@Home Client Control (FAHControl) #
-# Copyright (C) 2016-2020 foldingathome.org #
-# Copyright (C) 2010-2016 Stanford University #
-# #
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation, either version 3 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see . #
-# #
-################################################################################
+###############################################################################
+# #
+# Folding@Home Client Control (FAHControl) #
+# Copyright (C) 2016-2020 foldingathome.org #
+# Copyright (C) 2010-2016 Stanford University #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see . #
+# #
+###############################################################################
-import gtk
+from gi.repository import Gtk
import re
+
class EntryValidator:
- def __init__(self, app, entry, pattern, description = ''):
+ def __init__(self, app, entry, pattern, description=''):
self.app = app
self.entry = entry
self.re = re.compile(pattern)
@@ -33,21 +34,19 @@ class EntryValidator:
entry.connect('focus-in-event', self.on_focus_in_event)
entry.connect('focus-out-event', self.on_focus_out_event)
-
def is_valid(self):
return self.re.match(self.entry.get_text()) is not None
-
- def on_focus_in_event(self, widget, event, data = None):
+ def on_focus_in_event(self, widget, event, data=None):
self.text = self.entry.get_text()
- return False # let the signal propagate
+ return False # let the signal propagate
-
- def on_focus_out_event(self, widget, event, data = None):
+ def on_focus_out_event(self, widget, event, data=None):
if not self.is_valid():
self.app.error('Invalid value\n%s' % self.description)
self.entry.set_text(self.text)
- else: self.text = self.entry.get_text()
+ else:
+ self.text = self.entry.get_text()
- return False # let the signal propagate
+ return False # let the signal propagate
diff --git a/fah/util/__init__.py b/fah/util/__init__.py
index 8623b23..723b66d 100644
--- a/fah/util/__init__.py
+++ b/fah/util/__init__.py
@@ -1,23 +1,23 @@
-################################################################################
-# #
-# Folding@Home Client Control (FAHControl) #
-# Copyright (C) 2016-2020 foldingathome.org #
-# Copyright (C) 2010-2016 Stanford University #
-# #
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation, either version 3 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see . #
-# #
-################################################################################
+###############################################################################
+# #
+# Folding@Home Client Control (FAHControl) #
+# Copyright (C) 2016-2020 foldingathome.org #
+# Copyright (C) 2010-2016 Stanford University #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see . #
+# #
+###############################################################################
# fah.util
@@ -28,7 +28,7 @@ import gtk
if sys.platform == 'darwin':
try:
from gtk_osxapplication import *
- except:
+ except ImportError:
from gtkosx_application import gtkosx_application_get_resource_path \
as quartz_application_get_resource_path
@@ -40,7 +40,8 @@ from .PYONDecoder import *
def parse_bool(x):
- if isinstance(x, bool): return x
+ if isinstance(x, bool):
+ return x
return x.lower() in ['true', 't', '1', 'yes', 'y']
@@ -65,13 +66,16 @@ def status_to_color(status):
return '#1ef0bc'
elif status == 'DUMP':
return '#d2c272'
- else: return None
+ else:
+ return None
-def get_span_markup(text, bg = None, fg = 'black'):
+def get_span_markup(text, bg=None, fg='black'):
markup = '%s' % text
return markup
@@ -81,18 +85,22 @@ def iterate_container(widget):
if isinstance(widget, gtk.Container):
for child in widget.get_children():
- for x in iterate_container(child): yield x
+ for x in iterate_container(child):
+ yield x
def make_row(cols, keys):
for col in cols:
- if col in keys: yield keys[col]
- else: yield ''
+ if col in keys:
+ yield keys[col]
+ else:
+ yield ''
def get_combo_items(widget):
items = []
- def iterate_list(model, path, iter, data = None):
+
+ def iterate_list(model, path, iter, data=None):
items.append(model.get_value(iter, 0))
widget.get_model().foreach(iterate_list, None)
@@ -106,19 +114,24 @@ def get_widget_str_value(widget):
# Clean up float formatting
value = '%.2f' % widget.get_value()
- if value.endswith('.00'): value = value[0:-3]
- elif value.endswith('.0'): value = value[0:-2]
+ if value.endswith('.00'):
+ value = value[0:-3]
+ elif value.endswith('.0'):
+ value = value[0:-2]
return value
- elif isinstance(widget, gtk.Entry): return widget.get_text()
+ elif isinstance(widget, gtk.Entry):
+ return widget.get_text()
elif isinstance(widget, gtk.RadioButton):
# TODO interpret as a number? or name?
pass
elif isinstance(widget, gtk.ToggleButton):
- if widget.get_active(): return 'true'
- else: return 'false'
+ if widget.get_active():
+ return 'true'
+ else:
+ return 'false'
elif isinstance(widget, gtk.ComboBox):
# NOTE This does not always get the displayed text
@@ -129,20 +142,26 @@ def get_widget_str_value(widget):
def set_widget_str_value(widget, value):
- if value is None: value = ''
+ if value is None:
+ value = ''
value = str(value)
if isinstance(widget, (gtk.SpinButton, gtk.Range)):
# Must come before gtk.Entry for gtk.SpinButton
- if value == '': value = 0
+ if value == '':
+ value = 0
else:
- try: value = float(value)
- except: value = 0
+ try:
+ value = float(value)
+ except:
+ value = 0
widget.set_value(value)
elif isinstance(widget, (gtk.Entry, gtk.Label)):
- if widget.get_text() != value: widget.set_text(value)
- elif isinstance(widget, gtk.RadioButton): pass # Ignore for now
+ if widget.get_text() != value:
+ widget.set_text(value)
+ elif isinstance(widget, gtk.RadioButton):
+ pass # Ignore for now
elif isinstance(widget, gtk.ToggleButton):
widget.set_active(parse_bool(value))
elif isinstance(widget, gtk.Button):
@@ -164,10 +183,13 @@ def set_widget_str_value(widget, value):
elif isinstance(widget, gtk.ProgressBar):
widget.set_text(value)
- if value == '': value = '0'
+ if value == '':
+ value = '0'
- if value.endswith('%'): fraction = float(value[:-1]) / 100.0
- else: fraction = float(value)
+ if value.endswith('%'):
+ fraction = float(value[:-1]) / 100.0
+ else:
+ fraction = float(value)
widget.set_fraction(fraction)
@@ -196,16 +218,19 @@ def set_widget_change_action(widget, action):
def get_home_dir():
- if sys.platform == 'win32': return '.'
+ if sys.platform == 'win32':
+ return '.'
path = os.path.expanduser("~")
if sys.platform == 'darwin':
path = os.path.join(path, 'Library/Application Support/FAHClient')
- else: path = os.path.join(path, '.FAHClient')
+ else:
+ path = os.path.join(path, '.FAHClient')
- if not os.path.exists(path): os.makedirs(path)
+ if not os.path.exists(path):
+ os.makedirs(path)
return path