Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
pygobject
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
147
Issues
147
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GNOME
pygobject
Commits
654711d0
Commit
654711d0
authored
Nov 08, 2011
by
Sebastian Pölsterl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert all strings to utf-8 encoding when retrieving from TreeModel
https://bugzilla.gnome.org/show_bug.cgi?id=663610
parent
4f637212
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
1 deletions
+47
-1
Gtk.py
gi/overrides/Gtk.py
+15
-0
compathelper.py
tests/compathelper.py
+2
-0
test_overrides.py
tests/test_overrides.py
+30
-1
No files found.
gi/overrides/Gtk.py
View file @
654711d0
...
...
@@ -797,6 +797,13 @@ class TreeModel(Gtk.TreeModel):
self
.
set_value
(
treeiter
,
i
,
value
)
def
_decode_value
(
self
,
treeiter
,
column
,
value
):
type_
=
self
.
get_column_type
(
column
)
if
type_
==
GObject
.
TYPE_STRING
and
sys
.
version_info
<
(
3
,
0
):
value
=
value
.
decode
(
'UTF-8'
)
return
value
def
_convert_value
(
self
,
treeiter
,
column
,
value
):
if
value
is
None
:
return
...
...
@@ -965,6 +972,10 @@ class ListStore(Gtk.ListStore, TreeModel, TreeSortable):
value
=
self
.
_convert_value
(
treeiter
,
column
,
value
)
Gtk
.
ListStore
.
set_value
(
self
,
treeiter
,
column
,
value
)
def
get_value
(
self
,
treeiter
,
column
):
value
=
Gtk
.
ListStore
.
get_value
(
self
,
treeiter
,
column
)
return
self
.
_decode_value
(
treeiter
,
column
,
value
)
def
set
(
self
,
treeiter
,
*
args
):
def
_set_lists
(
columns
,
values
):
...
...
@@ -1180,6 +1191,10 @@ class TreeStore(Gtk.TreeStore, TreeModel, TreeSortable):
value
=
self
.
_convert_value
(
treeiter
,
column
,
value
)
Gtk
.
TreeStore
.
set_value
(
self
,
treeiter
,
column
,
value
)
def
get_value
(
self
,
treeiter
,
column
):
value
=
Gtk
.
TreeStore
.
get_value
(
self
,
treeiter
,
column
)
return
self
.
_decode_value
(
treeiter
,
column
,
value
)
def
set
(
self
,
treeiter
,
*
args
):
def
_set_lists
(
columns
,
values
):
...
...
tests/compathelper.py
View file @
654711d0
...
...
@@ -62,8 +62,10 @@ if sys.version_info >= (3, 0):
'''
_unicode
=
lambda
s
:
str
(
s
)
_unichr
=
chr
else
:
_long
=
long
_basestring
=
basestring
_bytes
=
str
_unicode
=
lambda
s
:
unicode
(
s
,
'UTF-8'
)
_unichr
=
unichr
tests/test_overrides.py
View file @
654711d0
# -*- coding: utf-8 -*-
# -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
...
...
@@ -7,7 +8,7 @@ import sys
import
os
sys
.
path
.
insert
(
0
,
"../"
)
from
compathelper
import
_long
,
_unicode
,
_bytes
from
compathelper
import
_long
,
_unicode
,
_bytes
,
_unichr
from
gi.repository
import
GLib
from
gi.repository
import
GObject
...
...
@@ -1261,6 +1262,34 @@ class TestGtk(unittest.TestCase):
model
[
0
]
=
(
3
,
"three"
,
-
0.3
)
def
test_tree_model_unicode
(
self
):
model
=
Gtk
.
ListStore
(
str
)
text
=
(
_unicode
(
"just
\n
a
\t
string"
),
_unicode
(
"Tr"
)
+
_unichr
(
0xf6
)
+
_unicode
(
"del"
),
_unicode
(
"N"
)
+
_unichr
(
0xe1
)
+
_unicode
(
"m"
)
+
_unichr
(
0xe8
),
_unichr
(
0xff
)
+
_unichr
(
0xdf
)
+
_unicode
(
"er"
),
_unichr
(
0x152
)
+
_unichr
(
0x180
)
+
_unichr
(
0x1d25
))
for
item
in
text
:
model
.
append
([
item
])
def
byte_compare
(
have
,
expected
):
if
sys
.
version_info
<
(
3
,
0
):
self
.
assertTrue
(
isinstance
(
have
,
unicode
))
else
:
self
.
assertTrue
(
isinstance
(
have
,
str
))
self
.
assertEqual
(
len
(
have
),
len
(
expected
))
for
i
in
range
(
len
(
expected
)):
a
=
have
[
i
]
b
=
expected
[
i
]
self
.
assertEqual
(
a
,
b
)
self
.
assertEqual
(
ord
(
a
),
ord
(
b
))
for
i
in
range
(
len
(
model
)):
byte_compare
(
model
[
i
][
0
],
text
[
i
])
def
test_tree_row_slice
(
self
):
model
=
Gtk
.
ListStore
(
int
,
str
,
float
)
model
.
append
([
1
,
"one"
,
-
0.1
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment