Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert from PyGTK to PyGObject #20

Merged
merged 52 commits into from
Sep 23, 2018
Merged

Convert from PyGTK to PyGObject #20

merged 52 commits into from
Sep 23, 2018

Conversation

danyeaw
Copy link
Member

@danyeaw danyeaw commented Jul 23, 2018

Conversion from PyGTK to PyGObject (and Gtk+ 2 to 3). Steps taken include:

  1. Automatic rename using pygi-convert.sh to do basic find and replace between PyGTK and PyGObject syntax.
  2. Fixed some additional Python 3 compatibility cleanups with ez_setup and the tests
  3. Completed manual updates to finish the conversion, including the largest update which was to replace the scroll adjustment signals to inherit from Gtk.Scrollable

All tests pass with both Python 2.7.15 and 3.7.0.

Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
@wrobell
Copy link
Collaborator

wrobell commented Aug 10, 2018

I would remove use of old_div. 99% of time the division is between floats. There are few exceptions where you might need integer division operator, but they should be easy to spot.

@danyeaw
Copy link
Member Author

danyeaw commented Aug 12, 2018

@wrobell I agree that we might be safe to remove old_div, but despite being really ugly to look at, I would prefer to wait until we have Gaphas tested in a working Gtk3 and PyGObject app prior to changing it. I'm working hard to be as conservative as possible because the conversion is already changing so much at once.

@danyeaw
Copy link
Member Author

danyeaw commented Aug 30, 2018

@wrobell Thanks for helping to fix another error! It looks like there is still more work to do to get the DrawingArea to show up. I did run it using the master branch with Python 2.7, so I see now the behavior the demo is supposed to have. 👍

@wrobell
Copy link
Collaborator

wrobell commented Aug 30, 2018

Another possible fix:

diff --git a/gaphas/aspect.py b/gaphas/aspect.py
index fe695d4..0314471 100644
--- a/gaphas/aspect.py
+++ b/gaphas/aspect.py
@@ -140,22 +140,24 @@ HandleSelection = generic(ItemHandleSelection)
 @HandleSelection.when_type(Element)
 class ElementHandleSelection(ItemHandleSelection):
     CURSORS = (
-        Gdk.CursorType.TOP_LEFT_CORNER,
-        Gdk.CursorType.TOP_RIGHT_CORNER,
-        Gdk.CursorType.BOTTOM_RIGHT_CORNER,
-        Gdk.CursorType.BOTTOM_LEFT_CORNER,
+        'nw-resize',
+        'ne-resize',
+        'se-resize',
+        'sw-resize',
     )
 
     def select(self):
         index = self.item.handles().index(self.handle)
         if index < 4:
-            self.view.window.set_cursor(self.CURSORS[index])
+            display = self.get_display()
+            cursor = Gdk.Cursor.new_from_name(display, CURSORS[index])
+            self.view.get_window().set_cursor(cursor)
 
     def unselect(self):
         from .view import DEFAULT_CURSOR
 
         cursor = Gdk.Cursor(DEFAULT_CURSOR)
-        self.view.window.set_cursor(cursor)
+        self.view.get_window().set_cursor(cursor)
 
 
 
diff --git a/gaphas/tool.py b/gaphas/tool.py
index 4cc8b82..48830e2 100644
--- a/gaphas/tool.py
+++ b/gaphas/tool.py
@@ -686,7 +686,7 @@ class TextEditTool(Tool):
         window.set_property('decorated', False)
         window.set_resize_mode(Gtk.ResizeMode.IMMEDIATE)
         #window.set_modal(True)
-        window.set_parent_window(self.view.window)
+        window.set_parent_window(self.view.get_window())
         buffer = Gtk.TextBuffer()
         text_view = Gtk.TextView()
         text_view.set_buffer(buffer)

Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
@danyeaw
Copy link
Member Author

danyeaw commented Aug 31, 2018

