Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
GNOME
pygobject
Commits
32cc594a
Commit
32cc594a
authored
Mar 22, 2012
by
Johan Dahlin
Committed by
Johan Dahlin
Mar 22, 2012
Browse files
Remove all tabs and fix indentation
By running the whole source tree via the indent.py script found in the Python distribution.
parent
c375e313
Changes
31
Hide whitespace changes
Inline
Side-by-side
demos/gtk-demo/demos/Entry/search_entry.py
View file @
32cc594a
...
...
@@ -36,7 +36,7 @@ class SearchboxApp:
self
.
window
=
Gtk
.
Dialog
(
'Search Entry'
,
buttons
=
(
Gtk
.
STOCK_CLOSE
,
Gtk
.
ResponseType
.
NONE
))
self
.
window
.
connect
(
'response'
,
lambda
x
,
y
:
self
.
window
.
destroy
())
self
.
window
.
connect
(
'response'
,
lambda
x
,
y
:
self
.
window
.
destroy
())
self
.
window
.
connect
(
'destroy'
,
Gtk
.
main_quit
)
content_area
=
self
.
window
.
get_content_area
()
...
...
@@ -134,7 +134,7 @@ class SearchboxApp:
def
start_search
(
self
,
button
,
entry
):
self
.
show_cancel_button
()
self
.
search_progress_id
=
GObject
.
timeout_add_seconds
(
1
,
self
.
start_search_feedback
,
self
.
start_search_feedback
,
entry
)
self
.
finish_search_id
=
GObject
.
timeout_add_seconds
(
15
,
self
.
finish_search
,
...
...
demos/gtk-demo/demos/Icon View/iconviewedit.py
View file @
32cc594a
...
...
@@ -51,8 +51,8 @@ class IconviewEditApp:
renderer
=
Gtk
.
CellRendererPixbuf
()
icon_view
.
pack_start
(
renderer
,
True
)
icon_view
.
set_cell_data_func
(
renderer
,
self
.
set_cell_color
,
None
)
self
.
set_cell_color
,
None
)
renderer
=
Gtk
.
CellRendererText
()
icon_view
.
pack_start
(
renderer
,
True
)
...
...
@@ -64,27 +64,22 @@ class IconviewEditApp:
self
.
window
.
show_all
()
def
set_cell_color
(
self
,
cell_layout
,
cell
,
tree_model
,
iter_
,
icon_view
):
# FIXME return single element instead of tuple
text
=
tree_model
.
get
(
iter_
,
self
.
COL_TEXT
)[
0
]
color
=
Gdk
.
color_parse
(
text
)
pixel
=
0
if
color
is
not
None
:
pixel
=
\
(
color
.
red
>>
8
)
<<
24
|
\
(
color
.
green
>>
8
)
<<
16
|
\
(
color
.
blue
>>
8
)
<<
8
pixbuf
=
GdkPixbuf
.
Pixbuf
.
new
(
GdkPixbuf
.
Colorspace
.
RGB
,
False
,
8
,
24
,
24
)
pixbuf
.
fill
(
pixel
)
cell
.
props
.
pixbuf
=
pixbuf
def
set_cell_color
(
self
,
cell_layout
,
cell
,
tree_model
,
iter_
,
icon_view
):
# FIXME return single element instead of tuple
text
=
tree_model
.
get
(
iter_
,
self
.
COL_TEXT
)[
0
]
color
=
Gdk
.
color_parse
(
text
)
pixel
=
0
if
color
is
not
None
:
pixel
=
\
(
color
.
red
>>
8
)
<<
24
|
\
(
color
.
green
>>
8
)
<<
16
|
\
(
color
.
blue
>>
8
)
<<
8
pixbuf
=
GdkPixbuf
.
Pixbuf
.
new
(
GdkPixbuf
.
Colorspace
.
RGB
,
False
,
8
,
24
,
24
)
pixbuf
.
fill
(
pixel
)
cell
.
props
.
pixbuf
=
pixbuf
def
edited
(
self
,
cell
,
path_string
,
text
,
icon_view
):
model
=
icon_view
.
get_model
()
...
...
demos/gtk-demo/demos/Tree View/liststore.py
View file @
32cc594a
...
...
@@ -87,7 +87,7 @@ class ListStoreApp:
self
.
window
.
set_default_size
(
280
,
250
)
self
.
window
.
show_all
()
self
.
window
.
connect
(
'delete-event'
,
self
.
window_closed
)
self
.
timeout
=
GObject
.
timeout_add
(
80
,
self
.
spinner_timeout
)
...
...
@@ -98,7 +98,7 @@ class ListStoreApp:
def
spinner_timeout
(
self
):
if
self
.
model
is
None
:
return
False
iter_
=
self
.
model
.
get_iter_first
()
pulse
=
self
.
model
.
get
(
iter_
,
self
.
COLUMN_PULSE
)[
0
]
if
pulse
==
999999999
:
...
...
@@ -120,7 +120,7 @@ class ListStoreApp:
str
,
bool
,
bool
)
col
=
0
for
bug
in
data
:
if
col
==
1
or
col
==
3
:
...
...
@@ -144,7 +144,7 @@ class ListStoreApp:
def
add_columns
(
self
,
treeview
):
model
=
treeview
.
get_model
()
# column for is_fixed toggle
renderer
=
Gtk
.
CellRendererToggle
()
renderer
.
connect
(
'toggled'
,
self
.
is_fixed_toggled
,
model
)
...
...
demos/gtk-demo/demos/appwindow.py
View file @
32cc594a
...
...
@@ -120,15 +120,15 @@ Boston, MA 02111-1307, USA.
about
=
Gtk
.
AboutDialog
(
parent
=
window
,
program_name
=
'GTK+ Code Demos'
,
version
=
'0.1'
,
copyright
=
'(C) 2010 The PyGI Team'
,
license
=
license
,
website
=
'http://live.gnome.org/PyGI'
,
comments
=
'Program to demonstrate PyGI functions.'
,
authors
=
authors
,
documenters
=
documentors
,
logo
=
transparent
,
title
=
'About GTK+ Code Demos'
)
version
=
'0.1'
,
copyright
=
'(C) 2010 The PyGI Team'
,
license
=
license
,
website
=
'http://live.gnome.org/PyGI'
,
comments
=
'Program to demonstrate PyGI functions.'
,
authors
=
authors
,
documenters
=
documentors
,
logo
=
transparent
,
title
=
'About GTK+ Code Demos'
)
about
.
connect
(
'response'
,
widget_destroy
)
about
.
show
()
...
...
demos/gtk-demo/demos/dialogs.py
View file @
32cc594a
...
...
@@ -45,11 +45,11 @@ class DialogsApp:
hbox
=
Gtk
.
HBox
(
spacing
=
8
);
vbox
.
pack_start
(
hbox
,
False
,
False
,
0
)
button
=
Gtk
.
Button
.
new_with_mnemonic
(
"_Message Dialog"
);
button
.
connect
(
'clicked'
,
self
.
_message_dialog_clicked
)
self
.
_message_dialog_clicked
)
hbox
.
pack_start
(
button
,
False
,
False
,
0
)
vbox
.
pack_start
(
Gtk
.
HSeparator
(),
False
,
False
,
0
);
...
...
@@ -58,9 +58,9 @@ class DialogsApp:
vbox
.
pack_start
(
hbox
,
False
,
False
,
0
)
vbox2
=
Gtk
.
VBox
(
spacing
=
0
);
button
=
Gtk
.
Button
.
new_with_mnemonic
(
"_Interactive Dialog"
);
button
.
connect
(
'clicked'
,
self
.
_interactive_dialog_clicked
)
self
.
_interactive_dialog_clicked
)
hbox
.
pack_start
(
vbox2
,
False
,
False
,
0
)
vbox2
.
pack_start
(
button
,
False
,
False
,
0
)
...
...
@@ -77,7 +77,7 @@ class DialogsApp:
label
.
set_mnemonic_widget
(
self
.
entry1
)
label
=
Gtk
.
Label
.
new_with_mnemonic
(
"E_ntry 2"
);
table
.
attach_defaults
(
label
,
0
,
1
,
1
,
2
);
self
.
entry2
=
Gtk
.
Entry
()
...
...
@@ -89,10 +89,10 @@ class DialogsApp:
def
_interactive_dialog_clicked
(
self
,
button
):
dialog
=
Gtk
.
Dialog
(
'Interactive Dialog'
,
self
.
window
,
Gtk
.
DialogFlags
.
MODAL
|
Gtk
.
DialogFlags
.
MODAL
|
Gtk
.
DialogFlags
.
DESTROY_WITH_PARENT
,
(
Gtk
.
STOCK_OK
,
Gtk
.
ResponseType
.
OK
,
"_Non-stock Button"
,
Gtk
.
ResponseType
.
CANCEL
))
(
Gtk
.
STOCK_OK
,
Gtk
.
ResponseType
.
OK
,
"_Non-stock Button"
,
Gtk
.
ResponseType
.
CANCEL
))
content_area
=
dialog
.
get_content_area
()
hbox
=
Gtk
.
HBox
(
spacing
=
8
)
...
...
@@ -122,7 +122,7 @@ class DialogsApp:
local_entry2
.
set_text
(
self
.
entry2
.
get_text
())
table
.
attach_defaults
(
local_entry2
,
1
,
2
,
1
,
2
)
label
.
set_mnemonic_widget
(
local_entry2
);
hbox
.
show_all
();
response
=
dialog
.
run
()
...
...
@@ -134,10 +134,10 @@ class DialogsApp:
def
_message_dialog_clicked
(
self
,
button
):
dialog
=
Gtk
.
MessageDialog
(
self
.
window
,
Gtk
.
DialogFlags
.
MODAL
|
Gtk
.
DialogFlags
.
MODAL
|
Gtk
.
DialogFlags
.
DESTROY_WITH_PARENT
,
Gtk
.
MessageType
.
INFO
,
Gtk
.
ButtonsType
.
OK
,
Gtk
.
MessageType
.
INFO
,
Gtk
.
ButtonsType
.
OK
,
"This message box has been popped up the following
\n
number of times:"
)
dialog
.
format_secondary_text
(
'%d'
%
self
.
dialog_counter
)
dialog
.
run
()
...
...
demos/gtk-demo/demos/expander.py
View file @
32cc594a
...
...
@@ -21,7 +21,7 @@
title
=
"Expander"
description
=
"""
GtkExpander allows to provide additional content that is initially hidden.
GtkExpander allows to provide additional content that is initially hidden.
This is also known as "disclosure triangle".
"""
...
...
@@ -29,7 +29,7 @@ from gi.repository import Gtk
class
ExpanderApp
:
def
__init__
(
self
):
self
.
window
=
Gtk
.
Dialog
(
"GtkExpander"
,
self
.
window
=
Gtk
.
Dialog
(
"GtkExpander"
,
None
,
0
,
(
Gtk
.
STOCK_CLOSE
,
Gtk
.
ResponseType
.
NONE
))
self
.
window
.
set_resizable
(
False
)
...
...
@@ -49,7 +49,7 @@ class ExpanderApp:
label
=
Gtk
.
Label
(
'Details can be shown or hidden'
)
expander
.
add
(
label
)
self
.
window
.
show_all
()
def
main
(
demoapp
=
None
):
...
...
demos/gtk-demo/demos/images.py
View file @
32cc594a
...
...
@@ -199,7 +199,7 @@ class ImagesApp:
# file was truncated we'll know on close that
# it was incomplete.
try
:
self
.
pixbuf_loader
.
close
()
self
.
pixbuf_loader
.
close
()
except
GObject
.
GError
as
e
:
dialog
=
Gtk
.
MessageDialog
(
self
.
window
,
Gtk
.
DialogFlags
.
DESTROY_WITH_PARENT
,
...
...
demos/gtk-demo/demos/links.py
View file @
32cc594a
...
...
@@ -21,7 +21,7 @@
title
=
"Links"
description
=
"""
GtkLabel can show hyperlinks. The default action is to call gtk_show_uri() on
GtkLabel can show hyperlinks. The default action is to call gtk_show_uri() on
their URI, but it is possible to override this with a custom handler.
"""
...
...
demos/gtk-demo/demos/rotatedtext.py
View file @
32cc594a
...
...
@@ -48,13 +48,13 @@ class RotatedTextApp:
FONT
=
"Serif 18"
def
__init__
(
self
):
white
=
Gdk
.
RGBA
()
white
.
red
=
1.0
white
.
green
=
1.0
white
.
blue
=
1.0
white
.
alpha
=
1.0
self
.
window
=
Gtk
.
Window
(
title
=
"Rotated Text"
)
self
.
window
.
set_default_size
(
4
*
self
.
RADIUS
,
2
*
self
.
RADIUS
)
self
.
window
.
connect
(
'destroy'
,
Gtk
.
main_quit
)
...
...
@@ -62,7 +62,7 @@ class RotatedTextApp:
box
=
Gtk
.
HBox
()
box
.
set_homogeneous
(
True
)
self
.
window
.
add
(
box
)
# add a drawing area
da
=
Gtk
.
DrawingArea
()
box
.
add
(
da
)
...
...
@@ -78,7 +78,7 @@ class RotatedTextApp:
# Setup some fancy stuff on the label
layout
=
label
.
get_layout
()
PangoCairo
.
context_set_shape_renderer
(
layout
.
get_context
(),
self
.
fancy_shape_renderer
,
None
)
...
...
@@ -110,7 +110,7 @@ class RotatedTextApp:
metrics
=
pango_ctx
.
get_metrics
(
layout
.
get_font_description
(),
None
)
ascent
=
metrics
.
get_ascent
()
logical_rect
=
Pango
.
Rectangle
()
logical_rect
.
x
=
0
logical_rect
.
width
=
ascent
...
...
@@ -137,7 +137,7 @@ class RotatedTextApp:
attrs.insert(attr)
'''
return
attrs
def
rotated_text_draw
(
self
,
da
,
cairo_ctx
):
# Create a cairo context and set up a transformation matrix so that the user
# space coordinates for the centered square where we draw are [-RADIUS, RADIUS],
...
...
@@ -149,11 +149,11 @@ class RotatedTextApp:
cairo_ctx
.
translate
(
device_radius
+
(
width
-
2
*
device_radius
)
/
2
,
device_radius
+
(
height
-
2
*
device_radius
)
/
2
)
cairo_ctx
.
scale
(
device_radius
/
self
.
RADIUS
,
cairo_ctx
.
scale
(
device_radius
/
self
.
RADIUS
,
device_radius
/
self
.
RADIUS
)
# Create a subtle gradient source and use it.
pattern
=
cairo
.
LinearGradient
(
-
self
.
RADIUS
,
-
self
.
RADIUS
,
pattern
=
cairo
.
LinearGradient
(
-
self
.
RADIUS
,
-
self
.
RADIUS
,
self
.
RADIUS
,
self
.
RADIUS
)
pattern
.
add_color_stop_rgb
(
0.0
,
0.5
,
0.0
,
0.0
)
pattern
.
add_color_stop_rgb
(
1.0
,
0.0
,
0.0
,
0.5
)
...
...
@@ -178,14 +178,14 @@ class RotatedTextApp:
for
i
in
range
(
self
.
N_WORDS
):
# Inform Pango to re-layout the text with the new transformation matrix
PangoCairo
.
update_layout
(
cairo_ctx
,
layout
)
width
,
height
=
layout
.
get_pixel_size
()
cairo_ctx
.
move_to
(
-
width
/
2
,
-
self
.
RADIUS
*
0.9
)
PangoCairo
.
show_layout
(
cairo_ctx
,
layout
)
# Rotate for the next turn
cairo_ctx
.
rotate
(
math
.
pi
*
2
/
self
.
N_WORDS
)
return
False
def
main
(
demoapp
=
None
):
...
...
gi/_glib/option.py
View file @
32cc594a
...
...
@@ -207,7 +207,7 @@ class OptionGroup(optparse.OptionGroup):
entries
=
[]
for
option
in
self
.
option_list
:
entries
.
extend
(
option
.
_to_goptionentries
())
group
.
add_entries
(
entries
)
return
group
...
...
gi/_gobject/constants.py
View file @
32cc594a
...
...
@@ -77,4 +77,3 @@ G_MAXSIZE = _gobject.G_MAXSIZE
G_MAXSSIZE
=
_gobject
.
G_MAXSSIZE
G_MINOFFSET
=
_gobject
.
G_MINOFFSET
G_MAXOFFSET
=
_gobject
.
G_MAXOFFSET
gi/importer.py
View file @
32cc594a
...
...
@@ -76,4 +76,3 @@ class DynamicImporter(object):
dynamic_module
.
_load
()
return
dynamic_module
gi/module.py
View file @
32cc594a
...
...
@@ -128,7 +128,7 @@ class IntrospectionModule(object):
# identifier conversion (e. g. in Turkish 'i'.upper() == 'i')
# see https://bugzilla.gnome.org/show_bug.cgi?id=649165
ascii_upper_trans
=
maketrans
(
'abcdefgjhijklmnopqrstuvwxyz'
,
'abcdefgjhijklmnopqrstuvwxyz'
,
'ABCDEFGJHIJKLMNOPQRSTUVWXYZ'
)
for
value_info
in
info
.
get_values
():
value_name
=
value_info
.
get_name
().
translate
(
ascii_upper_trans
)
...
...
@@ -231,9 +231,9 @@ class DynamicModule(object):
return
getattr
(
self
.
_overrides_module
,
name
,
None
)
else
:
# check the registry just in case the module hasn't loaded yet
# TODO: Only gtypes are registered in the registry right now
# but it would be nice to register all overrides and
# get rid of the module imports. We might actually see a
# TODO: Only gtypes are registered in the registry right now
# but it would be nice to register all overrides and
# get rid of the module imports. We might actually see a
# speedup.
key
=
'%s.%s'
%
(
self
.
_namespace
,
name
)
if
key
in
registry
:
...
...
@@ -245,7 +245,7 @@ class DynamicModule(object):
# Python's default dir() is just dir(self.__class__) + self.__dict__.keys()
result
=
set
(
dir
(
self
.
__class__
))
result
.
update
(
self
.
__dict__
.
keys
())
result
.
update
(
dir
(
self
.
_introspection_module
))
override_exports
=
getattr
(
self
.
_overrides_module
,
'__all__'
,
())
result
.
update
(
override_exports
)
...
...
gi/overrides/GLib.py
View file @
32cc594a
...
...
@@ -156,11 +156,11 @@ class Variant(GLib.Variant):
format_string is a standard GVariant type signature, value is a Python
object whose structure has to match the signature.
Examples:
GLib.Variant('i', 1)
GLib.Variant('(is)', (1, 'hello'))
GLib.Variant('(asa{sv})', ([], {'foo': GLib.Variant('b', True),
GLib.Variant('(asa{sv})', ([], {'foo': GLib.Variant('b', True),
'bar': GLib.Variant('i', 2)}))
'''
creator
=
_VariantCreator
()
...
...
@@ -216,7 +216,7 @@ class Variant(GLib.Variant):
# tuple
if
self
.
get_type_string
().
startswith
(
'('
):
res
=
[
self
.
get_child_value
(
i
).
unpack
()
res
=
[
self
.
get_child_value
(
i
).
unpack
()
for
i
in
range
(
self
.
n_children
())]
return
tuple
(
res
)
...
...
@@ -230,7 +230,7 @@ class Variant(GLib.Variant):
# array
if
self
.
get_type_string
().
startswith
(
'a'
):
return
[
self
.
get_child_value
(
i
).
unpack
()
return
[
self
.
get_child_value
(
i
).
unpack
()
for
i
in
range
(
self
.
n_children
())]
# variant (just unbox transparently)
...
...
@@ -245,7 +245,7 @@ class Variant(GLib.Variant):
If the signature is not a tuple, it returns one element with the entire
signature. If the signature is an empty tuple, the result is [].
This is useful for e. g. iterating over method parameters which are
passed as a single Variant.
'''
...
...
@@ -377,4 +377,3 @@ setattr(Variant, 'new_tuple', new_tuple)
setattr
(
Variant
,
'get_string'
,
get_string
)
__all__
.
append
(
'Variant'
)
gi/overrides/Gdk.py
View file @
32cc594a
...
...
@@ -296,49 +296,49 @@ def color_parse(color):
if
Gdk
.
_version
>=
'3.0'
:
SELECTION_PRIMARY
=
Gdk
.
atom_intern
(
'PRIMARY'
,
True
)
__all__
.
append
(
'SELECTION_PRIMARY'
)
SELECTION_SECONDARY
=
Gdk
.
atom_intern
(
'SECONDARY'
,
True
)
__all__
.
append
(
'SELECTION_SECONDARY'
)
SELECTION_CLIPBOARD
=
Gdk
.
atom_intern
(
'CLIPBOARD'
,
True
)
__all__
.
append
(
'SELECTION_CLIPBOARD'
)
TARGET_BITMAP
=
Gdk
.
atom_intern
(
'BITMAP'
,
True
)
__all__
.
append
(
'TARGET_BITMAP'
)
TARGET_COLORMAP
=
Gdk
.
atom_intern
(
'COLORMAP'
,
True
)
__all__
.
append
(
'TARGET_COLORMAP'
)
TARGET_DRAWABLE
=
Gdk
.
atom_intern
(
'DRAWABLE'
,
True
)
__all__
.
append
(
'TARGET_DRAWABLE'
)
TARGET_PIXMAP
=
Gdk
.
atom_intern
(
'PIXMAP'
,
True
)
__all__
.
append
(
'TARGET_PIXMAP'
)
TARGET_STRING
=
Gdk
.
atom_intern
(
'STRING'
,
True
)
__all__
.
append
(
'TARGET_STRING'
)
SELECTION_TYPE_ATOM
=
Gdk
.
atom_intern
(
'ATOM'
,
True
)
__all__
.
append
(
'SELECTION_TYPE_ATOM'
)
SELECTION_TYPE_BITMAP
=
Gdk
.
atom_intern
(
'BITMAP'
,
True
)
__all__
.
append
(
'SELECTION_TYPE_BITMAP'
)
SELECTION_TYPE_COLORMAP
=
Gdk
.
atom_intern
(
'COLORMAP'
,
True
)
__all__
.
append
(
'SELECTION_TYPE_COLORMAP'
)
SELECTION_TYPE_DRAWABLE
=
Gdk
.
atom_intern
(
'DRAWABLE'
,
True
)
__all__
.
append
(
'SELECTION_TYPE_DRAWABLE'
)
SELECTION_TYPE_INTEGER
=
Gdk
.
atom_intern
(
'INTEGER'
,
True
)
__all__
.
append
(
'SELECTION_TYPE_INTEGER'
)
SELECTION_TYPE_PIXMAP
=
Gdk
.
atom_intern
(
'PIXMAP'
,
True
)
__all__
.
append
(
'SELECTION_TYPE_PIXMAP'
)
SELECTION_TYPE_WINDOW
=
Gdk
.
atom_intern
(
'WINDOW'
,
True
)
__all__
.
append
(
'SELECTION_TYPE_WINDOW'
)
SELECTION_TYPE_STRING
=
Gdk
.
atom_intern
(
'STRING'
,
True
)
__all__
.
append
(
'SELECTION_TYPE_STRING'
)
...
...
gi/overrides/Gio.py
View file @
32cc594a
...
...
@@ -165,7 +165,7 @@ class _DBusProxyMethodCall:
class
DBusProxy
(
Gio
.
DBusProxy
):
'''Provide comfortable and pythonic method calls.
This marshalls the method arguments into a GVariant, invokes the
call_sync() method on the DBusProxy object, and unmarshalls the result
GVariant back into a Python tuple.
...
...
@@ -193,7 +193,7 @@ class DBusProxy(Gio.DBusProxy):
error_handler(proxy_object, exception, user_data) is called when it
finishes. If error_handler is not given, result_handler is called with
the exception object as result instead.
- user_data: Optional user data to pass to result_handler for
asynchronous calls.
...
...
gi/overrides/Gtk.py
View file @
32cc594a
...
...
@@ -822,89 +822,89 @@ class TreeModel(Gtk.TreeModel):
for
column
in
columns
:
value
=
row
[
column
]
if
value
is
None
:
continue
# None means skip this row
continue
# None means skip this row
self
.
set_value
(
treeiter
,
column
,
value
)
def
_convert_value
(
self
,
column
,
value
):
if
value
is
None
:
return
None
# we may need to convert to a basic type
type_
=
self
.
get_column_type
(
column
)
if
type_
==
GObject
.
TYPE_STRING
:
if
isinstance
(
value
,
str
):
value
=
str
(
value
)
elif
sys
.
version_info
<
(
3
,
0
):
if
isinstance
(
value
,
unicode
):
value
=
value
.
encode
(
'UTF-8'
)
else
:
raise
ValueError
(
'Expected string or unicode for column %i but got %s%s'
%
(
column
,
value
,
type
(
value
)))
else
:
raise
ValueError
(
'Expected a string for column %i but got %s'
%
(
column
,
type
(
value
)))
elif
type_
==
GObject
.
TYPE_FLOAT
or
type_
==
GObject
.
TYPE_DOUBLE
:
if
isinstance
(
value
,
float
):
value
=
float
(
value
)
if
value
is
None
:
return
None
# we may need to convert to a basic type
type_
=
self
.
get_column_type
(
column
)
if
type_
==
GObject
.
TYPE_STRING
:
if
isinstance
(
value
,
str
):
value
=
str
(
value
)
elif
sys
.
version_info
<
(
3
,
0
):
if
isinstance
(
value
,
unicode
):
value
=
value
.
encode
(
'UTF-8'
)
else
:
raise
ValueError
(
'Expected a float for column %i but got %s'
%
(
column
,
type
(
value
)))
elif
type_
==
GObject
.
TYPE_LONG
or
type_
==
GObject
.
TYPE_INT
:
if
isinstance
(
value
,
int
):
value
=
int
(
value
)
elif
sys
.
version_info
<
(
3
,
0
):
if
isinstance
(
value
,
long
):
value
=
long
(
value
)
else
:
raise
ValueError
(
'Expected an long for column %i but got %s'
%
(
column
,
type
(
value
)))
raise
ValueError
(
'Expected string or unicode for column %i but got %s%s'
%
(
column
,
value
,
type
(
value
)))
else
:
raise
ValueError
(
'Expected a string for column %i but got %s'
%
(
column
,
type
(
value
)))
elif
type_
==
GObject
.
TYPE_FLOAT
or
type_
==
GObject
.
TYPE_DOUBLE
:
if
isinstance
(
value
,
float
):
value
=
float
(
value
)
else
:
raise
ValueError
(
'Expected a float for column %i but got %s'
%
(
column
,
type
(
value
)))
elif
type_
==
GObject
.
TYPE_LONG
or
type_
==
GObject
.
TYPE_INT
:
if
isinstance
(
value
,
int
):
value
=
int
(
value
)
elif
sys
.
version_info
<
(
3
,
0
):
if
isinstance
(
value
,
long
):
value
=
long
(
value
)
else
:
raise
ValueError
(
'Expected an integer for column %i but got %s'
%
(
column
,
type
(
value
)))
elif
type_
==
GObject
.
TYPE_BOOLEAN
:
cmp_classes
=
[
int
]
raise
ValueError
(
'Expected an long for column %i but got %s'
%
(
column
,
type
(
value
)))
else
:
raise
ValueError
(
'Expected an integer for column %i but got %s'
%
(
column
,
type
(
value
)))
elif
type_
==
GObject
.
TYPE_BOOLEAN
:
cmp_classes
=
[
int
]
if
sys
.
version_info
<
(
3
,
0
):
cmp_classes
.
append
(
long
)
if
isinstance
(
value
,
tuple
(
cmp_classes
)):
value
=
bool
(
value
)
else
:
raise
ValueError
(
'Expected a bool for column %i but got %s'
%
(
column
,
type
(
value
)))
else
:
# use GValues directly to marshal to the correct type
# standard object checks should take care of validation
# so we don't have to do it here
value_container
=
GObject
.
Value
()
value_container
.
init
(
type_
)
if
type_
==
GObject
.
TYPE_CHAR
:
value_container
.
set_char
(
value
)
value
=
value_container
elif
type_
==
GObject
.
TYPE_UCHAR
:
value_container
.
set_uchar
(
value
)
value
=
value_container
elif
type_
==
GObject
.
TYPE_UNICHAR
:
cmp_classes
=
[
str
]
if
sys
.
version_info
<
(
3
,
0
):