Skip to content

Commit

Permalink
GTK3: Initial port work DOES NOT WORK
Browse files Browse the repository at this point in the history
This is the recovey of the pre-Git work on porting Virtaal to GTK3.

*************************************
**This does not work at the moment.**
*************************************

The biggest blocker was the missing GenericTreeModel that we use in the
translation editor.  This was not part of GTK introspection, but now with
pygobject 3.7.90[1], pygtkcompat adds support for GenerciTreModel.

Way forward:
1. I was using jhbuild, so that needs to be worked on to ensure that it builds
   again.
   - Putting the jhbuild config into the Virtaal repo would be a good thing.
     We already use jhbuild for Mac OS X building, and we could probably use it
     for Windows building.
2. Might want to actually abandon these changes and rerun the automatic porting
   scripts.
   - Since the scripts have been improved since I starte this I'm sure it would
     rewrite more then I did, I had to do a lot of manual conversion so these
     are of benefit now anyway.
3. Once we can build again just start plugging away at bugs.
   - Worked: With my build I got it to start, got the welcome screen and could
     open some of the config pages.
   - Didn't work: you can't open any translation files, nothing displayed
     because of missing GenericTreeModel, the custom settings pages didn't
     render well either.

Cautions:
- Might want to abandon all my virtaal.ui changes - these where made in an
  attempt to get some stuff rendering, the assumptions might be wrong.

Benefits (or why bother to do this):
- GTK3 is the way forward, so unless we port we won't benefit from new code.
  - This is important for ongoing Windows and Mac OS support for Virtaal.
  - Platforms like OLPC use it
  - I expect that in time, GTK2 will slowly disappear as a default install on
    various Linux distros.
- PyGTK is no longer the way forward for GTK and Python.
  - We can only get GTK3 if we port to pygobject at the same time. So we can't
    do one at a time we have to do both together.
- It allows us to experiment with GTK broadway, doing GTK on the web.
- It's a fun thing to hack

[1] http://ftp.gnome.org/pub/GNOME/sources/pygobject/3.7/pygobject-3.7.90.news
  • Loading branch information