@wrobell Thanks for the help on that one as well 👍
We are getting closer, I'm now not getting errors all over the place when running the demo. Next we need to figure out why the DrawingArea isn't being displayed.

In Python 3.7 I'm also getting an error that I'm not in 2.7, on line 243 of view.py:

        if item.point((ix, iy)) < 0.5:
            return item

The item.point method is just a "pass" function, so it returns a NoneType. Python 3.7 is flagging this as a TypeError for comparing a NoneType and a float. Anyone know what the history of this get_item_at_point method is, it seems like it would never work since measuring the distance from the item to the point is non-functional.

@amolenaar
Copy link
Member

@danyeaw Is it a pass-function only in the Item class? I would expect the subclasses to override this method.

Disclaimer: I have not checked the code on this one.

@danyeaw
Copy link
Member Author

danyeaw commented Aug 31, 2018

@amolenaar Got it, I missed that the item could also be an element or line as well, thanks for pointing me in the right direction. 👍

Signed-off-by: Dan Yeaw <dan@yeaw.me>
@danyeaw
Copy link
Member Author

danyeaw commented Sep 10, 2018

I am getting closer. The GtkView is now visible, but it is very narrow and it doesn't get larger through allocation when the window is resized.

@wrobell
Copy link
Collaborator

wrobell commented Sep 10, 2018

One more issue to be solved:

diff --git a/gaphas/guide.py b/gaphas/guide.py
index b9da308..a4c5080 100644
--- a/gaphas/guide.py
+++ b/gaphas/guide.py
@@ -307,7 +307,7 @@ class GuidePainter(ItemPaintFocused):
 
         cr = context.cairo
         view = self.view
-        allocation = view.allocation
+        allocation = view.get_allocation()
         w, h = allocation.width, allocation.height
 
         cr.save()

Removes the following error when resizing a box

AttributeError: 'GtkView' object has no attribute 'allocation'

Signed-off-by: Dan Yeaw <dan@yeaw.me>
@danyeaw
Copy link
Member Author

danyeaw commented Sep 11, 2018

Thanks @wrobell!

@danyeaw
Copy link
Member Author

danyeaw commented Sep 13, 2018

If I override the do_size_allocate allocation, I can get a window that looks closer to what I was expecting:

--- gaphas/view.py	(revision 28a3382b5a6cee296090f47c307c909586ff8bad)
+++ gaphas/view.py	(date 1536803890000)
@@ -822,10 +822,14 @@
         """
         Allocate the widget size ``(x, y, width, height)``.
         """
-        Gtk.DrawingArea.do_size_allocate(self, allocation)
-        self.set_allocation(allocation)
-        self.update_adjustments(allocation)
-        self._qtree.resize((0, 0, allocation.width, allocation.height))
+        print(allocation.width, allocation.height)
+        alloc = Gdk.Rectangle()
+        alloc.width = 500
+        alloc.height = 500
+        Gtk.DrawingArea.do_size_allocate(self, alloc)
+        self.set_allocation(alloc)
+        self.update_adjustments(alloc)
+        self._qtree.resize((0, 0, alloc.width, alloc.height))
 
     def on_size_allocate(self, widget, allocation):
         pass

I'm not sure why the allocation.width being passed to the do_size_allocate method is only 15.

screenshot from 2018-09-12 22-08-35

Signed-off-by: Dan Yeaw <dan@yeaw.me>
@danyeaw
Copy link
Member Author

danyeaw commented Sep 14, 2018

It's working 👍 I had to override the ScrolledWindow to tell it to horizontally expand.
screenshot from 2018-09-13 22-30-13

@amolenaar
Copy link
Member

Nice. This looks like the demo app I once built :D :shipit:

Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
Signed-off-by: Dan Yeaw <dan@yeaw.me>
@danyeaw danyeaw merged commit 7e4c8a2 into gaphor:master Sep 23, 2018
@danyeaw danyeaw deleted the pygobject-conservative branch September 23, 2018 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants