Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102634

Re: What's the best/neatest way to get Unicode data from a database into a grid cell?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Vlastimil Brom <vlastimil.brom@gmail.com>
Newsgroups comp.lang.python
Subject Re: What's the best/neatest way to get Unicode data from a database into a grid cell?
Date Sun, 7 Feb 2016 19:22:34 +0100
Lines 65
Message-ID <mailman.77.1454869362.2317.python-list@python.org> (permalink)
References <tqljoc-nad.ln1@esprimo.zbmc.eu>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de WF3J+uSqv8yGmDFve2Fp7wbXu096JtKCj/tG6x/yNVnw==
Return-Path <vlastimil.brom@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '(using': 0.07; '-*-': 0.07; 'utf-8': 0.07; '(instead': 0.09; 'coding:': 0.09; 'grid': 0.09; 'newly': 0.09; 'other)': 0.09; 'sqlite': 0.09; 'subject:into': 0.09; 'utf8': 0.09; 'python': 0.10; '2.7': 0.13; 'encoding': 0.15; 'subject: \n ': 0.15; 'subsequent': 0.15; '(mainly': 0.16; '(within': 0.16; 'declaration': 0.16; 'display,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Unicode': 0.16; 'app': 0.16; 'changes': 0.20; 'handles': 0.20; 'correctly.': 0.22; 'seems': 0.23; 'tried': 0.24; 'header :In-Reply-To:1': 0.24; 'chris': 0.26; 'error': 0.27; 'message- id:@mail.gmail.com': 0.27; 'handled': 0.29; "i'm": 0.30; 'subject:/': 0.30; 'url:mailman': 0.30; 'creating': 0.30; 'code': 0.30; 'are:': 0.32; 'point': 0.33; 'url:python': 0.33; 'displayed': 0.33; 'url:listinfo': 0.34; 'correctly': 0.34; 'file': 0.34; 'handle': 0.34; 'received:google.com': 0.35; 'saved': 0.35; 'unicode': 0.35; 'quite': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; '(and': 0.36; 'beginning': 0.36; 'loaded': 0.36; 'to:addr :python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'beyond': 0.37; 'seem': 0.37; 'starting': 0.37; 'received:209': 0.38; 'green': 0.38; 'names': 0.38; 'skip:s 40': 0.38; 'hi,': 0.38; 'why': 0.39; 'data': 0.39; 'does': 0.39; 'subject:from': 0.39; 'subject:the': 0.39; 'skip:e 20': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'some': 0.40; 'your': 0.60; 'back': 0.62; 'intent': 0.66; 'realise': 0.66; 'subject:get': 0.81; '3.4': 0.84; 'greek': 0.84; 'start.': 0.84; 'to:name:python': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=rFDH4s9DmKxhPEoRdug9VHP9ieXgCpQl9ThmCGdmvzQ=; b=rkV6g01FJpuy/J6AANB8mdIifluahymGXZAQ9CIQ+NQOznn5yYCcjRmK5IdHFro3nh vVihaPigS1N5joGJBYfbvyxuSL7ElXV/cqT5mE5sJsiwRIUGA/A2ci8EsilJwkFSeHyO F68UfLT8p3qS4ZBV5m8WsBkGWO6jWx7UhJG/+l8PC8eAmac0s1gpPfnHl6k5+hrS/IaZ RHnNi/apZUbl9E/u8AZVtvZf07LdUj62Bmm0QmY7Gb5SR0VAe568AYrHtXcea5yXc/R9 Q7AF+kcYlAlMn3AKT+DX0DqIEhYZI1skzJL6D+QmZYpxq/D+pKXJq0eBfqfBunQ2LquQ 8FDw==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=rFDH4s9DmKxhPEoRdug9VHP9ieXgCpQl9ThmCGdmvzQ=; b=ZfI7vSmR2DLM23DCsWUAGx1yvHjdFe1olz3qVGgJQJ9C42VQDcjYhbH94gQI92Z9QY GcPbUVc7Bt5UnfoT3LYZU2IcnT0s3CnVd7gWxwf21iwd/Jk6GTXSWiifvtTE5ucOPNeE WzeO3/HRLxp6D+hBovjDrUGnm1PAZC/QoJiAtEMtmqkgU151hxDJnIt+psy9YkvQ6Tga Gs3XZUeatiLJJrrlrdD1Xj+/fKx2j9REzJlGUOnVqQy8e1z0aWPUbQmA5OzSjHeaDFaf w7jhXyhdQ6r0reMpwCoLdtmBUPe2NUtDHFiaE8nuQrErSaFKEL6bCZeprqnqro195W/0 sd1A==
X-Gm-Message-State AG10YORYAJpv7fcjKrUUVkUH6yXvKLBkxrVkzMlqqqQOkJIJVepDqGg9Nf4PqZw5qqSPyOaSaBzEoab5mbAa5g==
X-Received by 10.25.90.83 with SMTP id o80mr9966850lfb.23.1454869354550; Sun, 07 Feb 2016 10:22:34 -0800 (PST)
In-Reply-To <tqljoc-nad.ln1@esprimo.zbmc.eu>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21rc2
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:102634