dwaynebailey committed Mar 14, 2013
1 parent cb5307a commit 28cbcdd
Show file tree
Hide file tree
Showing 82 changed files with 1,174 additions and 1,117 deletions.
5 changes: 3 additions & 2 deletions bin/virtaal
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ if not packaged:
# We can't meaningfully report on these, and we build our own windows
# version, so let's leave this out for the benefit of startup time.
from virtaal.support import depcheck
optional_modules = ['enchant', 'gtkspell', 'psycopg2']
# FIXME need to investigate gtkspell for gtk3 support
optional_modules = ['enchant', 'psycopg2']
error_messages = {
'translate': 'Translate Toolkit >= %s is required for Virtaal to function.' % str(depcheck.MIN_TRANSLATE_VERSION),
'gtk': 'Gtk >= 2.12.0 and PyGTK is required for Virtaal to function.',
'gtk': 'Gtk >= 2.12.0 is required for Virtaal to function.',
'lxml.etree': 'LXML is required for XML-based format support as well as AutoCorrection.',
'json': 'SimpleJSON or Python >= 2.6 is required for certain TM back-ends.',
'pycurl': 'PyCurl is required for certain TM and terminology back-ends.',
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def add_win32_options(options):
"includes": [
# some of these are needed by plugins and are therefore not detected
"lxml", "lxml._elementpath", "psyco", "cairo", "pango",
"pangocairo", "atk", "gobject", "gtk.keysyms",
"pangocairo", "atk", "gobject", "Gdk.KEY_",
"gtkspell",
"tarfile",
"translate.storage.placeables.terminology", # terminology
Expand Down Expand Up @@ -516,7 +516,7 @@ def add_mac_options(options):
"options": {
"py2app": {
"packages": ["CoreFoundation", "objc"],
"includes": ["lxml", "lxml._elementpath", "lxml.etree", "glib", "gio", "psyco", "cairo", "pango", "pangocairo", "atk", "gobject", "gtk.keysyms", "pycurl", "translate.services", "translate.services.tmclient", "translate.services.opentranclient", "CoreFoundation"],
"includes": ["lxml", "lxml._elementpath", "lxml.etree", "glib", "gio", "psyco", "cairo", "pango", "pangocairo", "atk", "gobject", "Gdk.KEY_", "pycurl", "translate.services", "translate.services.tmclient", "translate.services.opentranclient", "CoreFoundation"],
#"semi_standalone": True,
"compressed": True,
"argv_emulation": True,
Expand Down
90 changes: 33 additions & 57 deletions share/virtaal/virtaal.ui

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion virtaal/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.

"""This file contains the version."""
ver = "0.7.1-rc1"
ver = "0.7.1-introspection"
14 changes: 7 additions & 7 deletions virtaal/common/gobjectwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

from gobject import GObject, signal_list_names
#import logging
from gi.repository import GObject
import logging


class GObjectWrapper(GObject):
class GObjectWrapper(GObject.GObject):
"""
A wrapper for GObject sub-classes that provides some more powerful signal-
handling.
"""

# INITIALIZERS #
def __init__(self):
GObject.__init__(self)
self._all_signals = signal_list_names(self.__gtype_name__)
GObject.GObject.__init__(self)
self._all_signals = GObject.signal_list_names(self.__gtype_name__)
self._enabled_signals = list(self._all_signals)


Expand All @@ -56,5 +56,5 @@ def enable_signals(self, signals=[]):

def emit(self, signame, *args):
if signame in self._enabled_signals:
#logging.debug('emit("%s", %s)' % (signame, ','.join([repr(arg) for arg in args])))
GObject.emit(self, signame, *args)
logging.debug('emit("%s", %s)' % (signame, ','.join([repr(arg) for arg in args])))
GObject.GObject.emit(self, signame, *args)
10 changes: 5 additions & 5 deletions virtaal/common/pan_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def get_default_font():

# First try and get the default font size from GConf
try:
import gconf
client = gconf.client_get_default()
client.add_dir('/desktop/gnome/interface', gconf.CLIENT_PRELOAD_NONE)
from gi.repository import GConf
client = GConf.Client.get_default()
client.add_dir('/desktop/gnome/interface', GConf.ClientPreloadType.PRELOAD_NONE)
font_name = client.get_string('/desktop/gnome/interface/monospace_font_name')
font_size = font_name.split(' ')[-1]
except ImportError, ie:
Expand All @@ -103,8 +103,8 @@ def get_default_font():

# Get the default font size from Gtk
if not font_size:
import gtk
font_name = str(gtk.Label().rc_get_style().font_desc)
from gi.repository import Gtk
font_name = str(Gtk.Label().rc_get_style().font_desc)
font_size = font_name.split(' ')[-1]

if font_size:
Expand Down
8 changes: 4 additions & 4 deletions virtaal/controllers/checkscontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.

import logging
from gobject import SIGNAL_RUN_FIRST, timeout_add
from gi.repository import GObject

from virtaal.common import GObjectWrapper

Expand Down Expand Up @@ -82,8 +82,8 @@ class ChecksController(BaseController):

__gtype_name__ = 'ChecksController'
__gsignals__ = {
'checker-set': (SIGNAL_RUN_FIRST, None, (object,)),
'unit-checked': (SIGNAL_RUN_FIRST, None, (object, object, object))
'checker-set': (GObject.SignalFlags.RUN_FIRST, None, (object,)),
'unit-checked': (GObject.SignalFlags.RUN_FIRST, None, (object, object, object))
}

CHECK_TIMEOUT = 500
Expand Down Expand Up @@ -207,7 +207,7 @@ def _start_check_timer(self):
# haven't changed units yet, probably strange timing issue
return
self._check_timer_active = True
timeout_add(self.CHECK_TIMEOUT, self._check_timer_expired, self.last_unit)
GObject.timeout_add(self.CHECK_TIMEOUT, self._check_timer_expired, self.last_unit)

def get_check_name(self, check):
"""Return the human readable form of the given check name."""
Expand Down
6 changes: 3 additions & 3 deletions virtaal/controllers/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.

import logging
from gobject import SIGNAL_RUN_FIRST
from gi.repository import GObject
from bisect import bisect_left

from virtaal.common import GObjectWrapper
Expand All @@ -36,8 +36,8 @@ class Cursor(GObjectWrapper):
__gtype_name__ = "Cursor"

__gsignals__ = {
"cursor-changed": (SIGNAL_RUN_FIRST, None, ()),
"cursor-empty": (SIGNAL_RUN_FIRST, None, ()),
"cursor-changed": (GObject.SignalFlags.RUN_FIRST, None, ()),
"cursor-empty": (GObject.SignalFlags.RUN_FIRST, None, ()),
}


Expand Down
6 changes: 3 additions & 3 deletions virtaal/controllers/langcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.

import os
from gobject import SIGNAL_RUN_FIRST
from gi.repository import GObject

from virtaal.common import GObjectWrapper, pan_app
from virtaal.models.langmodel import LanguageModel
Expand All @@ -34,8 +34,8 @@ class LanguageController(BaseController):

__gtype_name__ = 'LanguageController'
__gsignals__ = {
'source-lang-changed': (SIGNAL_RUN_FIRST, None, (str,)),
'target-lang-changed': (SIGNAL_RUN_FIRST, None, (str,)),
'source-lang-changed': (GObject.SignalFlags.RUN_FIRST, None, (str,)),
'target-lang-changed': (GObject.SignalFlags.RUN_FIRST, None, (str,)),
}

NUM_RECENT = 5
Expand Down
10 changes: 5 additions & 5 deletions virtaal/controllers/maincontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import logging
import os.path
import gtk
from gobject import SIGNAL_RUN_FIRST
from gi.repository import Gtk
from gi.repository import GObject

from virtaal.common import GObjectWrapper, pan_app
from virtaal.views.mainview import MainView
Expand All @@ -35,8 +35,8 @@ class MainController(BaseController):

__gtype_name__ = 'MainController'
__gsignals__ = {
'controller-registered': (SIGNAL_RUN_FIRST, None, (object,)),
'quit': (SIGNAL_RUN_FIRST, None, tuple()),
'controller-registered': (GObject.SignalFlags.RUN_FIRST, None, (object,)),
'quit': (GObject.SignalFlags.RUN_FIRST, None, tuple()),
}

# INITIALIZERS #
Expand Down Expand Up @@ -181,7 +181,7 @@ def open_file(self, filename=None, uri='', forget_dir=False):
# make it our problem and ensure the last ones are in the main
# controller.
while not self.placeables_controller:
gtk.main_iteration(False)
Gtk.main_iteration_do(False)
if filename is None:
return self.view.open_file()
if self.store_controller.is_modified():
Expand Down
5 changes: 3 additions & 2 deletions virtaal/controllers/modecontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

import gobject
from gi.repository import GObject

from virtaal.common import GObjectWrapper

Expand All @@ -37,7 +37,7 @@ class ModeController(BaseController):

__gtype_name__ = 'ModeController'
__gsignals__ = {
'mode-selected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,)),
'mode-selected': (GObject.SignalFlags.RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)),
}
default_mode_name = 'Default'

Expand Down Expand Up @@ -99,6 +99,7 @@ def select_mode(self, mode):

self.current_mode = mode
self._ignore_mode_change = True
# FIXME what when mode ia None? .name is undefined
self.view.select_mode(self.modenames[mode.name])
self._ignore_mode_change = False
self.view.show()
Expand Down
4 changes: 2 additions & 2 deletions virtaal/controllers/placeablescontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

import gobject
from gi.repository import GObject
from translate.storage.placeables import general, StringElem, parse as parse_placeables

from virtaal.common import pan_app, GObjectWrapper
Expand All @@ -32,7 +32,7 @@ class PlaceablesController(BaseController):

__gtype_name__ = 'PlaceablesController'
__gsignals__ = {
'parsers-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, tuple()),
'parsers-changed': (GObject.SignalFlags.RUN_FIRST, None, tuple()),
}

parsers = []
Expand Down
9 changes: 5 additions & 4 deletions virtaal/controllers/plugincontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import logging
import os
import sys
from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT, idle_add
from gi.repository import GObject
from gi.repository import GLib

from virtaal.common import pan_app, GObjectWrapper

Expand All @@ -43,8 +44,8 @@ class PluginController(BaseController):

__gtype_name__ = 'PluginController'
__gsignals__ = {
'plugin-enabled': (SIGNAL_RUN_FIRST, None, (TYPE_PYOBJECT,)),
'plugin-disabled': (SIGNAL_RUN_FIRST, None, (TYPE_PYOBJECT,)),
'plugin-enabled': (GObject.SignalFlags.RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)),
'plugin-disabled': (GObject.SignalFlags.RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)),
}

# The following class variables are set for the main plug-in controller.
Expand Down Expand Up @@ -138,7 +139,7 @@ def load_plugins(self):
if name in disabled_plugins:
continue
# We use idle_add(), so that the UI will respond sooner
idle_add(self.enable_plugin, name)
GLib.idle_add(self.enable_plugin, name)
logging.info('Queued all plugins for loading')

def shutdown(self):
Expand Down
10 changes: 5 additions & 5 deletions virtaal/controllers/storecontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

import gobject
from gi.repository import GObject
import logging
import os
import shutil
Expand All @@ -36,9 +36,9 @@ class StoreController(BaseController):

__gtype_name__ = 'StoreController'
__gsignals__ = {
'store-loaded': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()),
'store-saved': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()),
'store-closed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()),
'store-loaded': (GObject.SignalFlags.RUN_FIRST, None, ()),
'store-saved': (GObject.SignalFlags.RUN_FIRST, None, ()),
'store-closed': (GObject.SignalFlags.RUN_FIRST, None, ()),
}

