Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Port to python 3 and GTK3 #56

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
de95d53
FAHControl init is not crashing
nikolaik Mar 22, 2020
0a9c0f9
Add updated .glade file
nikolaik Mar 22, 2020
fae889f
Do not set_proc_name in FAHControl
nikolaik Mar 22, 2020
f897e58
Fix basic UI errors
nikolaik Mar 22, 2020
b2cb272
Working client, connection and a lot of the UI
nikolaik Mar 22, 2020
d57193c
Fix python 2 exception handling
nikolaik Mar 22, 2020
18aa5a6
Minor str/bytes fix
nikolaik Mar 23, 2020
582337b
Python3 is already Unicode. Re-encoding to unicode causes errors.
guystreeter Mar 26, 2020
1c14fd2
Correct some exception raising and checking.
guystreeter Mar 26, 2020
d755caa
Correctly encode the raw binary icon strings.
guystreeter Mar 26, 2020
340fb3f
Properly initialize the Preferences dialog combo boxes.
guystreeter Mar 27, 2020
83351b3
Make the Viewer button icon show up.
guystreeter Mar 27, 2020
169265b
Keep the windows from growing larger every time the app is started.
guystreeter Mar 27, 2020
f3d6917
Use python3 set in environment
nikolaik Mar 28, 2020
7059c6b
Get running on macos
nikolaik Mar 28, 2020
3e51059
Remove gtk import
nikolaik Mar 29, 2020
4e7d675
Merge branch 'master' into feature/gtk3-python3
nikolaik Apr 5, 2020
7b253d1
Updated linux and debian deps
nikolaik Apr 5, 2020
efdbebc
Add a spec file for building RPM packages, and a script to build it.
guystreeter Apr 24, 2020
0c8ffb1
Fix .desktop file so it passes RPM validation
guystreeter Apr 24, 2020
f47fd20
Use "rpmbuild" subir for building, because "rpm" subdir exists
guystreeter Apr 25, 2020
b605655
Fixes for building in mock/copr/koji targets.
guystreeter Apr 25, 2020
34203bb
Remove arch string from tar archive filename.
guystreeter Apr 25, 2020
c6d6c43
Ignore the rpmbuild directory.
guystreeter Apr 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
/config.log
/package*.txt
/fah/FAHControl_glade.py
fah/#FAHControl.glade#
/fah/Version.py
/FAHControl.egg-info
/deb_dist
/dist
/version.txt
/FAHControl*.tar.gz
/fahcontrol*.pkg
/rpmbuild

# Temporary files
*~

