2to3 conversion
This commit is contained in:
parent
5ef3ee1179
commit
e0a9a3994d
@ -1,4 +1,4 @@
|
|||||||
################################################################################
|
###############################################################################
|
||||||
# #
|
# #
|
||||||
# Folding@Home Client Control (FAHControl) #
|
# Folding@Home Client Control (FAHControl) #
|
||||||
# Copyright (C) 2016-2020 foldingathome.org #
|
# Copyright (C) 2016-2020 foldingathome.org #
|
||||||
@ -17,13 +17,14 @@
|
|||||||
# You should have received a copy of the GNU General Public License #
|
# You should have received a copy of the GNU General Public License #
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||||
# #
|
# #
|
||||||
################################################################################
|
###############################################################################
|
||||||
|
|
||||||
import gtk
|
from gi.repository import Gtk
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
class EntryValidator:
|
class EntryValidator:
|
||||||
def __init__(self, app, entry, pattern, description = ''):
|
def __init__(self, app, entry, pattern, description=''):
|
||||||
self.app = app
|
self.app = app
|
||||||
self.entry = entry
|
self.entry = entry
|
||||||
self.re = re.compile(pattern)
|
self.re = re.compile(pattern)
|
||||||
@ -33,21 +34,19 @@ class EntryValidator:
|
|||||||
entry.connect('focus-in-event', self.on_focus_in_event)
|
entry.connect('focus-in-event', self.on_focus_in_event)
|
||||||
entry.connect('focus-out-event', self.on_focus_out_event)
|
entry.connect('focus-out-event', self.on_focus_out_event)
|
||||||
|
|
||||||
|
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
return self.re.match(self.entry.get_text()) is not None
|
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()
|
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():
|
if not self.is_valid():
|
||||||
self.app.error('Invalid value\n%s' % self.description)
|
self.app.error('Invalid value\n%s' % self.description)
|
||||||
self.entry.set_text(self.text)
|
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
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
################################################################################
|
###############################################################################
|
||||||
# #
|
# #
|
||||||
# Folding@Home Client Control (FAHControl) #
|
# Folding@Home Client Control (FAHControl) #
|
||||||
# Copyright (C) 2016-2020 foldingathome.org #
|
# Copyright (C) 2016-2020 foldingathome.org #
|
||||||
@ -17,7 +17,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License #
|
# You should have received a copy of the GNU General Public License #
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||||
# #
|
# #
|
||||||
################################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
# fah.util
|
# fah.util
|
||||||
@ -28,7 +28,7 @@ import gtk
|
|||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
try:
|
try:
|
||||||
from gtk_osxapplication import *
|
from gtk_osxapplication import *
|
||||||
except:
|
except ImportError:
|
||||||
from gtkosx_application import gtkosx_application_get_resource_path \
|
from gtkosx_application import gtkosx_application_get_resource_path \
|
||||||
as quartz_application_get_resource_path
|
as quartz_application_get_resource_path
|
||||||
|
|
||||||
@ -40,7 +40,8 @@ from .PYONDecoder import *
|
|||||||
|
|
||||||
|
|
||||||
def parse_bool(x):
|
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']
|
return x.lower() in ['true', 't', '1', 'yes', 'y']
|
||||||
|
|
||||||
|
|
||||||
@ -65,13 +66,16 @@ def status_to_color(status):
|
|||||||
return '#1ef0bc'
|
return '#1ef0bc'
|
||||||
elif status == 'DUMP':
|
elif status == 'DUMP':
|
||||||
return '#d2c272'
|
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 = '<span'
|
markup = '<span'
|
||||||
if bg is not None: markup += ' background="%s"' % bg
|
if bg is not None:
|
||||||
if fg is not None: markup += ' foreground="%s"' % fg
|
markup += ' background="%s"' % bg
|
||||||
|
if fg is not None:
|
||||||
|
markup += ' foreground="%s"' % fg
|
||||||
markup += '>%s</span>' % text
|
markup += '>%s</span>' % text
|
||||||
return markup
|
return markup
|
||||||
|
|
||||||
@ -81,18 +85,22 @@ def iterate_container(widget):
|
|||||||
|
|
||||||
if isinstance(widget, gtk.Container):
|
if isinstance(widget, gtk.Container):
|
||||||
for child in widget.get_children():
|
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):
|
def make_row(cols, keys):
|
||||||
for col in cols:
|
for col in cols:
|
||||||
if col in keys: yield keys[col]
|
if col in keys:
|
||||||
else: yield ''
|
yield keys[col]
|
||||||
|
else:
|
||||||
|
yield ''
|
||||||
|
|
||||||
|
|
||||||
def get_combo_items(widget):
|
def get_combo_items(widget):
|
||||||
items = []
|
items = []
|
||||||
def iterate_list(model, path, iter, data = None):
|
|
||||||
|
def iterate_list(model, path, iter, data=None):
|
||||||
items.append(model.get_value(iter, 0))
|
items.append(model.get_value(iter, 0))
|
||||||
|
|
||||||
widget.get_model().foreach(iterate_list, None)
|
widget.get_model().foreach(iterate_list, None)
|
||||||
@ -106,19 +114,24 @@ def get_widget_str_value(widget):
|
|||||||
|
|
||||||
# Clean up float formatting
|
# Clean up float formatting
|
||||||
value = '%.2f' % widget.get_value()
|
value = '%.2f' % widget.get_value()
|
||||||
if value.endswith('.00'): value = value[0:-3]
|
if value.endswith('.00'):
|
||||||
elif value.endswith('.0'): value = value[0:-2]
|
value = value[0:-3]
|
||||||
|
elif value.endswith('.0'):
|
||||||
|
value = value[0:-2]
|
||||||
return value
|
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):
|
elif isinstance(widget, gtk.RadioButton):
|
||||||
# TODO interpret as a number? or name?
|
# TODO interpret as a number? or name?
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif isinstance(widget, gtk.ToggleButton):
|
elif isinstance(widget, gtk.ToggleButton):
|
||||||
if widget.get_active(): return 'true'
|
if widget.get_active():
|
||||||
else: return 'false'
|
return 'true'
|
||||||
|
else:
|
||||||
|
return 'false'
|
||||||
|
|
||||||
elif isinstance(widget, gtk.ComboBox):
|
elif isinstance(widget, gtk.ComboBox):
|
||||||
# NOTE This does not always get the displayed text
|
# 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):
|
def set_widget_str_value(widget, value):
|
||||||
if value is None: value = ''
|
if value is None:
|
||||||
|
value = ''
|
||||||
value = str(value)
|
value = str(value)
|
||||||
|
|
||||||
if isinstance(widget, (gtk.SpinButton, gtk.Range)):
|
if isinstance(widget, (gtk.SpinButton, gtk.Range)):
|
||||||
# Must come before gtk.Entry for gtk.SpinButton
|
# Must come before gtk.Entry for gtk.SpinButton
|
||||||
if value == '': value = 0
|
if value == '':
|
||||||
|
value = 0
|
||||||
else:
|
else:
|
||||||
try: value = float(value)
|
try:
|
||||||
except: value = 0
|
value = float(value)
|
||||||
|
except:
|
||||||
|
value = 0
|
||||||
widget.set_value(value)
|
widget.set_value(value)
|
||||||
|
|
||||||
elif isinstance(widget, (gtk.Entry, gtk.Label)):
|
elif isinstance(widget, (gtk.Entry, gtk.Label)):
|
||||||
if widget.get_text() != value: widget.set_text(value)
|
if widget.get_text() != value:
|
||||||
elif isinstance(widget, gtk.RadioButton): pass # Ignore for now
|
widget.set_text(value)
|
||||||
|
elif isinstance(widget, gtk.RadioButton):
|
||||||
|
pass # Ignore for now
|
||||||
elif isinstance(widget, gtk.ToggleButton):
|
elif isinstance(widget, gtk.ToggleButton):
|
||||||
widget.set_active(parse_bool(value))
|
widget.set_active(parse_bool(value))
|
||||||
elif isinstance(widget, gtk.Button):
|
elif isinstance(widget, gtk.Button):
|
||||||
@ -164,10 +183,13 @@ def set_widget_str_value(widget, value):
|
|||||||
elif isinstance(widget, gtk.ProgressBar):
|
elif isinstance(widget, gtk.ProgressBar):
|
||||||
widget.set_text(value)
|
widget.set_text(value)
|
||||||
|
|
||||||
if value == '': value = '0'
|
if value == '':
|
||||||
|
value = '0'
|
||||||
|
|
||||||
if value.endswith('%'): fraction = float(value[:-1]) / 100.0
|
if value.endswith('%'):
|
||||||
else: fraction = float(value)
|
fraction = float(value[:-1]) / 100.0
|
||||||
|
else:
|
||||||
|
fraction = float(value)
|
||||||
|
|
||||||
widget.set_fraction(fraction)
|
widget.set_fraction(fraction)
|
||||||
|
|
||||||
@ -196,16 +218,19 @@ def set_widget_change_action(widget, action):
|
|||||||
|
|
||||||
|
|
||||||
def get_home_dir():
|
def get_home_dir():
|
||||||
if sys.platform == 'win32': return '.'
|
if sys.platform == 'win32':
|
||||||
|
return '.'
|
||||||
|
|
||||||
path = os.path.expanduser("~")
|
path = os.path.expanduser("~")
|
||||||
|
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
path = os.path.join(path, 'Library/Application Support/FAHClient')
|
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
|
return path
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user