Show key headers only | View raw


2016-02-07 12:19 GMT+01:00  <cl@isbd.net>:
> I'm using this as a starting point for creating a grid to view and
> edit some sqlite data:-
>     http://www.salstat.com/news/linking-wxgrid-to-sqlite-database-in-python-an-example
>
> I can actually understand most of it which is a good start.
>
> However my database has quite a lot of Unicode data as there are
> French (and other) names with accents etc.  What's the right way to
> handle this reasonably neatly?  At the moment it traps an error at
> line 37:-
>     self.SetCellValue(row_num, i, str(cells[i]))
>
> I realise why this fails (I think) but how should one program this so
> that:-
>     1 - the accented characters are displayed correctly in the grid cell
>     2 - One can edit the cell with accented characters
>
> (I'll get round how to get the accented characters back to the
> database later!)
>
> My system (xubuntu 15.10) is all UTF8 so accented characters are
> handled by the display, in terminals, etc. correctly.  I'm currently
> using python 2.7 for this but would be quite happy to move to 3.4 if
> this handles UTF8 better (I seem to remember it does maybe).
>
> --
> Chris Green
> ยท
> --
> https://mail.python.org/mailman/listinfo/python-list

Hi,
your code in
http://www.salstat.com/news/linking-wxgrid-to-sqlite-database-in-python-an-example

seems to work for me after small changes with both python 2.7 and 3.4
(using wx Phoenix)
the changes I made are:
- encoding declaration at the beginning of the file (mainly for py 2,
if utf-8 is used):

#! Python
# -*- coding: utf-8 -*-

- removing the str(...) call in the offending line you mentioned:
 self.SetCellValue(row_num, i, cells[i])
(what was the intent of the conversion to str?)

- corrected event name (insted of EVT_GRID_CELL_CHANGE)
self.Bind(gridlib.EVT_GRID_CELL_CHANGED, self.CellContentsChanged)

- normal App() call (instead of the PySimpleApp)

app = wx.App()

I randomly tried some characters using Latin, Greek etc. characters
(within BMP) as well as Gothic - beyond the FFFF range - the cell
content seems to be saved and and newly loaded from the sqlite db on
subsequent calls of the app.

regards,
    vbr

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What's the best/neatest way to get Unicode data from a database into a grid cell? cl@isbd.net - 2016-02-07 11:19 +0000
  Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Chris Angelico <rosuav@gmail.com> - 2016-02-07 22:56 +1100
    Re: What's the best/neatest way to get Unicode data from a database into a grid cell? cl@isbd.net - 2016-02-07 12:42 +0000
      Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Chris Angelico <rosuav@gmail.com> - 2016-02-08 00:11 +1100
        Re: What's the best/neatest way to get Unicode data from a database into a grid cell? cl@isbd.net - 2016-02-07 13:59 +0000
  Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Dietmar Schwertberger <maillist@schwertberger.de> - 2016-02-07 16:06 +0100
    Re: What's the best/neatest way to get Unicode data from a database into a grid cell? cl@isbd.net - 2016-02-08 10:22 +0000
      Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Chris Angelico <rosuav@gmail.com> - 2016-02-08 21:57 +1100
  Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Vlastimil Brom <vlastimil.brom@gmail.com> - 2016-02-07 19:22 +0100
    Re: What's the best/neatest way to get Unicode data from a database into a grid cell? cl@isbd.net - 2016-02-08 10:42 +0000
      Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Chris Angelico <rosuav@gmail.com> - 2016-02-08 21:55 +1100
      Re: What's the best/neatest way to get Unicode data from a database into a grid cell? Vlastimil Brom <vlastimil.brom@gmail.com> - 2016-02-08 16:00 +0100

csiph-web