.eggs/
venv/
22 changes: 4 additions & 18 deletions FAHControl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
'''
Folding@Home Client Control (FAHControl)
Copyright (C) 2010-2020 foldingathome.org
Expand All @@ -22,21 +22,7 @@ import sys
import inspect
import socket
from optparse import OptionParser
from fah import FAHControl, load_fahcontrol_db
from fah.util import *
from fah.db import *


def set_proc_name(name):
from ctypes import cdll, byref, create_string_buffer

libc = cdll.LoadLibrary('libc.so.6')
buff = create_string_buffer(len(name)+1)
buff.value = name
libc.prctl(15, byref(buff), 0, 0, 0)


if sys.platform.startswith('linux'): set_proc_name('FAHControl')
from fah import FAHControl, single_app_addr

# If present, remove the Launch Services -psn_xxx_xxx argument
if len(sys.argv) > 1 and sys.argv[1][:4] == '-psn':
Expand All @@ -53,8 +39,8 @@ if options.exit:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(single_app_addr)
sock.send('EXIT')
if sock.recv(1024).strip() == 'OK': print ('Ok')
sock.send(b'EXIT')
if sock.recv(1024).strip() == b'OK': print ('Ok')
except Exception as e:
pass

Expand Down
4 changes: 2 additions & 2 deletions FAHControl.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ TryExec=FAHControl
StartupNotify=false
Terminal=false
Type=Application
Categories=Science;Biology;Education;;
Categories=Science;Biology;Education
Comment=Folding@home Client Control
Icon=FAHControl.png
Icon=FAHControl
6 changes: 3 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import os
env = Environment(ENV = os.environ)
try:
env.Tool('config', toolpath = [os.environ.get('CBANG_HOME')])
except Exception, e:
raise Exception, 'CBANG_HOME not set?\n' + str(e)
except Exception as e:
raise Exception('CBANG_HOME not set?\n' + str(e))

env.CBLoadTools('packager run_distutils osx fah-client-version')
env.CBAddVariables(
Expand All @@ -14,7 +14,7 @@ conf = env.CBConfigure()
# Version
try:
version = env.FAHClientVersion()
except Exception, e:
except Exception as e:
print(e)
version = '0.0.0'
env.Replace(PACKAGE_VERSION = version)
Expand Down
7 changes: 3 additions & 4 deletions fah/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import re
import copy
import collections
import gtk
import subprocess
import time
import sys
Expand Down Expand Up @@ -56,7 +55,7 @@ def __init__(self, app, name, address, port, password):

# Option names
names = app.client_option_widgets.keys()
self.option_names = map(lambda name: name.replace('_', '-'), names)
self.option_names = list(map(lambda name: name.replace('_', '-'), names))
self.option_names.append('power') # Folding power

# Init commands
Expand Down Expand Up @@ -208,7 +207,7 @@ def save_options(self, options):
for name, value in options.items():
cmd += ' ' + name
if name[-1] != '!':
cmd += "='%s'" % value.encode('string_escape')
cmd += "='%s'" % value

cmd += ' %s *' % ' '.join(self.option_names)

Expand Down Expand Up @@ -361,7 +360,7 @@ def update(self, app):
self.conn.messages = []

except Exception as e:
print (e)
print ('Error in Client.update', e)

# If client status has changed update UI
newStatus = self.get_status()
Expand Down
53 changes: 20 additions & 33 deletions fah/ClientConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
################################################################################

import sys
import gtk
import traceback
import re

from fah.util import parse_bool
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

from fah.util import parse_bool, get_selected_tree_column, get_active_combo_column
from fah.util import status_to_color
from fah.util import get_span_markup
from fah.util import get_widget_str_value
Expand All @@ -51,21 +54,6 @@ def get_buffer_text(buffer):
return buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())


def get_model_column(model, iter, column):
if iter is not None: return model.get_value(iter, column)


def get_selected_tree_column(tree, column):
selection = tree.get_selection()
model = tree.get_model()
if selection is not None:
return get_model_column(model, selection.get_selected()[1], column)


def get_active_combo_column(combo, column):
return get_model_column(combo.get_model(), combo.get_active_iter(), column)


class ClientConfig:
queue_cols = ('id state statecolor percentdone percent').split()

Expand Down Expand Up @@ -162,7 +150,7 @@ def update_queue_ui(self, app):
self.updating = False

# Reload queue list
for values in sorted(self.queue, lambda x, y: cmp(x['id'], y['id'])):
for values in sorted(self.queue, key=lambda x: x['id']):
unit_id = values['unit']
queue_id = values['id']
status = values['state'].title()
Expand Down Expand Up @@ -297,53 +285,53 @@ def update_info(self, app):
for child in port.get_children(): port.remove(child)

# Alignment
align = gtk.Alignment(0, 0, 1, 1)
align = Gtk.Alignment.new(0, 0, 1, 1)
align.set_padding(4, 4, 4, 4)
port.add(align)

# Vertical box
vbox = gtk.VBox()
vbox = Gtk.VBox()
align.add(vbox)

for category in self.info:
name = category[0]
category = category[1:]

# Frame
frame = gtk.Frame('<b>%s</b>' % name)
frame.set_shadow_type(gtk.SHADOW_ETCHED_IN)
frame = Gtk.Frame.new('<b>%s</b>' % name)
frame.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
frame.get_label_widget().set_use_markup(True)
vbox.pack_start(frame, False)
vbox.pack_start(frame, False, False, 0)

# Alignment
align = gtk.Alignment(0, 0, 1, 1)
align = Gtk.Alignment.new(0, 0, 1, 1)
align.set_padding(0, 0, 12, 0)
frame.add(align)

# Table
table = gtk.Table(len(category), 2)
table = Gtk.Table.new(len(category), 2, False)
table.set_col_spacing(0, 5)
align.add(table)

row = 0
for name, value in category:
# Name
label = gtk.Label('<b>%s</b>' % name)
label = Gtk.Label.new('<b>%s</b>' % name)
label.set_use_markup(True)
label.set_alignment(1, 0.5)
table.attach(label, 0, 1, row, row + 1, gtk.FILL, gtk.FILL)
table.attach(label, 0, 1, row, row + 1, Gtk.Align.FILL, Gtk.Align.FILL)

# Value
if value.startswith('http://'):
label = gtk.LinkButton(value, value)
label.set_relief(gtk.RELIEF_NONE)
label = Gtk.LinkButton.new(value, value)
label.set_relief(Gtk.ReliefStyle.NONE)
label.set_property('can-focus', False)

else: label = gtk.Label(value)
else: label = Gtk.Label.new(value)

label.set_alignment(0, 0.5)
label.modify_font(app.mono_font)
table.attach(label, 1, 2, row, row + 1, yoptions = gtk.FILL)
table.attach(label, 1, 2, row, row + 1, yoptions = Gtk.Align.FILL)

row += 1

Expand Down Expand Up @@ -501,11 +489,10 @@ def log_filter(self, line):


def log_add_lines(self, app, lines):
filtered = filter(self.log_filter, lines)
filtered = list(filter(self.log_filter, lines))

if len(filtered):
text = '\n'.join(filtered)
text = text.decode('utf-8', 'ignore')
app.log.insert(app.log.get_end_iter(), text + '\n')
self.scroll_log_to_end(app)

Expand Down
Loading