Jnrolfe / pychess

Automatically exported from code.google.com/p/pychess
GNU General Public License v3.0
0 stars 0 forks source link

Port to pygi #908

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I did a clone to port pychess to pygi. It needs work but you can play a game 
against it Human vs Human.

Link to clone: http://code.google.com/r/jcheetham19-pychess-pygi/source/checkout

Original issue reported on code.google.com by jcheetham19 on 24 Aug 2014 at 8:45

GoogleCodeExporter commented 8 years ago

Original comment by gbtami on 24 Aug 2014 at 9:46

GoogleCodeExporter commented 8 years ago
Good work! Tried it and got this on startup:
Traceback (most recent call last):
  File "./pychess", line 127, in <module>
    import pychess.Main
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/Main.py", line 26, in <module>
    from pychess.widgets import enginesDialog
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/enginesDialog.py", line 10, in <module>
    from pychess.widgets import newGameDialog
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/newGameDialog.py", line 32, in <module>
    from pychess.widgets import BoardPreview
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/BoardPreview.py", line 9, in <module>
    from pychess.widgets.BoardView import BoardView
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/BoardView.py", line 28, in <module>
    import preferencesDialog
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/preferencesDialog.py", line 10, in <module>
    from pychess.System import conf, gstreamer, uistuff
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/System/gstreamer.py", line 10, in <module>
    pyGst.require('0.10')
NameError: name 'pyGst' is not defined

Original comment by gbtami on 24 Aug 2014 at 9:51

GoogleCodeExporter commented 8 years ago
On my system I get ImportError which is caught and then sounds are muted.
I changed it to check for NameError as well so it should get past that now.
Haven't tested sounds yet. 

Original comment by jcheetham19 on 25 Aug 2014 at 5:56

GoogleCodeExporter commented 8 years ago
Now I get:

Traceback (most recent call last):
  File "./pychess", line 129, in <module>
    chess_file, ics_host, ics_port)
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/Main.py", line 479, in run
    pychess = PyChess(log_viewer, chess_file)
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/Main.py", line 316, in __init__
    self.initGlade(log_viewer)
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/Main.py", line 387, in initGlade
    clb = aboutdialog.get_child().get_children()[1].get_children()[2]
IndexError: list index out of range

p.s.
Btw. no need to check NameError. I think it was just a typo. It should be 
pygst.require('0.10')

Original comment by gbtami on 25 Aug 2014 at 7:34

GoogleCodeExporter commented 8 years ago
On my system the list is 2 GTKToggleButtons and a GTKButton. clb gets set to 
the GtkButton OK.

Not sure why yours is returning something else. Maybe it's down to different 
operating systems/versions.

Original comment by jcheetham19 on 25 Aug 2014 at 8:54

GoogleCodeExporter commented 8 years ago
I think it must be picking up the wrong glade file.
I tested it from within the source folder and set the PYTHONPATH:
    PYTHONPATH=lib/ ./pychess

Can you try this if you haven't already?

I usually set a different home folder to avoid interference with other 
installed versions:
    mkdir ~/pygihome
    PYTHONPATH=lib/ HOME=/home/john/pygihome ./pychess

Original comment by jcheetham19 on 25 Aug 2014 at 11:11

GoogleCodeExporter commented 8 years ago
I can start pychess with removing "clb = ..." and "clb.connect(...)" lines, and 
add 
aboutdialog.connect("response", callback)

But I can't play human-human games from New game menu, I get:
Traceback (most recent call last):
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/Main.py", line 181, in on_new_game1_activate
    newGameDialog.NewGameMode.run()
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/newGameDialog.py", line 383, in run
    cls._ensureReady()
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/newGameDialog.py", line 106, in _ensureReady
    _GameInitializationMode._init()
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/newGameDialog.py", line 144, in _init
    cls.widgets["configImageBlitz"], 5, 0)
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/newGameDialog.py", line 224, in __initTimeRadio
    ImageMenu.switchWithImage(configImage, alignment)
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/ImageMenu.py", line 86, in switchWithImage
    imageMenu = ImageMenu(image, dialog)
  File "/mnt/uhu2.2/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/ImageMenu.py", line 6, in __init__
    GObject.GObject.__init__(self)
NameError: global name 'GObject' is not defined

Seems we are using different versions of gtk/pygobject stuff.
Mine is 3.12.2

Original comment by gbtami on 25 Aug 2014 at 9:34

GoogleCodeExporter commented 8 years ago
Yes. I managed to reproduce the error using a different Linux.
New game menu is not working yet. You have to click the main 'start game' 
button.

Original comment by jcheetham19 on 25 Aug 2014 at 9:42

GoogleCodeExporter commented 8 years ago
My gtk version is 3.8.8.

Original comment by jcheetham19 on 25 Aug 2014 at 9:56

GoogleCodeExporter commented 8 years ago
The 'start game' button doesn't work too. I get:

Traceback (most recent call last):
  File "/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/TaskerManager.py", line 212, in openDialogClicked
    newGameDialog.NewGameMode.run()
  File "/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/newGameDialog.py", line 383, in run
    cls._ensureReady()
  File "/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/newGameDialog.py", line 106, in _ensureReady
    _GameInitializationMode._init()
  File "/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/newGameDialog.py", line 144, in _init
    cls.widgets["configImageBlitz"], 5, 0)
  File "/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/newGameDialog.py", line 224, in __initTimeRadio
    ImageMenu.switchWithImage(configImage, alignment)
  File "/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/ImageMenu.py", line 86, in switchWithImage
    imageMenu = ImageMenu(image, dialog)
  File "/home/tamas/jcheetham19-pychess-pygi/lib/pychess/widgets/ImageMenu.py", line 6, in __init__
    GObject.GObject.__init__(self)
NameError: global name 'GObject' is not defined

It's on Ubuntu 14.04, python-gi version is 3.12.0

Original comment by gbtami on 26 Aug 2014 at 6:32

GoogleCodeExporter commented 8 years ago
Thanks for the info. I added a fix for this and some other fixes for a stack 
overflow warning and a program hang when closing down.
I've only tested it on 3.8 though.
I'll see if I can get set up so I can do some testing on 3.12 as well.

Original comment by jcheetham19 on 26 Aug 2014 at 7:22

GoogleCodeExporter commented 8 years ago
I installed Ubuntu 14.04 and tested pychess. The strange thing is it's working 
OK for me. I didn't even get the error described in post #4 which I expected to 
get because I haven't fixed Main.py yet. So I'm not sure why I don't get the 
same result as you.

I tested with a clean install (no previous settings/engines). I ran from within 
the source folder using ./pychess command. I selected opponent as Human from 
the combo box and clicked 'start game' and I could play a game OK.

I did get this error on the terminal but it didn't affect the running of the 
game:

john@stealth:~/dev/pychess/pygi1/jcheetham19-pychess-pygi$ ./pychess
Warning: eco.db not find, run pgn2ecodb.sh
/usr/lib/python2.7/dist-packages/gi/types.py:259: RuntimeWarning: Mixin class 
pychess.widgets.ChatWindow.Panel is an old style class, please update this to 
derive from "object".
  RuntimeWarning)
Traceback (most recent call last):
  File "/home/john/dev/pychess/pygi1/jcheetham19-pychess-pygi/lib/pychess/widgets/gamenanny.py", line 254, in on_game_started
    gamemodel.start_analyzer(HINT)
  File "/home/john/dev/pychess/pygi1/jcheetham19-pychess-pygi/lib/pychess/Utils/GameModel.py", line 274, in start_analyzer
    analyzer = init_engine(analyzer_type, self)
  File "/home/john/dev/pychess/pygi1/jcheetham19-pychess-pygi/lib/pychess/Players/engineNest.py", line 448, in init_engine
    engine = anaengines[0]
IndexError: list index out of range

Original comment by jcheetham19 on 26 Aug 2014 at 2:13

