-
Notifications
You must be signed in to change notification settings - Fork 4
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
Port to Python3, Gtk3 and GLib #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,25 +21,28 @@ | |
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Frotz.activity. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import gi | ||
gi.require_version('Gtk', '3.0') | ||
gi.require_version('Vte', '2.91') | ||
import os | ||
import sys | ||
|
||
import logging | ||
from gettext import gettext as _ | ||
|
||
import gtk | ||
import gobject | ||
from gi.repository import Gtk, Gdk,GLib | ||
import dbus | ||
|
||
from sugar.activity import activity | ||
from sugar.activity import activityfactory | ||
from sugar import env | ||
from sugar.graphics.toolbutton import ToolButton | ||
from sugar.graphics.palette import Palette | ||
import ConfigParser | ||
from sugar3.activity import activity | ||
from sugar3.graphics.toolbarbox import ToolbarBox | ||
from sugar3.activity import activityfactory | ||
from sugar3 import env | ||
from sugar3.graphics.toolbutton import ToolButton | ||
from sugar3.graphics.palette import Palette | ||
import configparser | ||
import os.path | ||
import pango | ||
from gi.repository import Pango | ||
from gi.repository import Vte | ||
|
||
import platform, sys | ||
from ctypes import cdll | ||
|
@@ -48,13 +51,13 @@ | |
pass # FIXME | ||
else: | ||
if platform.architecture()[0] == '64bit': | ||
vte_path = "x86-64" | ||
vte_path = "x86_64" | ||
else: | ||
vte_path = "x86" | ||
vte = cdll.LoadLibrary("lib/%s/libvte.so.9" % vte_path) | ||
sys.path.append("lib/%s" % vte_path) | ||
vte = cdll.LoadLibrary("/usr/lib/"+vte_path+"-linux-gnu/libvte-2.91.so.0") | ||
sys.path.append("/usr/lib/"+vte_path+"-linux-gnu" ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason why you added this to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The activity was giving error before given in #4 in python2. The error is gone after changing . You can try this one also. by running on sugar-live-build. Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The activity was written to work with early versions of Fedora that did not have up to date VTE package. Newer VTE was in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And of course remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks I didn't know that. I thought the error was just related to not loading the required lib. So I just made necessary changes for working. I will take care about it further. |
||
|
||
|
||
import vte | ||
|
||
class FrotzActivity(activity.Activity): | ||
|
||
|
@@ -66,7 +69,7 @@ def __init__(self, handle): | |
self.set_title(_('Frotz')) | ||
self.connect('key-press-event', self.__key_press_cb) | ||
|
||
toolbox = activity.ActivityToolbox(self) | ||
toolbox = ToolbarBox() | ||
|
||
self._edit_toolbar = activity.EditToolbar() | ||
toolbox.add_toolbar(_('Edit'), self._edit_toolbar) | ||
|
@@ -91,13 +94,13 @@ def __init__(self, handle): | |
self.set_toolbox(toolbox) | ||
toolbox.show() | ||
|
||
box = gtk.HBox(False, 4) | ||
box = Gtk.HBox(False, 4) | ||
|
||
self._vte = VTE() | ||
self._vte.show() | ||
self._vte.connect("child-exited", self._quit_cb) | ||
|
||
scrollbar = gtk.VScrollbar(self._vte.get_adjustment()) | ||
scrollbar = Gtk.VScrollbar(self._vte.get_adjustment()) | ||
scrollbar.show() | ||
|
||
box.pack_start(self._vte) | ||
|
@@ -112,10 +115,10 @@ def __init__(self, handle): | |
default_game_file = os.path.join(activity.get_bundle_path(), "Advent.z5") | ||
# when we return to the idle state, launch the default game | ||
# if read_file is called, that will override this | ||
gobject.idle_add(self.start_game, default_game_file) | ||
GLib.idle_add(self.start_game, default_game_file) | ||
|
||
def _quit_cb(self, foo=None): | ||
print "Quitting..." | ||
print("Quitting...") | ||
sys.exit(0) | ||
|
||
def start_game(self, game_file): | ||
|
@@ -143,19 +146,19 @@ def read_file(self, file_path): | |
|
||
def open_url(self, url): | ||
"""Ask the journal to open an URL for us.""" | ||
from sugar import profile | ||
from sugar3 import profile | ||
from shutil import rmtree | ||
from sugar.datastore import datastore | ||
from sugar.activity.activity import show_object_in_journal | ||
from sugar3.datastore import datastore | ||
from sugar3.activity.activity import show_object_in_journal | ||
from tempfile import mkdtemp | ||
tmpfolder = mkdtemp('.tmp', 'url', os.path.join(self.get_activity_root(), 'instance')) | ||
tmpfilepath = os.path.join(tmpfolder, 'url') | ||
try: | ||
tmpfile = open(tmpfilepath, 'w') | ||
tmpfile.write(url) | ||
tmpfile.close() | ||
os.chmod(tmpfolder, 0755) | ||
os.chmod(tmpfilepath, 0755) | ||
os.chmod(tmpfolder, 0o755) | ||
os.chmod(tmpfilepath, 0o755) | ||
jobject = datastore.create() | ||
metadata = { | ||
'title': url, | ||
|
@@ -165,7 +168,7 @@ def open_url(self, url): | |
'icon-color': profile.get_color().to_string(), | ||
'mime_type': 'text/uri-list', | ||
} | ||
for k, v in metadata.items(): | ||
for k, v in list(metadata.items()): | ||
jobject.metadata[k] = v # the dict.update method is missing =( | ||
jobject.file_path = tmpfilepath | ||
datastore.write(jobject) | ||
|
@@ -187,28 +190,28 @@ def _paste_cb(self, button): | |
self._vte.paste_clipboard() | ||
|
||
def __key_press_cb(self, window, event): | ||
if event.state & gtk.gdk.CONTROL_MASK and event.state & gtk.gdk.SHIFT_MASK: | ||
if event.state & Gtk.gdk.CONTROL_MASK and event.state & Gtk.gdk.SHIFT_MASK: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an incomplete port, look for the correct method and make the necessary changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks I will take a look at these ones. |
||
|
||
if gtk.gdk.keyval_name(event.keyval) == "C": | ||
if Gtk.gdk.keyval_name(event.keyval) == "C": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This too. |
||
if self._vte.get_has_selection(): | ||
self._vte.copy_clipboard() | ||
return True | ||
elif gtk.gdk.keyval_name(event.keyval) == "V": | ||
elif Gtk.gdk.keyval_name(event.keyval) == "V": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this. |
||
self._vte.paste_clipboard() | ||
return True | ||
|
||
return False | ||
|
||
class VTE(vte.Terminal): | ||
class VTE(Vte.Terminal): | ||
def __init__(self): | ||
vte.Terminal.__init__(self) | ||
Vte.Terminal.__init__(self) | ||
self._configure_vte() | ||
|
||
#os.chdir(os.environ["HOME"]) | ||
self.fork_command() | ||
|
||
def _configure_vte(self): | ||
conf = ConfigParser.ConfigParser() | ||
conf = configparser.ConfigParser() | ||
conf_file = os.path.join(env.get_profile_path(), 'terminalrc') | ||
|
||
if os.path.isfile(conf_file): | ||
|
@@ -223,7 +226,7 @@ def _configure_vte(self): | |
else: | ||
font = 'Monospace 8' | ||
conf.set('terminal', 'font', font) | ||
self.set_font(pango.FontDescription(font)) | ||
self.set_font(Pango.FontDescription(font)) | ||
|
||
if conf.has_option('terminal', 'fg_color'): | ||
fg_color = conf.get('terminal', 'fg_color') | ||
|
@@ -235,8 +238,8 @@ def _configure_vte(self): | |
else: | ||
bg_color = '#FFFFFF' | ||
conf.set('terminal', 'bg_color', bg_color) | ||
self.set_colors(gtk.gdk.color_parse (fg_color), | ||
gtk.gdk.color_parse (bg_color), | ||
self.set_colors(Gtk.gdk.color_parse (fg_color), | ||
Gtk.gdk.color_parse (bg_color), | ||
Comment on lines
+241
to
+242
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this too. |
||
[]) | ||
|
||
if conf.has_option('terminal', 'cursor_blink'): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/python | ||
from sugar.activity import bundlebuilder | ||
bundlebuilder.start('Frotz') | ||
from sugar3.activity import bundlebuilder | ||
bundlebuilder.start() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular reason why you changed the bundle id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was giving bundle_id not found error when I tested with python2. But after making changes the error has gone. The activity was not starting before with python2. You can try this one on python2 by changing. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reasons not to change the bundle_id include;
~/Activities
as well as/usr/share/sugar/activities
,I don't think a bundle_id not found error is a correct reason to change the bundle_id. Next time that happens, try to diagnose why it happened rather than jumping to conclusions about the cause. 😁