# INITIALIZERS #
Expand Down Expand Up @@ -139,7 +139,7 @@ def get_store_checks(self):

def get_unit_celleditor(self, unit):
"""Load the given unit in via the C{UnitController} and return
the C{gtk.CellEditable} it creates."""
the C{Gtk.CellEditable} it creates."""
return self.unit_controller.load_unit(unit)

def is_modified(self):
Expand Down
13 changes: 7 additions & 6 deletions virtaal/controllers/undocontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

import gobject
import gtk
from gtk import gdk
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import Gdk
from translate.storage.placeables import StringElem

from virtaal.common import GObjectWrapper, pan_app
Expand Down Expand Up @@ -69,9 +70,9 @@ def _setup_key_bindings(self):
This method *may* need to be moved into a view object, but if it is,
it will be the only functionality in such a class. Therefore, it
is done here. At least for now."""
gtk.accel_map_add_entry("<Virtaal>/Edit/Undo", gtk.keysyms.z, gdk.CONTROL_MASK)
Gtk.AccelMap.add_entry("<Virtaal>/Edit/Undo", Gdk.KEY_z, Gdk.ModifierType.CONTROL_MASK)

self.accel_group = gtk.AccelGroup()
self.accel_group = Gtk.AccelGroup()
# The following line was commented out, because it caused a double undo when pressing
# Ctrl+Z, but only one if done through the menu item. This way it all works as expected.
#self.accel_group.connect_by_path("<Virtaal>/Edit/Undo", self._on_undo_activated)
Expand Down Expand Up @@ -166,7 +167,7 @@ def _perform_undo(self, undo_info):
def refresh():
textbox.refresh_cursor_pos = undo_info['cursorpos']
textbox.refresh()
gobject.idle_add(refresh)
GLib.idle_add(refresh)