GoogleCodeExporter commented 8 years ago
#10 was produced on my office box running Ubuntu 14.04.1 other bugs reported 
before was produced on my home box running UHU-Linux 3. It contains some newer 
packages (gtk/pygobject), as I mentioned before.

In all my previous tests I skipped startup engine discovery koz it seemed it 
doesn't progress, but today I was most patient and finally it was able to 
discover pychess own engine, so I was able to start a human-human game! 

Original comment by gbtami on 26 Aug 2014 at 6:12

GoogleCodeExporter commented 8 years ago
Yes it seems to depend on the version. I get the error in post #4 when I test 
on arch linux (32 bit virtualbox version). This has pygobject 3.12.2.
Anyway glad it works on ubuntu.

Original comment by jcheetham19 on 26 Aug 2014 at 7:02

GoogleCodeExporter commented 8 years ago
jcheetham19, great work! I successfully played a few moves in a Human vs. Human 
game with the attached patch to stop gstreamer from crashing and get sound 
working on Fedora 20.

Original comment by mattgatto on 27 Aug 2014 at 1:29

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks. Patch applied.

Original comment by jcheetham19 on 27 Aug 2014 at 6:45

GoogleCodeExporter commented 8 years ago
So as not to duplicate effort: I'm currently working on getting the FICS Lounge 
to work on this. Here's what I have so far.

Original comment by mattgatto on 27 Aug 2014 at 9:31

Attachments:

GoogleCodeExporter commented 8 years ago
jcheetham19, fixed #4 error in hg tip.

Original comment by gbtami on 27 Aug 2014 at 9:56

GoogleCodeExporter commented 8 years ago
Added those patches thanks.

I tried to add you as members to the clone so we can all commit. I can't see 
where I can add members or is that not possible on a clone?

One issue I have is that arena.py hangs. It discovers my engines (pychess and 
gnuchess) and starts the first match but it never finishes. If we can solve 
this it might make Human vs. engine work in the gui. I was going to look at it 
later but I think you can fix it quicker than me if you want to look at it.

Another thing was the colour schemes. In TaskerManager for example I tried 
replacing the pygtk code (get_style().bg[gtk.STATE_NORMAL])) with 
get_style_context().get_background_color(Gtk.StateFlags.NORMAL) but this just 
returns 0,0,0. I ended up hard coding the colour for now.

I will look at some menu stuff next starting with newgame dialog. 

Original comment by jcheetham19 on 28 Aug 2014 at 6:59

GoogleCodeExporter commented 8 years ago
I don't think you can add people to commit on clones.

Original comment by mattgatto on 29 Aug 2014 at 6:40

GoogleCodeExporter commented 8 years ago
Made preferences dialog work.

Original comment by gbtami on 29 Aug 2014 at 9:31

Attachments:

GoogleCodeExporter commented 8 years ago
Added thanks.

Original comment by jcheetham19 on 30 Aug 2014 at 6:32

GoogleCodeExporter commented 8 years ago
Some useful info about porting:
https://wiki.gnome.org/action/show/Projects/PyGObject/IntrospectionPorting?actio
n=show&redirect=PyGObject%2FIntrospectionPorting

Original comment by gbtami on 2 Sep 2014 at 12:50

GoogleCodeExporter commented 8 years ago
Thanks for the link.
I bookmarked these too.
Python GTK+ 3 Tutorial:
http://python-gtk-3-tutorial.readthedocs.org/en/latest/

GTK+ 3 Reference Manual (C but still useful for python)
https://developer.gnome.org/gtk3/stable/

I'll look at fixing human vs engine if nobody started it.

Original comment by jcheetham19 on 3 Sep 2014 at 7:08

GoogleCodeExporter commented 8 years ago
I'v just read the threading link 
(https://wiki.gnome.org/Projects/PyGObject/Threading), and it says "It is 
actually supported to call GTK+ from multiple threads, but this support is 
deprecated and will be removed eventually.", so seems we should switch to use 
idle_add() too.

Original comment by gbtami on 3 Sep 2014 at 8:32

GoogleCodeExporter commented 8 years ago
I'm already working on switching to idle_add and as it's not strictly needed to 
port pygi I wouldn't worry about it.

Original comment by mattgatto on 3 Sep 2014 at 8:08

GoogleCodeExporter commented 8 years ago
Renaming patch.

Original comment by gbtami on 4 Sep 2014 at 1:39

Attachments:

GoogleCodeExporter commented 8 years ago
Patch added thanks.

Original comment by jcheetham19 on 4 Sep 2014 at 5:09

GoogleCodeExporter commented 8 years ago
Python GObject Introspection API Reference: https://lazka.github.io/pgi-docs/

Fixed spy/hint arrows.

Original comment by gbtami on 4 Sep 2014 at 6:51

Attachments:

GoogleCodeExporter commented 8 years ago
Good link thanks.
Patch applied.

Original comment by jcheetham19 on 4 Sep 2014 at 8:29

GoogleCodeExporter commented 8 years ago
I don't have time right now to work on getting FICS to work, so if anyone wants 
to do so, their work won't overlap with mine.

Original comment by mattgatto on 5 Sep 2014 at 12:55

GoogleCodeExporter commented 8 years ago
We have to think about stock icons usage, because they are deprecated in gtk 
3.10 and not installed in 3.12, unless distro packagers save them somehow.

Original comment by gbtami on 7 Sep 2014 at 9:48

GoogleCodeExporter commented 8 years ago
John, I'v just added committer role to you. If you like you can create a named 
branch in the main repo, so you don't have to apply our patches again and again 
in the future.

Original comment by gbtami on 8 Sep 2014 at 7:47

GoogleCodeExporter commented 8 years ago
A short guide to branching: 
http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/

Original comment by gbtami on 8 Sep 2014 at 7:49

GoogleCodeExporter commented 8 years ago
Thanks. I'll look into creating named branches.

Original comment by jcheetham19 on 9 Sep 2014 at 7:18

GoogleCodeExporter commented 8 years ago
New pygi branch has been created.

Original comment by jcheetham19 on 12 Sep 2014 at 6:22

GoogleCodeExporter commented 8 years ago

Original comment by mattgatto on 28 Sep 2014 at 10:09

GoogleCodeExporter commented 8 years ago

Original comment by gbtami on 12 Oct 2014 at 12:23

GoogleCodeExporter commented 8 years ago
Thomas find an interesting post about new gtk-drawing:
"Regarding animation, we need something like 'repeat' but running on
the gtk thread. Perhaps gtk_widget_add_tick_callback is the modern way
to do this? At least that is recommended here
http://blogs.gnome.org/alexl/2013/11/04/the-modern-gtk-drawing-model/"

Original comment by gbtami on 21 Oct 2014 at 8:03

GoogleCodeExporter commented 8 years ago
jcheetham: What remains to be done to finish this?

Original comment by mattgatto on 29 Nov 2014 at 11:00

GoogleCodeExporter commented 8 years ago
I believe most things are working but I will mention a few things.

There was an issue with colours because you can't use things like
get_style.dark[gtk.state.selected] any more. Instead you should use
get_style_context. I set up some colours in Background.py which are
obtained from the theme. I then replaced the
get_style.dark[gtk.state.selected] type commands with lookup_color
commands which lookup the colours set up in Background.py. I don't know
if this was the best way to do it but it seems to work OK. I tested with
the default gnome3 Adwaita theme and with a couple of other themes I got
from http://gnome-look.org/ and the pygi version looks the same as the
pygtk version.

Another issue is that the digAHole routine in OverlayWindow.py is not
implemented. This doesn't seem to make a difference on gnome3 but if you
are using a system with a non compositing display then it means the star
arrows do not have transparent backgrounds when you move the windows
around. The problem is if you want to use shape_combine then you have to
use a Gdk.Region. For Python 2.x pycairo does not support/implement
cairo.Region(). See
https://bugs.launchpad.net/ubuntu/+source/pygobject/+bug/1028115/comments/8

I didn't look at stock icons (post #32). I found this link that says
they won't disappear until GTK version 4.0:
https://bugs.launchpad.net/ubuntu/+source/pygobject/+bug/1028115/comments/8

I tested mainly on CentOS7 (gtk 3.8.8) so there may be issues on newer
versions of GTK.

That's all I can think of. I'll post again if I remember any other
issues.

Original comment by jcheetham19 on 29 Nov 2014 at 8:53

GoogleCodeExporter commented 8 years ago
Thanks for the update. The stock icons issue we can deal with when we need to 
in the future by importing the icons we use into the project.

Apparently, even if we were using Python 3.x, we still wouldn't be able to 
create a cairo.Region(). Support was added to pycairo git ( 
https://bugs.freedesktop.org/show_bug.cgi?id=44336 and 
http://cgit.freedesktop.org/pycairo/commit/?id=75e82a1b3f495a3abbc78e50a5c66356d
320fb15 ), but they haven't had a release since that commit because pycairo is 
not maintained. pygobject already has support ready to go when pycairo does 
have a release ( https://bugzilla.gnome.org/show_bug.cgi?id=667959 ).

I tried to create a cairo.Region() using Python-3 and pygi on my Fedora 20 
system but couldn't so I filed 
https://bugzilla.redhat.com/show_bug.cgi?id=1170566

How many Desktop Environments these days aren't using compositing? Or don't 
have it on by default, like, apparently MATE: 
https://wiki.archlinux.org/index.php/MATE#Enabling_compositing ? I don't see a 
problem with just disabling digAHole() if it works on all major distributions 
with default settings, until pycairo and pygobject catch up.

Tamás, what do you think?

Original comment by mattgatto on 4 Dec 2014 at 1:34

GoogleCodeExporter commented 8 years ago
I'm using Xfce without any compositing, and never felt that I'm  missing 
transparency :)

Original comment by gbtami on 4 Dec 2014 at 2:46

GoogleCodeExporter commented 8 years ago
A couple of screenshots to illustrate the effect I'm getting.
Screenshot1 is on Arch virtualbox guest with compositing on.
Screenshot2 is with compositing off.
I turned it off in settings, window manager tweaks, compositor.

To get these I dragged the score tab down and then the star arrows appeared.
You can see in screenshot2 the non transparent background of the star arrow 
which obscures the annotation tab.

Original comment by jcheetham19 on 4 Dec 2014 at 7:54

Attachments:

GoogleCodeExporter commented 8 years ago
Should have mentioned this is on xfce.

Original comment by jcheetham19 on 4 Dec 2014 at 8:03

GoogleCodeExporter commented 8 years ago
Is compositing on by default in xfce or not?

Original comment by mattgatto on 4 Dec 2014 at 8:14

GoogleCodeExporter commented 8 years ago
@jcheetham19, On my Xfce laptop with compositing off I see the same as in 
screenshot 1.

@mattgatto, I don't know what is the default.

Original comment by gbtami on 5 Dec 2014 at 11:15

GoogleCodeExporter commented 8 years ago
1. With pygobject 3.12.2 I see some huge buttons on seek tab.
2. There are some unicode errors using non english locale.

Original comment by gbtami on 5 Dec 2014 at 11:23

Attachments:

GoogleCodeExporter commented 8 years ago
I get the UnicodeDecode errors on the english locale too.

Instead of stock icons we can use Gio.ThemedIcon's. I got this from 
http://python-gtk-3-tutorial.readthedocs.org/en/latest/layout.html#id5 :

icon = Gio.ThemedIcon(name="mail-send-receive-symbolic")
image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)

I think the network strength icons -- 
"network-cellular-signal-excellent-symbolic" for example -- would work well for 
the ICLounge rating strength icons.

Original comment by mattgatto on 7 Dec 2014 at 4:30

GoogleCodeExporter commented 8 years ago
These icons are, on my GNOME-3 system, located at
/usr/share/icons/gnome/scalable/status

Original comment by mattgatto on 7 Dec 2014 at 4:35