fah-control icon indicating copy to clipboard operation
fah-control copied to clipboard

Port to python 3 and GTK3

Open nikolaik opened this issue 4 years ago β€’ 27 comments

This is a WIP of a basic port from the GTK2 UI to GTK3. This also moves to python 3 only. I've tried to keep the changes as minimal as possible, leaving out formatting with PEP8/black, travis tests and refactoring.

Note that I am pretty unfamiliar with gtk, so be kind. I have not been able to test on mac yet, and will need help on windows. Any feedback is welcome 😊

Summary of changes:

  • Add basic gtk test with pytest.
  • Start using gobject style imports of gtk, pango, glib, etc.
  • Remove some python 2 specifics like OrderedDict backport and use of xrange.
  • Fix usage of map and filter in python 3 and wrap them in list().
  • Fix relative imports in python 3.
  • Updated .glade file to gtk 3.0+.
  • In FAHControl, get_visible_dialogs, store_dimensions and preferences_dialog_init now works
  • Use bytes where appriate and strings elsewhere in connection handling.
  • Use quote from urllib.parse
  • Replaced sys.maxint with sys.maxsize
  • Removed FAHControl.set_proc_name

TODO:

  • [x] Icon is garbled
  • [x] ~Migrate preference 'donor_stats_link' and one more to Gtk.ComboBoxText~ Initilize donor_stats_link prefs properly
  • [x] Linux build, deb
  • [ ] Update packaging with correct deps
  • [ ] Linux build, rpm
  • [ ] MacOS build
  • [ ] Windows build

nikolaik avatar Mar 22 '20 23:03 nikolaik

I am very familiar with GTK 3 in Python 3. Can I help?

guystreeter avatar Mar 25 '20 01:03 guystreeter

@guystreeter Yes you can 😊 I'll add you as a collaborator on my forked repo. If you want look at the FIXME(nikolaik) things, the TODOs in the PR description or anything else you find bad or broken, that would help a lot!

I have researched a bit on how to package python gtk3 apps for windows, mac and linux and found that the gaphor project is pretty successful (found from this list). I think I'll have a look at getting things building on macos next.

nikolaik avatar Mar 25 '20 10:03 nikolaik

Cool. I'm a Linux geek (Fedora/Red Hat). I don't know much about Windows or Mac OS, but I do have one of each available. I'm well versed in rpm packaging, and have made a few simple deb packages. I've written Gtk 2/3 applications in Python 2/3 from scratch, so converting the program to Gtk 3 and Python 3 is probably where I can best help. I have to say that the current code style is painful to look at. I'd really like to reformat it :).

On Wed, Mar 25, 2020 at 5:27 AM Nikolai RΓΈed Kristiansen < [email protected]> wrote:

@guystreeter https://github.com/guystreeter Yes you can 😊 I'll add you as a collaborator on my forked repo. If you want look at the FIXME(nikolaik) things, the TODOs in the PR description or anything else you find bad or broken, that would help a lot!

I have researched a bit on how to package python gtk3 apps for windows, mac and linux and found that the gaphor project https://github.com/gaphor/gaphor is pretty successful (found from this list https://pygobject.readthedocs.io/en/latest/#who-is-using-pygobject. I think I'll have a look at getting things building on macos next.

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FoldingAtHome/fah-control/pull/56#issuecomment-603762056, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL45YVNOVCYLTUFOZKOXK6LRJHMALANCNFSM4LRPPNBQ .

guystreeter avatar Mar 25 '20 15:03 guystreeter

Cool. I'm a Linux geek (Fedora/Red Hat). I don't know much about Windows or Mac OS, but I do have one of each available. I'm well versed in rpm packaging, and have made a few simple deb packages.

Let's work together on the linux packaging then 😊

(...) I've written Gtk 2/3 applications in Python 2/3 from scratch, so converting the program to Gtk 3 and Python 3 is probably where I can best help.

Perfect πŸ‘Œ

I have to say that the current code style is painful to look at. I'd really like to reformat it :).

Agreed. To keep the scope of this PR down and to make it easier to review, I think code style and formatting should be left as a followup PR. As I see it, the most important contribution would be to make stuff run on a relative modern setup of Linux, to help other people contribute.

nikolaik avatar Mar 25 '20 16:03 nikolaik

I've pushed 3 commits. One corrects an encoding problem in the configuration dialog. One may not be specific to Python 3. Could just be a corner case I encountered, but it fixes an exception handling problem. The last one corrects the display of the icons. I think I got all of them, let me know if there are still some wonky ones.

guystreeter avatar Mar 26 '20 16:03 guystreeter

I've pushed some more changes. The comboboxes in the preference dialog initialize correctly. The icon on the Viewer button shows up now. The windows no longer get larger every time you start the application.

guystreeter avatar Mar 27 '20 19:03 guystreeter

What is the best way to test this branch? Do I need to build and install it? Or is there a way to run it from the build directory without installing.

Keep up the good work!

jasontitus avatar Mar 27 '20 21:03 jasontitus

You can run it from source.

 git clone https://github.com/nikolaik/fah-control.git
 cd fah-control
 git checkout feature/gtk3-python3
 ./FAHControl

Just to be sure you're only using the new stuff, I'd suggest you un-install the FAHControl package if you have it.

guystreeter avatar Mar 27 '20 23:03 guystreeter

You can run it from source.

 git clone https://github.com/nikolaik/fah-control.git
 cd fah-control
 git checkout feature/gtk3-python3
 ./FAHControl

I think there is a step missing. After a fresh clone I cannot start FAHControl:

 Traceback (most recent call last):
  File "./FAHControl", line 25, in <module>
    from fah import FAHControl, single_app_addr
  File "/data/git/fah-control/fah/__init__.py", line 24, in <module>
    from .Version import *
ModuleNotFoundError: No module named 'fah.Version'

I found out that this file is ignored from git as it is generated by setup.py. However, after I manually created that file I could start FAHControl on debian/buster.

Locke avatar Mar 28 '20 08:03 Locke

@guystreeter excellent work! I'll test the changes this weekend. Hopefully will have time to look at building on mac soon.

nikolaik avatar Mar 28 '20 11:03 nikolaik

You can run it from source.

 git clone https://github.com/nikolaik/fah-control.git
 cd fah-control
 git checkout feature/gtk3-python3
 ./FAHControl

I think there is a step missing. After a fresh clone I cannot start FAHControl:

 Traceback (most recent call last):
  File "./FAHControl", line 25, in <module>
    from fah import FAHControl, single_app_addr
  File "/data/git/fah-control/fah/__init__.py", line 24, in <module>
    from .Version import *
ModuleNotFoundError: No module named 'fah.Version'

I found out that this file is ignored from git as it is generated by setup.py. However, after I manually created that file I could start FAHControl on debian/buster.

Yes, sorry I forgot about that step. You can just run

python3 setup.py build

to create that file. Your app won't show the correct version number, but it will still run.

guystreeter avatar Mar 28 '20 15:03 guystreeter

While I'm waiting for testing of the source changes, I'll start updating the rpm packaging.

guystreeter avatar Mar 28 '20 16:03 guystreeter

I suppose that https://github.com/FoldingAtHome/fah-control/blob/master/stdeb.cfg Is outdated.

bhack avatar Mar 28 '20 18:03 bhack

While I'm waiting for testing of the source changes, I'll start updating the rpm packaging.

I tested your last commits @guystreeter and they worked like a charm.

Having a hard time packaging for macos, trying to use py2app, pyinstaller and the packaging script from gaphor. Having the most success with the gaphor method atm and will pursue that further the coming week.

nikolaik avatar Mar 29 '20 22:03 nikolaik

Well, I'm confused about how the RPM package is currently built. There is no RPM .spec file to control the build. Perhaps it is stored in some other source repository?

guystreeter avatar Mar 30 '20 02:03 guystreeter

@jcoffland We are trying to get this building again for gtk3+ and python3. Do you have any pointers on packaging?

nikolaik avatar Mar 30 '20 09:03 nikolaik

I documented my attempts on a Windows build here: https://github.com/nikolaik/fah-control/pull/2

Locke avatar Mar 31 '20 07:03 Locke

well it seems to be working for me Ubuntu 19.10 , glad to finally have the apt errors not showing how can I rebuild this into a deb installer so package manager can launch it again ?

MasterCATZ avatar Apr 01 '20 05:04 MasterCATZ

I am willing to contribute.

PokefanSean avatar Apr 01 '20 16:04 PokefanSean

I've been looking at building for debian and have an experimental branch build-linux which uses circleci to build. If you want to try out the new deb you'll find that as an artifact of the circleci job here (link to deb).

  • Does it work for you?

There are a few remaining known issues with it:

  • [x] ~package name should be fahcontrol like before~
  • [x] ~After downloading and running dpkg -I python3-fahcontrol_8.0.0-1_all.deb I see fewer dependencies than in stdeb.cfg, namely Depends: python3-gi, python3:any (>= 3.5~) instead of Depends: python3-gi-cairo, gir1.2-gtk-3.0.~

Update: Fixed the issues and made another build.

On the build side of things I see the next steps as

  • [ ] Reading the version from tags (instead of hardcoded version to v8.0.0).
  • [ ] Upload the deb to a github release.

nikolaik avatar Apr 05 '20 22:04 nikolaik

I haven't done anything with the rpm build yet. I was hoping to hear there was already a .spec file somewhere. It isn't difficult to create a new one, and I can do that. I remain confused, though, about the mention of RPM in the scripts SConstruct and rpm/build. Perhaps they are artifacts.

guystreeter avatar Apr 06 '20 01:04 guystreeter

Hi Nikolaik,

I tried the new deb package on Ubuntu 19.10. It installed perfectly: root@shark:/home/bert/Downloads# dpkg -i fahcontrol_8.0.0-1_all.deb Selecting previously unselected package fahcontrol. (Reading database ... 345286 files and directories currently installed.) Preparing to unpack fahcontrol_8.0.0-1_all.deb ... Unpacking fahcontrol (8.0.0-1) ... Setting up fahcontrol (8.0.0-1) ... root@shark:/home/bert/Downloads#

Also the usage looks good. But this is the first time I started fahcontrol. So I am not fully qualified to judge the functionalitty:-)

Great work though! Thx

Bert

brjhaverkamp avatar Apr 09 '20 10:04 brjhaverkamp

Installed on Siduction, no problems. I put in the number for my team, that was used in the /etc/fahclient/config.xml, replacing the team name that had been there, so it's definitely doing something. I didn't see anything in there about the Covid-19 setting I'd enabled, though. Perhaps that's held in FAHControl.db? Thanks for getting this going.

Pip

Huffleme avatar Apr 18 '20 12:04 Huffleme

Do we have a duplicated effort https://github.com/FoldingAtHome/fah-control/pull/70?

bhack avatar Apr 24 '20 21:04 bhack

I have added an RPM .spec file and a script to build RPM packages. I tested it on Fedora 31.

guystreeter avatar Apr 24 '20 22:04 guystreeter

Will it be possible to be PEP8 compliant? it will help the project be more consistent with other projects of python and easier to read. I would love to help with the effort of porting to python3 and the PEP8 one

moshe742 avatar May 16 '20 15:05 moshe742

any progress ?

Davilink avatar Dec 12 '20 12:12 Davilink