def _select_unit(self, unit):
"""Select the given unit in the store view.
Expand Down
14 changes: 7 additions & 7 deletions virtaal/controllers/unitcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

from gobject import SIGNAL_RUN_FIRST, timeout_add
from gi.repository import GObject
from translate.storage import workflow

from virtaal.common import GObjectWrapper
Expand All @@ -31,11 +31,11 @@ class UnitController(BaseController):

__gtype_name__ = "UnitController"
__gsignals__ = {
'unit-done': (SIGNAL_RUN_FIRST, None, (object, int)),
'unit-modified': (SIGNAL_RUN_FIRST, None, (object,)),
'unit-delete-text': (SIGNAL_RUN_FIRST, None, (object, object, object, int, int, object, int)),
'unit-insert-text': (SIGNAL_RUN_FIRST, None, (object, object, int, object, int)),
'unit-paste-start': (SIGNAL_RUN_FIRST, None, (object, object, object, int)),
'unit-done': (GObject.SignalFlags.RUN_FIRST, None, (object, int)),
'unit-modified': (GObject.SignalFlags.RUN_FIRST, None, (object,)),
'unit-delete-text': (GObject.SignalFlags.RUN_FIRST, None, (object, object, object, int, int, object, int)),
'unit-insert-text': (GObject.SignalFlags.RUN_FIRST, None, (object, object, int, object, int)),
'unit-paste-start': (GObject.SignalFlags.RUN_FIRST, None, (object, object, object, int)),
}

STATE_TIMEOUT = 200
Expand Down Expand Up @@ -188,7 +188,7 @@ def _start_state_timer(self):
if self._state_timer_active:
return
self._state_timer_active = True
timeout_add(self.STATE_TIMEOUT, self._state_timer_expired, self.current_unit)
GObject.timeout_add(self.STATE_TIMEOUT, self._state_timer_expired, self.current_unit)

def prepare_for_save(self):
"""Finalise outstanding changes to the toolkit store for saving."""
Expand Down
4 changes: 2 additions & 2 deletions virtaal/controllers/welcomescreencontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def __init__(self, main_controller):
def activate(self):
"""Show the welcome screen and trigger activation logic (ie. find
recent files)."""
from gobject import idle_add
idle_add(self.update_recent)
from gi.repository import GLib
GLib.idle_add(self.update_recent)
self.view.show()

def open_cheatsheat(self):
Expand Down

0 comments on commit 28cbcdd

Please sign in to comment.