[gnome-games/gnome-3-0] sudoku: Auto convert with pygi-convert.sh
- From: Thomas Hindoe Paaboel Andersen <thomashpa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/gnome-3-0] sudoku: Auto convert with pygi-convert.sh
- Date: Fri, 20 May 2011 21:14:56 +0000 (UTC)
commit 49b79b6d8de06cfda0826385d2ee3b08b6357857
Author: Thomas Hindoe Paaboel Andersen <phomes gmail com>
Date: Sat Apr 2 13:06:59 2011 +0200
sudoku: Auto convert with pygi-convert.sh
gnome-sudoku/src/gnome-sudoku.in.in | 6 +-
gnome-sudoku/src/lib/dancer.py | 18 ++--
gnome-sudoku/src/lib/dialog_swallower.py | 24 ++--
gnome-sudoku/src/lib/game_selector.py | 22 ++--
gnome-sudoku/src/lib/gsudoku.py | 62 +++++-----
gnome-sudoku/src/lib/gtk_goodies/Undo.py | 30 +++---
gnome-sudoku/src/lib/gtk_goodies/dialog_extras.py | 80 +++++++-------
gnome-sudoku/src/lib/gtk_goodies/gconf_wrapper.py | 4 +-
gnome-sudoku/src/lib/main.py | 114 +++++++++---------
gnome-sudoku/src/lib/number_box.py | 128 ++++++++++----------
gnome-sudoku/src/lib/printing.py | 28 +++---
gnome-sudoku/src/lib/saver.py | 10 +-
gnome-sudoku/src/lib/sudoku.py | 2 +-
gnome-sudoku/src/lib/sudoku_thumber.py | 12 +-
gnome-sudoku/src/lib/timer.py | 16 ++--
15 files changed, 278 insertions(+), 278 deletions(-)
---
diff --git a/gnome-sudoku/src/gnome-sudoku.in.in b/gnome-sudoku/src/gnome-sudoku.in.in
index 0ebc9c6..e210b5e 100644
--- a/gnome-sudoku/src/gnome-sudoku.in.in
+++ b/gnome-sudoku/src/gnome-sudoku.in.in
@@ -49,7 +49,7 @@ except ImportError:
except ImportError:
# Import of gnome-sudoku failed. Show error message.
- import gtk
+ from gi.repository import Gtk
import os.path
import gettext
from gettext import gettext as _
@@ -58,9 +58,9 @@ except ImportError:
gettext.textdomain('gnome-games')
title = _("Sudoku incorrectly installed")
description = _("""Sudoku is not able to start because required application files are not installed. If you are currently upgrading your system please wait until the upgrade has completed.""")
- dialog = gtk.MessageDialog(type = gtk.MESSAGE_ERROR, message_format = title)
+ dialog = Gtk.MessageDialog(type = Gtk.MessageType.ERROR, message_format = title)
dialog.format_secondary_text(description)
- dialog.add_button(gtk.STOCK_QUIT, gtk.RESPONSE_CLOSE)
+ dialog.add_button(Gtk.STOCK_QUIT, Gtk.ResponseType.CLOSE)
dialog.run()
sys.exit(0)
diff --git a/gnome-sudoku/src/lib/dancer.py b/gnome-sudoku/src/lib/dancer.py
index c885fe3..2ae5c8f 100644
--- a/gnome-sudoku/src/lib/dancer.py
+++ b/gnome-sudoku/src/lib/dancer.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-import gtk
+from gi.repository import Gtk
import gobject
import colors
@@ -41,9 +41,9 @@ class GridDancer:
box.need_restore = True
else:
box.need_restore = False
- self.grid.get_toplevel().child_focus(gtk.DIR_TAB_BACKWARD)
+ self.grid.get_toplevel().child_focus(Gtk.DIR_TAB_BACKWARD)
self.dancing = True
- gobject.timeout_add(350, self.dance_grid)
+ GObject.timeout_add(350, self.dance_grid)
def stop_dancing (self):
self.dancing = False
@@ -107,7 +107,7 @@ class GridDancer:
if __name__ == '__main__':
def test_dance_grid ():
import gsudoku
- window = gtk.Window()
+ window = Gtk.Window()
game = '''9 1 6 3 2 8 4 5 7
5 7 4 6 1 9 2 8 3
8 3 2 5 7 4 9 6 1
@@ -120,19 +120,19 @@ if __name__ == '__main__':
gsd = gsudoku.SudokuGameDisplay(game)
dancer = GridDancer(gsd)
- button = gtk.Button('toggle')
+ button = Gtk.Button('toggle')
button.connect('clicked',
lambda *args: dancer.stop_dancing() if dancer.dancing
else dancer.start_dancing())
- vbox = gtk.VBox()
- vbox.pack_start(gsd)
+ vbox = Gtk.VBox()
+ vbox.pack_start(gsd, True, True, 0)
vbox.pack_end(button)
vbox.set_focus_child(button)
window.add(vbox)
window.show_all()
- window.connect('delete-event', gtk.main_quit)
- gtk.main()
+ window.connect('delete-event', Gtk.main_quit)
+ Gtk.main()
test_dance_grid()
diff --git a/gnome-sudoku/src/lib/dialog_swallower.py b/gnome-sudoku/src/lib/dialog_swallower.py
index ed103ec..28d0d3c 100644
--- a/gnome-sudoku/src/lib/dialog_swallower.py
+++ b/gnome-sudoku/src/lib/dialog_swallower.py
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
-import gtk
+from gi.repository import Gtk
# Convenience library for a new kind of UI -- for e.g. this game, we
# don't really want to have dialogs. Nonetheless, it's convenient to
# design dialogs in gtkbuilder and run them in the standard manner... So we
# create a new "dialog" interface via a hidden notebook.
-class SwappableArea (gtk.Notebook):
+class SwappableArea (Gtk.Notebook):
swallowed = {}
@@ -15,13 +15,13 @@ class SwappableArea (gtk.Notebook):
def __init__ (self, main_area):
- gtk.Notebook.__init__(self)
+ GObject.GObject.__init__(self)
self.set_show_tabs(False)
self.set_show_border(False)
self.main_page = self.append_page(main_area)
def swallow_window (self, d):
- child = d.child
+ child = d.get_child()
d.remove(child)
return self.swallow_widget(child)
@@ -30,7 +30,7 @@ class SwappableArea (gtk.Notebook):
return self.append_page(w)
def response_cb (self, w, response, data=None):
- gtk.main_quit()
+ Gtk.main_quit()
self.response = response
def swallow_dialog (self, d):
@@ -45,7 +45,7 @@ class SwappableArea (gtk.Notebook):
self.swallow_dialog(d)
self.set_current_page(self.swallowed[d])
try:
- gtk.main()
+ Gtk.main()
except:
print 'Error in dialog!'
import traceback
@@ -61,17 +61,17 @@ class SwappableArea (gtk.Notebook):
if __name__ == '__main__':
- d = gtk.Dialog()
- d.vbox.add(gtk.Label('Foo, bar, baz'))
+ d = Gtk.Dialog()
+ d.vbox.add(Gtk.Label('Foo, bar, baz'))
d.vbox.show_all()
- d.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
- w = gtk.Window()
- b = gtk.Button('show d')
+ d.add_button(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
+ w = Gtk.Window()
+ b = Gtk.Button('show d')
b.show()
sa = SwappableArea(b)
sa.show()
w.add(sa)
b.connect_object('clicked', sa.run_dialog, d)
w.show()
- gtk.main()
+ Gtk.main()
diff --git a/gnome-sudoku/src/lib/game_selector.py b/gnome-sudoku/src/lib/game_selector.py
index db6fe90..e7d8996 100644
--- a/gnome-sudoku/src/lib/game_selector.py
+++ b/gnome-sudoku/src/lib/game_selector.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-import gtk
+from gi.repository import Gtk
import gobject
import os.path
import sudoku, saver, sudoku_maker
@@ -63,11 +63,11 @@ class NewOrSavedGameSelector:
self.saved_games = None
def setup_dialog (self):
- builder = gtk.Builder()
+ builder = Gtk.Builder()
builder.set_translation_domain(defaults.DOMAIN)
builder.add_from_file(self.ui_file)
self.dialog = builder.get_object('dialog1')
- self.dialog.set_default_response(gtk.RESPONSE_CANCEL)
+ self.dialog.set_default_response(Gtk.ResponseType.CANCEL)
self.dialog.connect('close', self.close)
self.dialog.hide()
saved_game_frame = builder.get_object('savedGameFrame')
@@ -97,7 +97,7 @@ class NewOrSavedGameSelector:
w.hide()
else:
saved_game_frame.show()
- self.saved_game_model.set_sort_column_id(2, gtk.SORT_DESCENDING)
+ self.saved_game_model.set_sort_column_id(2, Gtk.SortType.DESCENDING)
saved_game_view.set_model(self.saved_game_model)
saved_game_view.set_markup_column(0)
saved_game_view.set_pixbuf_column(1)
@@ -105,7 +105,7 @@ class NewOrSavedGameSelector:
view.set_item_width(150)
view.set_columns(4)
view.set_spacing(12)
- view.set_selection_mode(gtk.SELECTION_SINGLE)
+ view.set_selection_mode(Gtk.SelectionMode.SINGLE)
saved_game_view.connect('item-activated', self.saved_item_activated_cb)
saved_game_view.connect('button-release-event', self.item_clicked_cb)
new_game_view.connect('item-activated', self.new_item_activated_cb)
@@ -114,7 +114,7 @@ class NewOrSavedGameSelector:
@simple_debug
def make_new_game_model (self):
# Description, Pixbuf, Puzzle (str)
- self.new_game_model = gtk.ListStore(str, gtk.gdk.Pixbuf, str)
+ self.new_game_model = Gtk.ListStore(str, GdkPixbuf.Pixbuf, str)
saved_games_to_exclude = [
g['game'].split('\n')[0] for g in self.saved_games
]
@@ -180,7 +180,7 @@ class NewOrSavedGameSelector:
@simple_debug
def make_saved_game_model (self):
# Description, Image, Last-Access time (for sorting), Puzzle (jar)
- self.saved_game_model = gtk.ListStore(str, gtk.gdk.Pixbuf, int, gobject.TYPE_PYOBJECT)
+ self.saved_game_model = Gtk.ListStore(str, GdkPixbuf.Pixbuf, int, GObject.TYPE_PYOBJECT)
for g in self.saved_games:
game = g['game'].split('\n')[0]
grid = sudoku.sudoku_grid_from_string(game)
@@ -249,20 +249,20 @@ class NewOrSavedGameSelector:
@simple_debug
def resume_game (self, jar):
self.puzzle = (self.SAVED_GAME, jar)
- self.dialog.emit('response', gtk.RESPONSE_OK)
+ self.dialog.emit('response', Gtk.ResponseType.OK)
@simple_debug
def play_game (self, puzzle):
self.puzzle = (self.NEW_GAME, puzzle)
- self.dialog.emit('response', gtk.RESPONSE_OK)
+ self.dialog.emit('response', Gtk.ResponseType.OK)
@simple_debug
def close (self):
- self.dialog.emit('response', gtk.RESPONSE_CLOSE)
+ self.dialog.emit('response', Gtk.ResponseType.CLOSE)
@simple_debug
def handle_response (self, response):
- if response == gtk.RESPONSE_OK:
+ if response == Gtk.ResponseType.OK:
return self.puzzle
else:
return None
diff --git a/gnome-sudoku/src/lib/gsudoku.py b/gnome-sudoku/src/lib/gsudoku.py
index 87388fe..6135e7d 100644
--- a/gnome-sudoku/src/lib/gsudoku.py
+++ b/gnome-sudoku/src/lib/gsudoku.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-import gtk
+from gi.repository import Gtk
import gobject
import colors
import math
@@ -14,10 +14,10 @@ def gtkcolor_to_rgb (color):
color.green / float(2**16),
color.blue / float(2**16))
-class SudokuNumberGrid (gtk.AspectFrame):
+class SudokuNumberGrid (Gtk.AspectFrame):
def __init__ (self, group_size = 9):
- self.table = gtk.Table(rows = group_size, columns = group_size, homogeneous = True)
+ self.table = Gtk.Table(rows = group_size, columns = group_size, homogeneous = True)
self.group_size = group_size
self.__entries__ = {}
for x in range(self.group_size):
@@ -28,9 +28,9 @@ class SudokuNumberGrid (gtk.AspectFrame):
self.table.attach(e, x, x+1, y, y+1,
)
self.__entries__[(x, y)] = e
- gtk.AspectFrame.__init__(self, obey_child = False)
- self.set_shadow_type(gtk.SHADOW_NONE)
- self.eb = gtk.EventBox()
+ GObject.GObject.__init__(self, obey_child = False)
+ self.set_shadow_type(Gtk.ShadowType.NONE)
+ self.eb = Gtk.EventBox()
self.eb.add(self.table)
self.add(self.eb)
self.table.set_row_spacings(1)
@@ -56,24 +56,24 @@ class SudokuNumberGrid (gtk.AspectFrame):
def set_bg_color (self, color):
if type(color) == str:
try:
- color = gtk.gdk.color_parse(color)
+ color = Gdk.color_parse(color)
except:
print 'set_bg_color handed Bad color', color
return
- self.eb.modify_bg(gtk.STATE_NORMAL, color)
- self.eb.modify_base(gtk.STATE_NORMAL, color)
- self.eb.modify_fg(gtk.STATE_NORMAL, color)
- self.table.modify_bg(gtk.STATE_NORMAL, color)
- self.table.modify_base(gtk.STATE_NORMAL, color)
- self.table.modify_fg(gtk.STATE_NORMAL, color)
+ self.eb.modify_bg(Gtk.StateType.NORMAL, color)
+ self.eb.modify_base(Gtk.StateType.NORMAL, color)
+ self.eb.modify_fg(Gtk.StateType.NORMAL, color)
+ self.table.modify_bg(Gtk.StateType.NORMAL, color)
+ self.table.modify_base(Gtk.StateType.NORMAL, color)
+ self.table.modify_fg(Gtk.StateType.NORMAL, color)
for e in self.__entries__.values():
- e.modify_bg(gtk.STATE_NORMAL, color)
+ e.modify_bg(Gtk.StateType.NORMAL, color)
-class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
+class SudokuGameDisplay (SudokuNumberGrid, GObject.GObject):
__gsignals__ = {
- 'focus-changed':(gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
- 'puzzle-finished':(gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
+ 'focus-changed':(GObject.SignalFlags.RUN_LAST, None, ()),
+ 'puzzle-finished':(GObject.SignalFlags.RUN_LAST, None, ())
}
do_highlight_cells = False
@@ -90,7 +90,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
self.impossibilities = []
self.trackers = {}
self.tinfo = tracker_info.TrackerInfo()
- gobject.GObject.__init__(self)
+ GObject.GObject.__init__(self)
SudokuNumberGrid.__init__(self, group_size = group_size)
self.setup_grid(grid, group_size)
for e in self.__entries__.values():
@@ -102,7 +102,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
self.connect('focus-changed', self.highlight_cells)
def key_press_cb (self, widget, event):
- key = gtk.gdk.keyval_name(event.keyval)
+ key = Gdk.keyval_name(event.keyval)
dest = self.go_around(widget.x, widget.y, key)
if dest:
self.table.set_focus_child(self.__entries__[dest])
@@ -130,7 +130,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
def get_highlight_colors (self):
entry = self.__entries__.values()[0]
- default_color = gtkcolor_to_rgb(entry.style.bg[gtk.STATE_SELECTED])
+ default_color = gtkcolor_to_rgb(entry.style.bg[Gtk.StateType.SELECTED])
hsv = colors.rgb_to_hsv(*default_color)
box_s = hsv[1]
box_v = hsv[2]
@@ -203,7 +203,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
def set_hint_square (self, square):
if self.hint_square is not None:
self.hint_square.set_border_color(None)
- gobject.source_remove(self.hint_timer)
+ GObject.source_remove(self.hint_timer)
self.hint_timer = None
if square is None:
@@ -212,7 +212,7 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
self.hint_square = self.__entries__[square]
self.hint_animate_count = 0
self.animate_hint()
- self.hint_timer = gobject.timeout_add(150, self.animate_hint)
+ self.hint_timer = GObject.timeout_add(150, self.animate_hint)
@simple_debug
def show_hint (self):
@@ -737,8 +737,8 @@ class SudokuGameDisplay (SudokuNumberGrid, gobject.GObject):
self.update_all_hints()
if __name__ == '__main__':
- window = gtk.Window()
- window.connect('delete-event', gtk.main_quit)
+ window = Gtk.Window()
+ window.connect('delete-event', Gtk.main_quit)
def test_number_grid ():
t = SudokuNumberGrid(4)
@@ -760,17 +760,17 @@ if __name__ == '__main__':
from dialog_swallower import SwappableArea
sgd = SudokuGameDisplay()
sgd.set_bg_color('black')
- vb = gtk.VBox()
- hb = gtk.HBox()
+ vb = Gtk.VBox()
+ hb = Gtk.HBox()
swallower = SwappableArea(hb)
- tb = gtk.Toolbar()
- b = gtk.ToolButton(stock_id = gtk.STOCK_QUIT)
- b.connect('clicked', lambda x: window.hide() or gtk.main_quit())
+ tb = Gtk.Toolbar()
+ b = Gtk.ToolButton(stock_id = Gtk.STOCK_QUIT)
+ b.connect('clicked', lambda x: window.hide() or Gtk.main_quit())
tb.add(b)
def run_swallowed_dialog (*args):
md = MessageDialog(title = "Bar", label = "Bar", sublabel = "Baz "*12)
swallower.run_dialog(md)
- b2 = gtk.ToolButton(label = 'Dialog')
+ b2 = Gtk.ToolButton(label = 'Dialog')
b2.connect('clicked', run_swallowed_dialog)
tb.add(b2)
vb.pack_start(tb, fill = False, expand = False)
@@ -811,4 +811,4 @@ if __name__ == '__main__':
# reproduce_foobared_rendering()
test_sudoku_game()
window.show_all()
- gtk.main()
+ Gtk.main()
diff --git a/gnome-sudoku/src/lib/gtk_goodies/Undo.py b/gnome-sudoku/src/lib/gtk_goodies/Undo.py
index 382f9e9..c724be5 100644
--- a/gnome-sudoku/src/lib/gtk_goodies/Undo.py
+++ b/gnome-sudoku/src/lib/gtk_goodies/Undo.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-import gtk
+from gi.repository import Gtk
import difflib,re
DEBUG=False
def debug (*args,**kwargs):
@@ -304,8 +304,8 @@ class UndoHistoryList (list):
w.set_sensitive(val)
debug('%s.set_sensitive succeeded'%w,0)
except AttributeError:
- # 2.6 will give gtk.Action a set_sensitive property, but for now...
- #if type(w)==gtk.Action:
+ # 2.6 will give Gtk.Action a set_sensitive property, but for now...
+ #if type(w)==Gtk.Action:
for p in w.get_proxies():
debug('setting %s sensitivity to %s'%(w,val),0)
#p.set_sensitive(val)
@@ -331,7 +331,7 @@ class UndoHistoryList (list):
debug('Sensitizing "reapply" widgets',0)
self.set_sensitive(self.reapply_widget,True)
if self[-1].reapply_name:
- if type(self.reapply_widget)==gtk.MenuItem:
+ if type(self.reapply_widget)==Gtk.MenuItem:
alabel = self.reapply_widget.get_children()[0]
alabel.set_text_with_mnemonic(self[-1].reapply_name)
alabel.set_use_markup(True)
@@ -442,15 +442,15 @@ if __name__ == '__main__':
#while txt:
# txt = raw_input('Text: ')
# history[-1].add_text(txt)
- import gtk
- w = gtk.Window()
- e = gtk.Entry()
- tv = gtk.TextView()
- ub = gtk.Button(stock=gtk.STOCK_UNDO)
- rb = gtk.Button(stock=gtk.STOCK_REDO)
- sc = gtk.Button('show changes')
- vb = gtk.VBox()
- bb = gtk.HButtonBox()
+ from gi.repository import Gtk
+ w = Gtk.Window()
+ e = Gtk.Entry()
+ tv = Gtk.TextView()
+ ub = Gtk.Button(stock=Gtk.STOCK_UNDO)
+ rb = Gtk.Button(stock=Gtk.STOCK_REDO)
+ sc = Gtk.Button('show changes')
+ vb = Gtk.VBox()
+ bb = Gtk.HButtonBox()
bb.add(ub)
bb.add(rb)
bb.add(sc)
@@ -462,13 +462,13 @@ if __name__ == '__main__':
UndoableTextView(tv,uhl)
UndoableEntry(e,uhl)
w.show_all()
- w.connect('delete-event',lambda *args:gtk.main_quit())
+ w.connect('delete-event',lambda *args:Gtk.main_quit())
def show_changes (*args):
for c in uhl:
print c,' initial: ',c.initial_text,' current: ',c.text
ub.connect('clicked',lambda *args: debug('Undo clicked!',0))
sc.connect('clicked',show_changes)
rb.connect('clicked',lambda *args: debug('Redo clicked!',0))
- gtk.main()
+ Gtk.main()
diff --git a/gnome-sudoku/src/lib/gtk_goodies/dialog_extras.py b/gnome-sudoku/src/lib/gtk_goodies/dialog_extras.py
index 224093a..cde8679 100644
--- a/gnome-sudoku/src/lib/gtk_goodies/dialog_extras.py
+++ b/gnome-sudoku/src/lib/gtk_goodies/dialog_extras.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-import gtk
+from gi.repository import Gtk
import xml.sax.saxutils
from gettext import gettext as _
H_PADDING=12
@@ -8,7 +8,7 @@ Y_PADDING=12
class UserCancelledError (Exception):
pass
-class ModalDialog (gtk.Dialog):
+class ModalDialog (Gtk.Dialog):
def __init__ (self, default=None, title="", okay=True, label=False, sublabel=False, parent=None, cancel=True, modal=True, expander=None, image=None):
"""Our basic class. We allow for a label. Possibly an expander
with extra information, and a simple Okay button. The
@@ -22,11 +22,11 @@ class ModalDialog (gtk.Dialog):
self.set_border_width(15)
self.default = default
self.ret = default
- self.responses = {gtk.RESPONSE_OK:self.okcb,
- gtk.RESPONSE_CANCEL:self.cancelcb,
- gtk.RESPONSE_NONE:self.cancelcb,
- gtk.RESPONSE_CLOSE:self.cancelcb,
- gtk.RESPONSE_DELETE_EVENT:self.cancelcb}
+ self.responses = {Gtk.ResponseType.OK:self.okcb,
+ Gtk.ResponseType.CANCEL:self.cancelcb,
+ Gtk.ResponseType.NONE:self.cancelcb,
+ Gtk.ResponseType.CLOSE:self.cancelcb,
+ Gtk.ResponseType.DELETE_EVENT:self.cancelcb}
if modal: self.set_modal(True)
if label:
self.setup_label(label)
@@ -43,38 +43,38 @@ class ModalDialog (gtk.Dialog):
self.vbox.show_all()
def setup_dialog (self, *args, **kwargs):
- gtk.Dialog.__init__(self, *args, **kwargs)
+ GObject.GObject.__init__(self, *args, **kwargs)
def setup_label (self, label):
# we're going to add pango markup to our
# label to make it bigger as per GNOME HIG
label = '<span weight="bold" size="larger">%s</span>'%label
- self.label = gtk.Label()
+ self.label = Gtk.Label()
self.label.set_line_wrap(True)
self.label.set_selectable(True)
self.vbox.pack_start(self.label,expand=False)
self.label.set_padding(H_PADDING,Y_PADDING)
self.label.set_alignment(0,0)
- self.label.set_justify(gtk.JUSTIFY_LEFT)
+ self.label.set_justify(Gtk.Justification.LEFT)
self.label.ste_markup(label)
self.label.show()
def setup_sublabel (self,sublabel):
- self.sublabel = gtk.Label()
+ self.sublabel = Gtk.Label()
self.sublabel.set_selectable(True)
- self.vbox.pack_start(self.sublabel, expand=False)
+ self.vbox.pack_start(self.sublabel, False, True, 0)
self.sublabel.set_padding(H_PADDING,Y_PADDING)
self.sublabel.set_alignment(0,0)
- self.sublabel.set_justify(gtk.JUSTIFY_LEFT)
+ self.sublabel.set_justify(Gtk.Justification.LEFT)
self.sublabel.set_markup(sublabel)
self.sublabel.set_line_wrap(True)
self.sublabel.show()
def setup_buttons (self, cancel, okay):
if cancel:
- self.add_button(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL)
+ self.add_button(Gtk.STOCK_CANCEL,Gtk.ResponseType.CANCEL)
if okay:
- self.add_button(gtk.STOCK_OK,gtk.RESPONSE_OK)
+ self.add_button(Gtk.STOCK_OK,Gtk.ResponseType.OK)
self.connect('response',self.response_cb)
def response_cb (self, dialog, response, *params):
@@ -88,9 +88,9 @@ class ModalDialog (gtk.Dialog):
def setup_expander (self, expander):
label=expander[0]
body = expander[1]
- self.expander = gtk.Expander(label)
+ self.expander = Gtk.Expander(label)
self.expander.set_use_underline(True)
- self.expander_vbox = gtk.VBox()
+ self.expander_vbox = Gtk.VBox()
self.expander.add(self.expander_vbox)
self._add_expander_item(body)
self.expander.show()
@@ -99,7 +99,7 @@ class ModalDialog (gtk.Dialog):
def _add_expander_item (self, item):
if type(item)==type(""):
- l=gtk.Label(item)
+ l=Gtk.Label(label=item)
l.set_selectable(True)
l.set_line_wrap(True)
self.expander_vbox.pack_start(l,
@@ -108,29 +108,29 @@ class ModalDialog (gtk.Dialog):
elif type(item)==[] or type(item)==():
map(self._add_expander_item,item)
else:
- self.expander_vbox.pack_start(item)
+ self.expander_vbox.pack_start(item, True, True, 0)
def run (self):
self.show()
if self.widget_that_grabs_focus: self.widget_that_grabs_focus.grab_focus()
- if self.modal: gtk.main()
+ if self.modal: Gtk.main()
return self.ret
def okcb (self, *args):
self.hide()
- if self.modal: gtk.main_quit()
+ if self.modal: Gtk.main_quit()
def cancelcb (self, *args):
self.hide()
self.ret=None
- if self.modal: gtk.main_quit()
+ if self.modal: Gtk.main_quit()
-class MessageDialog (gtk.MessageDialog, ModalDialog):
+class MessageDialog (Gtk.MessageDialog, ModalDialog):
"""A simple class for displaying messages to our users."""
def __init__ (self, title="", default=None, okay=True, cancel=False, label=False, sublabel=False,
- expander=None, message_type=gtk.MESSAGE_INFO, icon=None, parent=None):
+ expander=None, message_type=Gtk.MessageType.INFO, icon=None, parent=None):
self.message_type=message_type
self.icon = icon
ModalDialog.__init__(self, title=title, default=default, okay=okay, cancel=cancel, label=label, sublabel=sublabel, parent=parent, expander=expander)
@@ -139,7 +139,7 @@ class MessageDialog (gtk.MessageDialog, ModalDialog):
kwargs['type']=self.message_type
if kwargs.has_key('title'):
del kwargs['title']
- gtk.MessageDialog.__init__(self, *args, **kwargs)
+ GObject.GObject.__init__(self, *args, **kwargs)
if self.icon:
if type(self.icon)==str:
self.image.set_from_file(self.icon)
@@ -159,14 +159,14 @@ class BooleanDialog (MessageDialog):
sublabel=False, cancel=True,
parent=None, custom_yes=None, custom_no=None, expander=None,
dont_ask_cb=None, dont_ask_custom_text=None,
- cancel_returns=None, message_type=gtk.MESSAGE_QUESTION
+ cancel_returns=None, message_type=Gtk.MessageType.QUESTION
):
"""Setup a BooleanDialog which returns True or False.
parent is our parent window.
custom_yes is custom text for the button that returns true or a dictionary
- to be handed to gtk.Button as keyword args.
+ to be handed to Gtk.Button as keyword args.
custom_no is custom text for the button that returns False or a dictionary
- to be handed to gtk.Button as keyword args
+ to be handed to Gtk.Button as keyword args
expander is a list whose first item is a label and second is a widget to be packed
into an expander widget with more information.
if dont_ask_variable is set, a Don't ask me again check
@@ -175,30 +175,30 @@ class BooleanDialog (MessageDialog):
dont_ask_custom_text is custom don't ask text."""
self.cancel_returns = cancel_returns
self.yes,self.no = custom_yes,custom_no
- if not self.yes: self.yes = gtk.STOCK_YES
- if not self.no: self.no = gtk.STOCK_NO
+ if not self.yes: self.yes = Gtk.STOCK_YES
+ if not self.no: self.no = Gtk.STOCK_NO
MessageDialog.__init__(self,title=title,okay=False,label=label, cancel=cancel, sublabel=sublabel,parent=parent, expander=expander, message_type=message_type)
- self.responses[gtk.RESPONSE_YES]=self.yescb
- self.responses[gtk.RESPONSE_NO]=self.nocb
+ self.responses[Gtk.ResponseType.YES]=self.yescb
+ self.responses[Gtk.ResponseType.NO]=self.nocb
if not cancel:
# if there's no cancel, all cancel-like actions
# are the equivalent of a NO response
- self.responses[gtk.RESPONSE_NONE]=self.nocb
- self.responses[gtk.RESPONSE_CANCEL]=self.nocb
- self.responses[gtk.RESPONSE_CLOSE]=self.nocb
- self.responses[gtk.RESPONSE_DELETE_EVENT]=self.nocb
+ self.responses[Gtk.ResponseType.NONE]=self.nocb
+ self.responses[Gtk.ResponseType.CANCEL]=self.nocb
+ self.responses[Gtk.ResponseType.CLOSE]=self.nocb
+ self.responses[Gtk.ResponseType.DELETE_EVENT]=self.nocb
if dont_ask_cb:
if not dont_ask_custom_text:
dont_ask_custom_text=_("Don't ask me this again.")
- self.dont_ask = gtk.CheckButton(dont_ask_custom_text)
+ self.dont_ask = Gtk.CheckButton(dont_ask_custom_text)
self.dont_ask.connect('toggled',dont_ask_cb)
self.vbox.add(self.dont_ask)
self.dont_ask.show()
def setup_buttons (self, cancel, okay):
MessageDialog.setup_buttons(self,cancel,None)
- self.add_button(self.no,gtk.RESPONSE_NO)
- self.add_button(self.yes,gtk.RESPONSE_YES)
+ self.add_button(self.no,Gtk.ResponseType.NO)
+ self.add_button(self.yes,Gtk.ResponseType.YES)
def yescb (self, *args):
self.ret=True
@@ -210,7 +210,7 @@ class BooleanDialog (MessageDialog):
self.okcb()
else:
self.hide()
- if self.modal: gtk.main_quit()
+ if self.modal: Gtk.main_quit()
def nocb (self, *args):
self.ret=False
diff --git a/gnome-sudoku/src/lib/gtk_goodies/gconf_wrapper.py b/gnome-sudoku/src/lib/gtk_goodies/gconf_wrapper.py
index 1693eae..ef7cd7b 100644
--- a/gnome-sudoku/src/lib/gtk_goodies/gconf_wrapper.py
+++ b/gnome-sudoku/src/lib/gtk_goodies/gconf_wrapper.py
@@ -3,7 +3,7 @@
# COPIED VERBATIM FROM http://www.daa.com.au/pipermail/pygtk/2002-August/003220.html
# by Johan Dahlin
-import gconf
+from gi.repository import GConf
from gconf import VALUE_BOOL, VALUE_INT, VALUE_STRING, VALUE_FLOAT
from types import StringType, IntType, FloatType, BooleanType
@@ -17,7 +17,7 @@ class GConfWrap:
def __init__ (self, appname, allowed={}):
self._domain = '/apps/%s/' % appname
self._allowed = allowed
- self._gconf_client = gconf.client_get_default ()
+ self._gconf_client = GConf.Client.get_default ()
def __getitem__ (self, attr):
return self.get_value (attr)
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index 1f4ccd5..b6133b8 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
try:
import pygtk
- pygtk.require('2.0')
+ pyGtk.require('2.0')
except ImportError, err:
print ("PyGTK not found. Please make sure it is installed properly and referenced in your PYTHONPATH environment variable.")
@@ -9,8 +9,8 @@ import os.path
import threading
import gobject
-import gtk
-import pango
+from gi.repository import Gtk
+from gi.repository import Pango
from gettext import gettext as _
from gettext import ngettext
@@ -27,20 +27,20 @@ from defaults import (APPNAME, APPNAME_SHORT, AUTHORS, COPYRIGHT, DESCRIPTION, D
from gtk_goodies import gconf_wrapper, Undo, dialog_extras
from simple_debug import simple_debug, options
-ICON_FACTORY = gtk.IconFactory()
+ICON_FACTORY = Gtk.IconFactory()
STOCK_PIXBUFS = {}
for filename, stock_id in [('footprints.png', 'tracks'), ]:
try:
- pb = gtk.gdk.pixbuf_new_from_file(os.path.join(IMAGE_DIR, filename))
- except gobject.GError, e:
+ pb = GdkPixbuf.Pixbuf.new_from_file(os.path.join(IMAGE_DIR, filename))
+ except GObject.GError, e:
print 'Failed to load pixbuf: %s' % e
continue
STOCK_PIXBUFS[stock_id] = pb
- iconset = gtk.IconSet(pb)
+ iconset = Gtk.IconSet(pb)
ICON_FACTORY.add(stock_id, iconset)
ICON_FACTORY.add_default()
-gtk.stock_add([('tracks',
+Gtk.stock_add([('tracks',
_('Track moves'),
0, 0, ""), ])
@@ -176,7 +176,7 @@ class UI (gconf_wrapper.GConfWrapper):
self.quit = False
# Generate puzzles in background...
- gobject.timeout_add_seconds(1, lambda *args: self.start_worker_thread() and True)
+ GObject.timeout_add_seconds(1, lambda *args: self.start_worker_thread() and True)
@inactivate_new_game_etc
def select_game (self):
@@ -217,43 +217,43 @@ class UI (gconf_wrapper.GConfWrapper):
self.setup_toggles()
def setup_main_window (self):
- gtk.window_set_default_icon_name('gnome-sudoku')
- self.w = gtk.Window()
+ Gtk.Window.set_default_icon_name('gnome-sudoku')
+ self.w = Gtk.Window()
self.w.set_default_size(self.gconf['width'], self.gconf['height'])
self.w.set_title(APPNAME_SHORT)
self.w.connect('configure-event', self.resize_cb)
self.w.connect('delete-event', self.quit_cb)
- self.uimanager = gtk.UIManager()
+ self.uimanager = Gtk.UIManager()
def setup_actions (self):
- self.main_actions = gtk.ActionGroup('MainActions')
+ self.main_actions = Gtk.ActionGroup('MainActions')
self.main_actions.add_actions([
('Game', None, _('_Game')),
- ('New', gtk.STOCK_NEW, None, '<Control>n', _('New game'), self.new_cb),
- ('Reset', gtk.STOCK_CLEAR, _('_Reset'), '<Control>b',
+ ('New', Gtk.STOCK_NEW, None, '<Control>n', _('New game'), self.new_cb),
+ ('Reset', Gtk.STOCK_CLEAR, _('_Reset'), '<Control>b',
None, self.game_reset_cb),
- ('Undo', gtk.STOCK_UNDO, _('_Undo'), '<Control>z',
+ ('Undo', Gtk.STOCK_UNDO, _('_Undo'), '<Control>z',
_('Undo last action'), self.stop_dancer),
- ('Redo', gtk.STOCK_REDO, _('_Redo'), '<Shift><Control>z',
+ ('Redo', Gtk.STOCK_REDO, _('_Redo'), '<Shift><Control>z',
_('Redo last action')),
- ('PuzzleInfo', gtk.STOCK_ABOUT, _('Puzzle _Statistics...'), None,
+ ('PuzzleInfo', Gtk.STOCK_ABOUT, _('Puzzle _Statistics...'), None,
None, self.show_info_cb),
- ('Print', gtk.STOCK_PRINT, _('_Print...'), '<Control>p', None, self.print_game),
- ('PrintMany', gtk.STOCK_PRINT, _('Print _Multiple Sudokus...'), None,
+ ('Print', Gtk.STOCK_PRINT, _('_Print...'), '<Control>p', None, self.print_game),
+ ('PrintMany', Gtk.STOCK_PRINT, _('Print _Multiple Sudokus...'), None,
None, self.print_multiple_games),
- ('Close', gtk.STOCK_CLOSE, None, '<Control>w', None, self.quit_cb),
+ ('Close', Gtk.STOCK_CLOSE, None, '<Control>w', None, self.quit_cb),
('Settings', None, _('_Settings')),
- ('FullScreen', gtk.STOCK_FULLSCREEN, None, 'F11', None, self.full_screen_cb),
+ ('FullScreen', Gtk.STOCK_FULLSCREEN, None, 'F11', None, self.full_screen_cb),
('Tools', None, _('_Tools')),
- ('ShowPossible', gtk.STOCK_DIALOG_INFO, _('_Hint'), '<Control>h',
+ ('ShowPossible', Gtk.STOCK_DIALOG_INFO, _('_Hint'), '<Control>h',
_('Show a square that is easy to fill.'), self.show_hint_cb),
('ClearTopNotes', None, _('Clear _Top Notes'), '<Control>j',
None, self.clear_top_notes_cb),
('ClearBottomNotes', None, _('Clear _Bottom Notes'), '<Control>k',
None, self.clear_bottom_notes_cb),
('Help', None, _('_Help'), None, None, None),
- ('ShowHelp', gtk.STOCK_HELP, _('_Contents'), 'F1', None, self.show_help),
- ('About', gtk.STOCK_ABOUT, None, None, None, self.show_about),
+ ('ShowHelp', Gtk.STOCK_HELP, _('_Contents'), 'F1', None, self.show_help),
+ ('About', Gtk.STOCK_ABOUT, None, None, None, self.show_about),
])
self.main_actions.add_toggle_actions([
('AlwaysShowPossible',
@@ -273,7 +273,7 @@ class UI (gconf_wrapper.GConfWrapper):
_('Mark new additions in a separate color so you can keep track of them.'),
self.tracker_toggle_cb, False),
('ToggleToolbar', None, _('Show _Toolbar'), None, None, self.toggle_toolbar_cb, True),
- ('ToggleHighlight', gtk.STOCK_SELECT_COLOR, _('_Highlighter'),
+ ('ToggleHighlight', Gtk.STOCK_SELECT_COLOR, _('_Highlighter'),
None, _('Highlight the current row, column and box'), self.toggle_highlight_cb, False)
])
@@ -312,24 +312,24 @@ class UI (gconf_wrapper.GConfWrapper):
self.gsd.set_bg_color(bgcol)
def setup_autosave (self):
- gobject.timeout_add_seconds(self.gconf['auto_save_interval'] or 60, # in seconds...
+ GObject.timeout_add_seconds(self.gconf['auto_save_interval'] or 60, # in seconds...
self.autosave)
def setup_main_boxes (self):
- self.vb = gtk.VBox()
+ self.vb = Gtk.VBox()
# Add menu bar and toolbar...
mb = self.uimanager.get_widget('/MenuBar')
mb.show()
self.vb.pack_start(mb, fill = False, expand = False)
self.tb = self.uimanager.get_widget('/Toolbar')
self.vb.pack_start(self.tb, fill = False, expand = False)
- self.main_area = gtk.HBox()
+ self.main_area = Gtk.HBox()
self.swallower = dialog_swallower.SwappableArea(self.main_area)
self.swallower.show()
self.vb.pack_start(self.swallower, True, padding = 12)
self.main_area.pack_start(self.gsd, padding = 6)
self.main_actions.set_visible(True)
- self.game_box = gtk.VBox()
+ self.game_box = Gtk.VBox()
self.main_area.show()
self.vb.show()
self.game_box.show()
@@ -483,27 +483,27 @@ class UI (gconf_wrapper.GConfWrapper):
and self.gsd.grid.is_changed()
and (not self.won)):
self.save_game(self)
- if gtk.main_level() > 1:
+ if Gtk.main_level() > 1:
# If we are in an embedded mainloop, that means that one
# of our "swallowed" dialogs is active, in which case we
# have to quit that mainloop before we can quit
# properly.
if self.swallower.running:
d = self.swallower.running
- d.response(gtk.RESPONSE_DELETE_EVENT)
- gtk.main_quit() # Quit the embedded mainloop
- gobject.idle_add(self.quit_cb, 100) # Call ourselves again
+ d.response(Gtk.ResponseType.DELETE_EVENT)
+ Gtk.main_quit() # Quit the embedded mainloop
+ GObject.idle_add(self.quit_cb, 100) # Call ourselves again
# to quit the main
# mainloop
return
# make sure we really go away before doing our saving --
# otherwise we appear sluggish.
- while gtk.events_pending():
- gtk.main_iteration()
+ while Gtk.events_pending():
+ Gtk.main_iteration()
self.stop_worker_thread()
# allow KeyboardInterrupts, which calls quit_cb outside the main loop
try:
- gtk.main_quit()
+ Gtk.main_quit()
except RuntimeError:
pass
@@ -694,7 +694,7 @@ class UI (gconf_wrapper.GConfWrapper):
@simple_debug
def show_about (self, *args):
- about = gtk.AboutDialog()
+ about = Gtk.AboutDialog()
about.set_transient_for(self.w)
about.set_name(APPNAME)
about.set_version(VERSION)
@@ -713,8 +713,8 @@ class UI (gconf_wrapper.GConfWrapper):
@simple_debug
def show_help (self, *args):
try:
- gtk.show_uri(self.w.get_screen(), "ghelp:gnome-sudoku", gtk.get_current_event_time())
- except gobject.GError, error:
+ Gtk.show_uri(self.w.get_screen(), "ghelp:gnome-sudoku", Gtk.get_current_event_time())
+ except GObject.GError, error:
# FIXME: This should create a pop-up dialog
print _('Unable to display help: %s') % str(error)
@@ -727,13 +727,13 @@ class UI (gconf_wrapper.GConfWrapper):
gp = printing.GamePrinter(self.sudoku_maker, self.gconf)
gp.run_dialog()
-class TrackerBox (gtk.VBox):
+class TrackerBox (Gtk.VBox):
@simple_debug
def __init__ (self, main_ui):
- gtk.VBox.__init__(self)
- self.builder = gtk.Builder()
+ GObject.GObject.__init__(self)
+ self.builder = Gtk.Builder()
self.builder.set_translation_domain(DOMAIN)
self.builder.add_from_file(os.path.join(UI_DIR, 'tracker.ui'))
self.main_ui = main_ui
@@ -758,12 +758,12 @@ class TrackerBox (gtk.VBox):
@simple_debug
def setup_tree (self):
self.tracker_tree = self.builder.get_object('TrackerTreeView')
- self.tracker_model = gtk.ListStore(int, gtk.gdk.Pixbuf, str)
- self.tracker_model.set_sort_column_id(0, gtk.SORT_ASCENDING)
+ self.tracker_model = Gtk.ListStore(int, GdkPixbuf.Pixbuf, str)
+ self.tracker_model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
self.tracker_tree.set_model(self.tracker_model)
- col1 = gtk.TreeViewColumn("", gtk.CellRendererPixbuf(), pixbuf = 1)
- rend = gtk.CellRendererText()
- col2 = gtk.TreeViewColumn("", rend, text = 2)
+ col1 = Gtk.TreeViewColumn("", Gtk.CellRendererPixbuf(), pixbuf = 1)
+ rend = Gtk.CellRendererText()
+ col2 = Gtk.TreeViewColumn("", rend, text = 2)
col2.set_cell_data_func(rend, self.draw_tracker_name)
self.tracker_tree.append_column(col2)
self.tracker_tree.append_column(col1)
@@ -777,22 +777,22 @@ class TrackerBox (gtk.VBox):
@simple_debug
def setup_actions (self):
- self.tracker_actions = gtk.ActionGroup('tracker_actions')
+ self.tracker_actions = Gtk.ActionGroup('tracker_actions')
self.tracker_actions.add_actions(
[('Remove',
- gtk.STOCK_CLEAR,
+ Gtk.STOCK_CLEAR,
_('_Remove'),
None, _('Delete selected tracker.'),
self.remove_tracker_cb
),
('Hide',
- gtk.STOCK_CLEAR,
+ Gtk.STOCK_CLEAR,
_('H_ide'),
None, _('Hide current tracker entries.'),
self.hide_tracker_cb
),
('Apply',
- gtk.STOCK_APPLY,
+ Gtk.STOCK_APPLY,
_('A_pply'),
None, _('Apply all tracked values and remove the tracker.'),
self.apply_tracker_cb
@@ -812,9 +812,9 @@ class TrackerBox (gtk.VBox):
def draw_tracker_name(self, column, cell, model, iter):
if model.get_value(iter, 0) == self.tinfo.showing_tracker:
- cell.set_property('weight', pango.WEIGHT_BOLD)
+ cell.set_property('weight', Pango.Weight.BOLD)
else:
- cell.set_property('weight', pango.WEIGHT_NORMAL)
+ cell.set_property('weight', Pango.Weight.NORMAL)
@simple_debug
def add_tracker (self, *args, **keys):
@@ -847,7 +847,7 @@ class TrackerBox (gtk.VBox):
pixbuf_str_new += chr(int(color[2]*255))
pixbuf_str_new += alpha
- return gtk.gdk.pixbuf_new_from_data(pixbuf_str_new, gtk.gdk.COLORSPACE_RGB, True, 8,
+ return GdkPixbuf.Pixbuf.new_from_data(pixbuf_str_new, GdkPixbuf.Colorspace.RGB, True, 8,
pixbuf.get_width(), pixbuf.get_height(), pixbuf.get_rowstride())
@simple_debug
@@ -1011,7 +1011,7 @@ def start_game ():
## You must call g_thread_init() before executing any other GLib
## functions in a threaded GLib program.
- gobject.threads_init()
+ GObject.threads_init()
if options.profile:
options.profile = False
@@ -1021,7 +1021,7 @@ def start_game ():
u = UI()
if not u.quit:
try:
- gtk.main()
+ Gtk.main()
except KeyboardInterrupt:
# properly quit on a keyboard interrupt...
u.quit_cb()
diff --git a/gnome-sudoku/src/lib/number_box.py b/gnome-sudoku/src/lib/number_box.py
index 2b3073e..a47937f 100644
--- a/gnome-sudoku/src/lib/number_box.py
+++ b/gnome-sudoku/src/lib/number_box.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
#!/usr/bin/python
-import gtk
+from gi.repository import Gtk
import gobject
-import pango
+from gi.repository import Pango
import cairo
import math
import tracker_info
@@ -15,35 +15,35 @@ BASE_SIZE = 35 # The "normal" size of a box (in pixels)
# And the standard font-sizes -- these should fit nicely with the
# BASE_SIZE
-BASE_FONT_SIZE = pango.SCALE * 13
-NOTE_FONT_SIZE = pango.SCALE * 6
+BASE_FONT_SIZE = Pango.SCALE * 13
+NOTE_FONT_SIZE = Pango.SCALE * 6
BORDER_WIDTH = 9.0 # The size of space we leave for a box
NORMAL_LINE_WIDTH = 1 # The size of the line we draw around a box
-class NumberSelector (gtk.EventBox):
+class NumberSelector (Gtk.EventBox):
__gsignals__ = {
- 'changed':(gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
+ 'changed':(GObject.SignalFlags.RUN_LAST, None, ()),
}
def __init__ (self, default = None, upper = 9):
self.value = default
- gtk.EventBox.__init__(self)
- self.table = gtk.Table()
+ GObject.GObject.__init__(self)
+ self.table = Gtk.Table()
self.add(self.table)
side = int(math.sqrt(upper))
n = 1
for y in range(side):
for x in range(side):
- b = gtk.Button()
- l = gtk.Label()
+ b = Gtk.Button()
+ l = Gtk.Label()
if n == self.value:
l.set_markup('<b><span size="x-small">%s</span></b>'%n)
else:
l.set_markup('<span size="x-small">%s</span>'%n)
b.add(l)
- b.set_relief(gtk.RELIEF_HALF)
+ b.set_relief(Gtk.ReliefStyle.HALF)
l = b.get_children()[0]
b.set_border_width(0)
l.set_padding(0, 0)
@@ -52,8 +52,8 @@ class NumberSelector (gtk.EventBox):
self.table.attach(b, x, x+1, y, y+1)
n += 1
if self.value:
- db = gtk.Button()
- l = gtk.Label()
+ db = Gtk.Button()
+ l = Gtk.Label()
l.set_markup_with_mnemonic('<span size="x-small">'+_('_Clear')+'</span>')
db.add(l)
l.show()
@@ -71,7 +71,7 @@ class NumberSelector (gtk.EventBox):
def set_value (self, n):
self.value = n
-class NumberBox (gtk.Widget):
+class NumberBox (Gtk.Widget):
text = ''
top_note_text = ''
@@ -87,22 +87,22 @@ class NumberBox (gtk.Widget):
border_color = None
__gsignals__ = {
- 'value-about-to-change':(gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
- 'notes-about-to-change':(gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
- 'changed':(gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
+ 'value-about-to-change':(GObject.SignalFlags.RUN_LAST, None, ()),
+ 'notes-about-to-change':(GObject.SignalFlags.RUN_LAST, None, ()),
+ 'changed':(GObject.SignalFlags.RUN_LAST, None, ()),
# undo-change - A hacky way to handle the fact that we want to
# respond to undo's changes but we don't want undo to respond
# to itself...
- 'undo-change':(gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
- 'notes-changed':(gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
+ 'undo-change':(GObject.SignalFlags.RUN_LAST, None, ()),
+ 'notes-changed':(GObject.SignalFlags.RUN_LAST, None, ()),
}
- base_state = gtk.STATE_NORMAL
+ base_state = Gtk.StateType.NORMAL
npicker = None
draw_boxes = False
def __init__ (self, upper = 9, text = ''):
- gtk.Widget.__init__(self)
+ GObject.GObject.__init__(self)
self.upper = upper
self.parent_win = None
self.timer = None
@@ -110,15 +110,15 @@ class NumberBox (gtk.Widget):
self.font.set_size(BASE_FONT_SIZE)
self.note_font = self.font.copy()
self.note_font.set_size(NOTE_FONT_SIZE)
- self._top_note_layout = pango.Layout(self.create_pango_context())
+ self._top_note_layout = Pango.Layout(self.create_pango_context())
self._top_note_layout.set_font_description(self.note_font)
- self._bottom_note_layout = pango.Layout(self.create_pango_context())
+ self._bottom_note_layout = Pango.Layout(self.create_pango_context())
self._bottom_note_layout.set_font_description(self.note_font)
self.top_note_list = []
self.bottom_note_list = []
self.tinfo = tracker_info.TrackerInfo()
self.set_property('can-focus', True)
- self.set_property('events', gtk.gdk.ALL_EVENTS_MASK)
+ self.set_property('events', Gdk.EventMask.ALL_EVENTS_MASK)
self.connect('button-press-event', self.button_press_cb)
self.connect('key-release-event', self.key_press_cb)
self.connect('enter-notify-event', self.pointer_enter_cb)
@@ -136,19 +136,19 @@ class NumberBox (gtk.Widget):
def pointer_enter_cb (self, *args):
if not self.is_focus():
- self.set_state(gtk.STATE_PRELIGHT)
+ self.set_state(Gtk.StateType.PRELIGHT)
def pointer_leave_cb (self, *args):
self.set_state(self.base_state)
self._toggle_box_drawing_(False)
def focus_in_cb (self, *args):
- self.set_state(gtk.STATE_SELECTED)
- self.base_state = gtk.STATE_SELECTED
+ self.set_state(Gtk.StateType.SELECTED)
+ self.base_state = Gtk.StateType.SELECTED
def focus_out_cb (self, *args):
- self.set_state(gtk.STATE_NORMAL)
- self.base_state = gtk.STATE_NORMAL
+ self.set_state(Gtk.StateType.NORMAL)
+ self.base_state = Gtk.StateType.NORMAL
self.destroy_npicker()
def destroy_npicker (self):
@@ -173,7 +173,7 @@ class NumberBox (gtk.Widget):
def button_press_cb (self, w, e):
if self.read_only:
return
- if e.type == gtk.gdk._2BUTTON_PRESS:
+ if e.type == Gdk._2BUTTON_PRESS:
# ignore second click (this makes a double click in the
# middle of a cell get us a display of the numbers, rather
# than selecting a number.
@@ -201,7 +201,7 @@ class NumberBox (gtk.Widget):
return
if self.npicker: # kill number picker no matter what is pressed
self.destroy_npicker()
- txt = gtk.gdk.keyval_name(e.keyval)
+ txt = Gdk.keyval_name(e.keyval)
if type(txt) == type(None):
# Make sure we don't trigger on unplugging the A/C charger etc
return
@@ -209,9 +209,9 @@ class NumberBox (gtk.Widget):
# Add the new value if need be
if txt in [str(n) for n in range(1, self.upper+1)]:
- if e.state & gtk.gdk.CONTROL_MASK:
+ if e.state & Gdk.EventMask.CONTROL_MASK:
self.add_note_text(txt, top = True)
- elif e.state & gtk.gdk.MOD1_MASK:
+ elif e.state & Gdk.ModifierType.MOD1_MASK:
self.remove_note_text(txt, top = True)
elif self.get_text() != txt or \
(self.tracker_id != tracker_info.NO_TRACKER and
@@ -223,12 +223,12 @@ class NumberBox (gtk.Widget):
elif txt in ['0', 'Delete', 'BackSpace']:
self.set_text_interactive('')
elif txt in ['n', 'N']:
- if e.state & gtk.gdk.MOD1_MASK:
+ if e.state & Gdk.ModifierType.MOD1_MASK:
self.set_note_text_interactive(top_text = '')
else:
self.show_note_editor(top = True)
elif txt in ['m', 'M']:
- if e.state & gtk.gdk.MOD1_MASK:
+ if e.state & Gdk.ModifierType.MOD1_MASK:
self.set_note_text_interactive(bottom_text = '')
else:
self.show_note_editor(top = False)
@@ -276,16 +276,16 @@ class NumberBox (gtk.Widget):
def show_note_editor (self, top = True):
alloc = self.get_allocation()
- w = gtk.Window()
+ w = Gtk.Window()
w.set_property('skip-pager-hint', True)
w.set_property('skip-taskbar-hint', True)
w.set_decorated(False)
- w.set_position(gtk.WIN_POS_MOUSE)
+ w.set_position(Gtk.WindowPosition.MOUSE)
w.set_size_request(alloc.width, alloc.height/2)
if self.parent_win:
w.set_transient_for(self.parent_win)
- f = gtk.Frame()
- e = gtk.Entry()
+ f = Gtk.Frame()
+ e = Gtk.Entry()
f.add(e)
if top:
e.set_text(self.top_note_text)
@@ -314,7 +314,7 @@ class NumberBox (gtk.Widget):
self.set_text_interactive('')
def show_number_picker (self):
- w = gtk.Window(type = gtk.WINDOW_POPUP)
+ w = Gtk.Window(type = Gtk.WindowType.POPUP)
ns = NumberSelector(upper = self.upper, default = self.get_value())
ns.connect('changed', self.number_changed_cb)
w.grab_focus()
@@ -337,7 +337,7 @@ class NumberBox (gtk.Widget):
def set_font (self, font):
if type(font) == str:
- font = pango.FontDescription(font)
+ font = Pango.FontDescription(font)
self.font = font
if self.text:
self.set_text(self.text)
@@ -345,7 +345,7 @@ class NumberBox (gtk.Widget):
def set_note_font (self, font):
if type(font) == str:
- font = pango.FontDescription(font)
+ font = Pango.FontDescription(font)
self.note_font = font
self._top_note_layout.set_font_description(font)
self._bottom_note_layout.set_font_description(font)
@@ -511,34 +511,34 @@ class NumberBox (gtk.Widget):
def do_realize (self):
# The do_realize method is responsible for creating GDK (windowing system)
- # resources. In this example we will create a new gdk.Window which we
+ # resources. In this example we will create a new Gdk.Window which we
# then draw on
# First set an internal flag telling that we're realized
- self.set_flags(self.flags() | gtk.REALIZED)
+ self.set_flags(self.flags() | Gtk.REALIZED)
- # Create a new gdk.Window which we can draw on.
+ # Create a new Gdk.Window which we can draw on.
# Also say that we want to receive exposure events by setting
# the event_mask
- self.window = gtk.gdk.Window(
+ self.window = Gdk.Window(
self.get_parent_window(),
width = self.allocation.width,
height = self.allocation.height,
- window_type = gtk.gdk.WINDOW_CHILD,
- wclass = gtk.gdk.INPUT_OUTPUT,
- event_mask = self.get_events() | gtk.gdk.EXPOSURE_MASK)
+ window_type = Gdk.WINDOW_CHILD,
+ wclass = Gdk.INPUT_OUTPUT,
+ event_mask = self.get_events() | Gdk.EventMask.EXPOSURE_MASK)
- # Associate the gdk.Window with ourselves, Gtk+ needs a reference
+ # Associate the Gdk.Window with ourselves, Gtk+ needs a reference
# between the widget and the gdk window
self.window.set_user_data(self)
- # Attach the style to the gdk.Window, a style contains colors and
+ # Attach the style to the Gdk.Window, a style contains colors and
# GC contextes used for drawing
self.style.attach(self.window)
# The default color of the background should be what
# the style (theme engine) tells us.
- self.style.set_background(self.window, gtk.STATE_NORMAL)
+ self.style.set_background(self.window, Gtk.StateType.NORMAL)
self.window.move_resize(*self.allocation)
def do_unrealize (self):
@@ -556,9 +556,9 @@ class NumberBox (gtk.Widget):
# text is, and a square
width, height = self._layout.get_size()
if width > height:
- side = width/pango.SCALE
+ side = width/Pango.SCALE
else:
- side = height/pango.SCALE
+ side = height/Pango.SCALE
(requisition.width, requisition.height) = (side, side)
def do_size_allocate(self, allocation):
@@ -570,7 +570,7 @@ class NumberBox (gtk.Widget):
# If we're realized, move and resize the window to the
# requested coordinates/positions
- if self.flags() & gtk.REALIZED:
+ if self.get_realized():
self.window.move_resize(*allocation)
def do_expose_event(self, event):
@@ -606,9 +606,9 @@ class NumberBox (gtk.Widget):
r*0.6, g*0.6, b*0.6
)
else:
- cr.set_source_color(self.style.base[gtk.STATE_INSENSITIVE])
+ cr.set_source_color(self.style.base[Gtk.StateType.INSENSITIVE])
elif self.is_focus():
- cr.set_source_color(self.style.base[gtk.STATE_SELECTED])
+ cr.set_source_color(self.style.base[Gtk.StateType.SELECTED])
elif self.custom_background_color:
cr.set_source_rgb(*self.custom_background_color)
else:
@@ -622,7 +622,7 @@ class NumberBox (gtk.Widget):
def draw_highlight_box (self, cr, w, h):
cr.set_source_color(
- self.style.base[gtk.STATE_SELECTED]
+ self.style.base[Gtk.StateType.SELECTED]
)
border = 4 * w / BASE_SIZE
cr.rectangle(
@@ -668,7 +668,7 @@ class NumberBox (gtk.Widget):
if self.text_color:
cr.set_source_rgb(*self.text_color)
elif self.read_only:
- cr.set_source_color(self.style.text[gtk.STATE_NORMAL])
+ cr.set_source_color(self.style.text[Gtk.StateType.NORMAL])
else:
cr.set_source_color(self.style.text[self.state])
# And draw the text in the middle of the allocated space
@@ -782,7 +782,7 @@ class SudokuNumberBox (NumberBox):
if not hasattr(self, 'bold_font'):
self.normal_font = self.font
self.bold_font = self.font.copy()
- self.bold_font.set_weight(pango.WEIGHT_BOLD)
+ self.bold_font.set_weight(Pango.Weight.BOLD)
if self.read_only:
self.set_font(self.bold_font)
else:
@@ -800,11 +800,11 @@ class SudokuNumberBox (NumberBox):
self.queue_draw()
-gobject.type_register(NumberBox)
+GObject.type_register(NumberBox)
if __name__ == '__main__':
- window = gtk.Window()
- window.connect('delete-event', gtk.main_quit)
+ window = Gtk.Window()
+ window.connect('delete-event', Gtk.main_quit)
def test_number_selector ():
nselector = NumberSelector(default = 3)
@@ -821,4 +821,4 @@ if __name__ == '__main__':
# test_number_selector()
test_number_box()
window.show_all()
- gtk.main()
+ Gtk.main()
diff --git a/gnome-sudoku/src/lib/printing.py b/gnome-sudoku/src/lib/printing.py
index 0b8ea18..ce66dfa 100644
--- a/gnome-sudoku/src/lib/printing.py
+++ b/gnome-sudoku/src/lib/printing.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-import gtk
+from gi.repository import Gtk
import cairo
import time
import os.path
@@ -48,7 +48,7 @@ class SudokuPrinter:
self.sudokus_per_page = sudokus_per_page
self.n_sudokus = len(sudokus)
self.sudokus = sudokus
- self.print_op = gtk.PrintOperation()
+ self.print_op = Gtk.PrintOperation()
self.print_op.connect( "begin-print", self.begin_print)
self.print_op.connect("draw-page", self.draw_page)
self.main_window = main_window
@@ -104,12 +104,12 @@ class SudokuPrinter:
def print_sudokus(*args, **kwargs):
sp = SudokuPrinter(*args, **kwargs)
- res = sp.print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, sp.main_window)
- if res == gtk.PRINT_OPERATION_RESULT_ERROR:
- error_dialog = gtk.MessageDialog(sp.main_window,
- gtk.DIALOG_DESTROY_WITH_PARENT,
- gtk.MESSAGE_ERROR,
- gtk.BUTTONS_CLOSE,
+ res = sp.print_op.run(Gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, sp.main_window)
+ if res == Gtk.PRINT_OPERATION_RESULT_ERROR:
+ error_dialog = Gtk.MessageDialog(sp.main_window,
+ Gtk.DialogFlags.DESTROY_WITH_PARENT,
+ Gtk.MessageType.ERROR,
+ Gtk.ButtonsType.CLOSE,
"Error printing file:\n")
error_dialog.connect("response", lambda w, id: w.destroy())
error_dialog.show()
@@ -131,7 +131,7 @@ class GamePrinter (gconf_wrapper.GConfWrapper):
def __init__ (self, sudoku_maker, gconf):
gconf_wrapper.GConfWrapper.__init__(self, gconf)
self.sudoku_maker = sudoku_maker
- self.builder = gtk.Builder()
+ self.builder = Gtk.Builder()
self.builder.set_translation_domain(defaults.DOMAIN)
self.builder.add_from_file(self.ui_file)
# Set up toggles...
@@ -155,11 +155,11 @@ class GamePrinter (gconf_wrapper.GConfWrapper):
]:
self.gconf_wrap_adjustment(key, widg)
self.dialog = self.builder.get_object('dialog')
- self.dialog.set_default_response(gtk.RESPONSE_OK)
+ self.dialog.set_default_response(Gtk.ResponseType.OK)
self.dialog.connect('response', self.response_cb)
def response_cb (self, dialog, response):
- if response not in (gtk.RESPONSE_ACCEPT, gtk.RESPONSE_OK):
+ if response not in (Gtk.ResponseType.ACCEPT, Gtk.ResponseType.OK):
self.dialog.hide()
return
# Otherwise, we're printing!
@@ -191,11 +191,11 @@ class GamePrinter (gconf_wrapper.GConfWrapper):
sudokus_per_page = self.sudokusPerPageSpinButton.get_adjustment().get_value())
self.sudokus_printed = sudokus
- response = sp.print_op.run(gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, sp.main_window)
+ response = sp.print_op.run(Gtk.PRINT_OPERATION_ACTION_PRINT_DIALOG, sp.main_window)
- if response == gtk.PRINT_OPERATION_RESULT_ERROR:
+ if response == Gtk.PRINT_OPERATION_RESULT_ERROR:
pass
- elif response == gtk.PRINT_OPERATION_RESULT_APPLY:
+ elif response == Gtk.PRINT_OPERATION_RESULT_APPLY:
if self.markAsPlayedToggle.get_active():
for sud, lab in self.sudokus_printed:
jar = {}
diff --git a/gnome-sudoku/src/lib/saver.py b/gnome-sudoku/src/lib/saver.py
index e4816de..c159e6e 100644
--- a/gnome-sudoku/src/lib/saver.py
+++ b/gnome-sudoku/src/lib/saver.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-import gtk
+from gi.repository import Gtk
import pickle, types, os, errno
import defaults
from gtk_goodies.dialog_extras import show_message
@@ -137,7 +137,7 @@ class SudokuTracker:
show_message(
title = _('No Space'),
label = _('No space left on disk'),
- message_type = gtk.MESSAGE_ERROR,
+ message_type = Gtk.MessageType.ERROR,
sublabel = _('Unable to create data folder %(path)s.') % locals() + '\n' + \
_('There is no disk space left!')
)
@@ -168,7 +168,7 @@ class SudokuTracker:
show_message(
title = _('Unable to save game.'),
label = _('Unable to save game.'),
- message_type = gtk.MESSAGE_ERROR,
+ message_type = Gtk.MessageType.ERROR,
sublabel = (_('Unable to save file %(filename)s.') % locals()
+ '\n' +
_('Error %(errno)s: %(error)s') % {
@@ -193,7 +193,7 @@ class SudokuTracker:
show_message(
title = _('Unable to mark game as finished.'),
label = _('Unable to mark game as finished.'),
- message_type = gtk.MESSAGE_ERROR,
+ message_type = Gtk.MessageType.ERROR,
sublabel = (_('Unable to save file %(filename)s.') % locals() + '\n' +
_('Error %(errno)s: %(error)s') % {
'errno':e.errno,
@@ -211,7 +211,7 @@ class SudokuTracker:
show_message(
title = _('Sudoku unable to mark game as finished.'),
label = _('Sudoku unable to mark game as finished.'),
- message_type = gtk.MESSAGE_ERROR,
+ message_type = Gtk.MessageType.ERROR,
sublabel = (_('Unable to save file %(filename)s.') % locals() + '\n' +
_('Error %(errno)s: %(error)s') % {
'errno':e.errno,
diff --git a/gnome-sudoku/src/lib/sudoku.py b/gnome-sudoku/src/lib/sudoku.py
index 0a131f8..a345593 100644
--- a/gnome-sudoku/src/lib/sudoku.py
+++ b/gnome-sudoku/src/lib/sudoku.py
@@ -467,7 +467,7 @@ class SudokuSolver (SudokuGrid):
guess_obj = Guess(least[0][0], least[0][1], guess)
if self.breadcrumbs:
self.breadcrumbs[-1].children.append(guess_obj)
- self.current_guess = None #reset (we're tracked via guess.child)
+ self.current_guess = None #reset (we're tracked via guess.get_child())
self.add(least[0][0], least[0][1], guess)
self.current_guess = guess_obj # (All deterministic additions
# get added to our
diff --git a/gnome-sudoku/src/lib/sudoku_thumber.py b/gnome-sudoku/src/lib/sudoku_thumber.py
index f85c24e..98f2c08 100644
--- a/gnome-sudoku/src/lib/sudoku_thumber.py
+++ b/gnome-sudoku/src/lib/sudoku_thumber.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-import gtk
+from gi.repository import Gtk
import cairo
SUDOKU_SIZE = 9
@@ -133,7 +133,7 @@ def make_pixbuf (sudoku, played, border_color, line_color = (0.4, 0.4, 0.4)):
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, size, size)
cr = cairo.Context(surface)
draw_sudoku(cr, sudoku, played, size, 0, 0, border_color, line_color)
- pixbuf = gtk.gdk.pixbuf_new_from_data(surface.get_data(), gtk.gdk.COLORSPACE_RGB,
+ pixbuf = GdkPixbuf.Pixbuf.new_from_data(surface.get_data(), GdkPixbuf.Colorspace.RGB,
True, 8, surface.get_width(), surface.get_height(), surface.get_stride())
del surface
return pixbuf
@@ -149,15 +149,15 @@ if __name__ == "__main__":
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 750, 750)
cr = cairo.Context(surface)
draw_sudoku(cr, sudoku, played, size, 100, 250, border_color, line_color)
- pb = gtk.gdk.pixbuf_new_from_data(surface.get_data(), gtk.gdk.COLORSPACE_RGB,
+ pb = GdkPixbuf.Pixbuf.new_from_data(surface.get_data(), GdkPixbuf.Colorspace.RGB,
True, 8, surface.get_width(), surface.get_height(), surface.get_stride())
del surface
- w = gtk.Window()
- img = gtk.Image()
+ w = Gtk.Window()
+ img = Gtk.Image()
img.set_from_pixbuf(pb)
w.add(img)
w.show_all()
- gtk.main()
+ Gtk.main()
diff --git a/gnome-sudoku/src/lib/timer.py b/gnome-sudoku/src/lib/timer.py
index 84f6f9a..c94656f 100644
--- a/gnome-sudoku/src/lib/timer.py
+++ b/gnome-sudoku/src/lib/timer.py
@@ -2,16 +2,16 @@
import gobject
import time
-class ActiveTimer (gobject.GObject):
+class ActiveTimer (GObject.GObject):
"""A timer to keep track of how much time a window is active."""
__gsignals__ = {
- 'timing-started': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()),
- 'timing-stopped': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
+ 'timing-started': (GObject.SignalFlags.RUN_LAST, None, ()),
+ 'timing-stopped': (GObject.SignalFlags.RUN_LAST, None, ())
}
def __init__ (self, window):
- gobject.GObject.__init__(self)
+ GObject.GObject.__init__(self)
self.window = window
# whether we have 'start_timing'; affects total_time
self.timer_running = False
@@ -70,18 +70,18 @@ class ActiveTimer (gobject.GObject):
self.timer_running = False
if __name__ == '__main__':
- import gtk
+ from gi.repository import Gtk
def report (timer):
pass
def test_active_timer ():
- win = gtk.Window()
+ win = Gtk.Window()
timer = ActiveTimer(win)
timer.start_timing()
win.connect('focus-out-event', lambda *args: report(timer))
- win.connect('delete-event', gtk.main_quit)
+ win.connect('delete-event', Gtk.main_quit)
win.show()
- gtk.main()
+ Gtk.main()
test_active_timer()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]