Re: Copy/paste bug in Qt GUI?

2009-06-19 Thread Ville M. Vainio

On Fri, Jun 19, 2009 at 6:22 PM, Edward K. Ream wrote:

> I can't help feeling there is something fishy here.  Unicode takes an
> optional encoding argument, and that argument makes no sense if QString
> represents a unicode object.

Yes, it doesn't make any sense. My guess is that it's silently
discarded when presented with QString.


-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-19 Thread Edward K. Ream
On Fri, Jun 19, 2009 at 2:10 AM, Ville M. Vainio  wrote:

>
> On Thu, Jun 18, 2009 at 10:35 PM, Edward K. Ream
> wrote:
>
> > If QString is, in fact, a (wrapper around) a unicode string, it should be
> > possible to convert to a proper Python unicode string without specifying
> an
> > encoding.  How is that done?
>
> QString is a C++ class (not technically "wrapper") that is used to
> represent unicode strings in Qt.
>
> You can get python unicode object out of QString the way we do now,
> i.e. just use unicode(myqstring).


I can't help feeling there is something fishy here.  Unicode takes an
optional encoding argument, and that argument makes no sense if QString
represents a unicode object.

Edward

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-19 Thread Ville M. Vainio

On Thu, Jun 18, 2009 at 10:35 PM, Edward K. Ream wrote:

> If QString is, in fact, a (wrapper around) a unicode string, it should be
> possible to convert to a proper Python unicode string without specifying an
> encoding.  How is that done?

QString is a C++ class (not technically "wrapper") that is used to
represent unicode strings in Qt.

You can get python unicode object out of QString the way we do now,
i.e. just use unicode(myqstring).

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-18 Thread Edward K. Ream
On Thu, Jun 18, 2009 at 11:28 AM, Ville M. Vainio wrote:

>
> On Thu, Jun 18, 2009 at 7:02 PM, Edward K. Ream
> wrote:
>
> No, QString is a real unicode string. QByteArray is what qt uses for
> binary data (e.g. QString has toUtf8 that gives QByteArray).
>

If QString is, in fact, a (wrapper around) a unicode string, it should be
possible to convert to a proper Python unicode string without specifying an
encoding.  How is that done?

Edward

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-18 Thread Ville M. Vainio

On Thu, Jun 18, 2009 at 7:28 PM, Ville M. Vainio wrote:

> No, QSting is a real unicode string. QByteArray is what qt uses for
> binary data (e.g. QString has toUtf8 that gives QByteArray).

BTW, this is not mere speculation; I work with C++ Qt on my day job
currently, and the distinction with bytes and strings is more concrete
in that environment (like it is in python3).

I still think the aim should be to *reduce* the amount of toUnicode
calls, not increase them.

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-18 Thread Ville M. Vainio

On Thu, Jun 18, 2009 at 7:02 PM, Edward K. Ream wrote:

>> Yeah, that's why we shouldn't use g.toUnicode with QStrings (i.e. we
>> shouldn't change unicode() to g.toUnicode in qt ui).
>
> These kind of details are why there is a separate g.app.gui.toUnicode
> wrapper in the qt plugin.

Let's call it something else than toUnicode then, to avoid the
confusion. We need a version that never decodes, and use that as much
as possible.


> Thus, it appears that QString is an encoded string, **not** a unicode
> character (at least on xp).  That is, s2 is a wrapper for a utf-8 encoded

No, QSting is a real unicode string. QByteArray is what qt uses for
binary data (e.g. QString has toUtf8 that gives QByteArray).


> My hair is turning ever grayer...Maybe this will work better for Py3k??

It works better with Py3k in that it fails earlier and more often :-).
But we should be very strict about bytes/unicode distinction already.

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-18 Thread Edward K. Ream
On Thu, Jun 18, 2009 at 10:24 AM, Ville M. Vainio wrote:

>
> > Once we have a QString, all our problems are solved.  A QString is
> > simply a wrapper for a unicode object.  As such, there are is no
> > decoding to be done because unicode objects have no encoding!
>
> Yeah, that's why we shouldn't use g.toUnicode with QStrings (i.e. we
> shouldn't change unicode() to g.toUnicode in qt ui).


These kind of details are why there is a separate g.app.gui.toUnicode
wrapper in the qt plugin.

But allow me to disagree with myself :-)  It appears that QString is *not* a
wrapper from unicode objects.  I ran the following script on xp:

QQQ

@first # -*- coding: utf-8 -*-

import PyQt4.QtCore as QtCore
import PyQt4.QtGui as QtGui

s0 = unicode('La Peña','utf-8')
print s0
e = s0.encode('utf-8',"strict")
print e
s2 = QtCore.QString(s0)
print s2
s3 = unicode(s2,'utf-8')
print s3

QQQ

And got this output:

La Peña
La Pe├▒a
La Pe├▒a
La Peña

Thus, it appears that QString is an encoded string, **not** a unicode
character (at least on xp).  That is, s2 is a wrapper for a utf-8 encoded
string, so we must call unicode (with the proper encoding!) to get a proper
Python unicode string.  BTW, the documentation for QString was what lead me
to write this script.

My hair is turning ever grayer...Maybe this will work better for Py3k??

Edward

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-18 Thread Ville M. Vainio

On Thu, Jun 18, 2009 at 5:54 PM, Edward K. Ream wrote:

>> There are 2 separate operations:
>>
>> - Extract unicode object from QString
>
> Once we have a QString, all our problems are solved.  A QString is
> simply a wrapper for a unicode object.  As such, there are is no
> decoding to be done because unicode objects have no encoding!

Yeah, that's why we shouldn't use g.toUnicode with QStrings (i.e. we
shouldn't change unicode() to g.toUnicode in qt ui).

We should probably create g.ucode (for py3 compatibility), so that:

if python3:

g.ucode = str

else:

g.ucode = unicode


In fact, I think that should be used for most other cases as well,
failing loudly when 'ascii' encoding doesn't work. These problems get
much easier to debug if we get early warning about bugs, as opposed to
failing silently (creating ? characters on errors, etc).

Also:

http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-evil/


-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-18 Thread Edward K. Ream

On Jun 18, 9:39 am, "Ville M. Vainio"  wrote:
> On Thu, Jun 18, 2009 at 5:18 PM, Edward K. Ream wrote:
> > P.S.  The reason I keep going on about g.toUnicode is that it is the
> > foundation of Leo3k.  In particular, the 'unicode' function does not exist
> > in Py3k, and so it must be wrapped.
>
> But then it should be just aliased to str.

That's what happens.  Take a look.

BTW, I have a half memory that the reason g.toUnicode has the fairly
bizarre coding style is to avoid Python errors.  Even so, pylint
complains that 'byte' doesn't exist, at least when pylint is run with
Python 2.x. I should probably have added a note to myself...

> There are 2 separate operations:
>
> - Extract unicode object from QString

Once we have a QString, all our problems are solved.  A QString is
simply a wrapper for a unicode object.  As such, there are is no
decoding to be done because unicode objects have no encoding!

> - Read file, producing unicode

The process of reading the file, passing .leo files to sax, and
getting objects (vnodes, etc) containing unicode is a bit
complicated.  For example, we have to clean characters that would
cause sax to choke before sending those characters to sax.  These
problems are likely unavoidable, but I believe the Leo3k code will
work pretty much as is.

Edward
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-18 Thread Ville M. Vainio

On Thu, Jun 18, 2009 at 5:18 PM, Edward K. Ream wrote:

> P.S.  The reason I keep going on about g.toUnicode is that it is the
> foundation of Leo3k.  In particular, the 'unicode' function does not exist
> in Py3k, and so it must be wrapped.

But then it should be just aliased to str. It definitely shouldn't do
any encoding - because if we "fall back" to encoding, we are hiding
bugs. There are 2 separate operations:

- Extract unicode object from QString
- Read file, producing unicode

These are unrelated, apart from the fact that the return value is
unicode object.

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-18 Thread Edward K. Ream
On Thu, Jun 18, 2009 at 9:00 AM, Ville M. Vainio  wrote:

>
> > I think this can, and should, be done.  g.app.gui.toUnicode will
> > simply do:
> >
> >return g.toUnicode(s,g.app.gui.defaultQtEncoding)
> >
> > where defaultQtEncoding is utf-8 by default, and can be set by @string
> > default_qt_encoding setting.
>
> I still think this is wrong (my understanding of unicode), but it's
> even more wrong to have it as setting. If anything, it should be
> hardcoded to utf-8.


Well, that is, in essence, what we get by calling g.toUnicode!

In my experience, a setting that *can* match the Python's default encoding
may be worthwhile.  It was with tk.  Furthermore, having that setting
default to utf-8 can hardly be worse than the present situation.  If people
find the setting useful, fine.  If not, nothing has been lost.

Edward

P.S.  The reason I keep going on about g.toUnicode is that it is the
foundation of Leo3k.  In particular, the 'unicode' function does not exist
in Py3k, and so it must be wrapped.

BTW, the present version of g.toUnicode goes overboard in trying to
eliminate duplicate code.  It would be much clearer to accept the
duplication, and have two completely separate versions of the code--one for
Python 2.x and one for Python 3.x.  I'll fix this early in the b3 cycle.

EKR

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-18 Thread Ville M. Vainio

On Thu, Jun 18, 2009 at 4:57 PM, Edward K. Ream wrote:

>> we may have to add a
>> setting that will tell the qt gui which encoding to assume by default.  We
>> will then pass that as a the encoding param to g.toUnicode, for example.
>
> I think this can, and should, be done.  g.app.gui.toUnicode will
> simply do:
>
>    return g.toUnicode(s,g.app.gui.defaultQtEncoding)
>
> where defaultQtEncoding is utf-8 by default, and can be set by @string
> default_qt_encoding setting.

I still think this is wrong (my understanding of unicode), but it's
even more wrong to have it as setting. If anything, it should be
hardcoded to utf-8.

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-18 Thread Ville M. Vainio

On Thu, Jun 18, 2009 at 4:50 PM, Edward K. Ream wrote:

>> We should use setMimeData of QClipboard to set binary data:
>>
>> http://doc.trolltech.com/4.5/qclipboard.html#setMimeData
>
> When do we ever want to put binary data to the clipboard?  Are you calling
> utf-8 encoded strings binary data?

Yes, utf-8 encoded strings are binary data ('bytes' on Python 3).
Treating it as "text" is wrong, and we are (correctly) getting an
exception for that.  Utf-8 can be converted to text (unicode) by
decoding it.

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-18 Thread Edward K. Ream

On Jun 18, 8:50 am, "Edward K. Ream"  wrote:
> we may have to add a
> setting that will tell the qt gui which encoding to assume by default.  We
> will then pass that as a the encoding param to g.toUnicode, for example.

I think this can, and should, be done.  g.app.gui.toUnicode will
simply do:

return g.toUnicode(s,g.app.gui.defaultQtEncoding)

where defaultQtEncoding is utf-8 by default, and can be set by @string
default_qt_encoding setting.

Edward
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-18 Thread Edward K. Ream
On Wed, Jun 17, 2009 at 9:46 AM, Ville M. Vainio  wrote:

>
> Our current clipboard approach has a fundamental problem: we are
> treating clipboard as text (unicode), but the xml data (outline
> structure) is not text. It's 8 bit binary data (that happens to be in
> utf8).


This may be a bug, but I wouldn't get excited and call it a fundamental
problem.

Leo assumes that all data it deals with internally is unicode.  This, and
nothing else, is fundamental.  To make this work, Leo converts from
so-called encoded formats to unicode when reading data, and converts back to
encoded formats when writing data.

g.toUnicode is the basis of this approach.  There may be, as you suggest,
instances where g.toUnicode isn't the easiest, or even correct, way to
convert data to unicode.  If so, we can deal with it, and use comments to
explain why g.toUnicode won't work.

I'm sure you understand this, but I want to say it anyway to emphasize what
is, and isn't, fundamentally important.

As you your recent change to g.app.gui.toUnicode::

g.trace('Warning - toUnicode does encoding (bugs possible)')
return unicode(s,encoding,errors='replace')

This is, in essence, exactly what g.toUnicode does.  Yes, errors are
possible if the encoding specified does not match the encoding used to
created the encoded text.  g.toUnicode will convert "bad" characters to '?'
characters.

By the way, neither unicode nor g.toUnicode *does* encoding (that's the
reverse process).  Instead, these functions *assume* an encoding.  If there
is, in fact, a "fundamental" problem, it is that it is not possible, in
general, given an encoded string, to deduce the encoding.  But we aren't
going to change that.

Please note that g.app.gui.toUnicode is called only from the qt gui plugin.
Whatever encoding problems arise apply only to the gui plugin.  In essence,
the "general/fundamental" problem is simply stated:  how do we know what
encoding to pass to g.app.gui.toUnicode?

The tk gui handles this by using various settings to specify encodings.  All
will be well if those settings match the user's installation.

In short, there is a general/fundamental problem with calling unicode, or
equivalently, g.toUnicode, namely to avoid data loss (converting characters
to '?' characters, for instance) the encoding specified must match the
actual encoding of the encoded data.  There is no way around this problem,
and it has nothing specifically to do with Leo.

In *some* cases, we may be able to know for sure what the encoding is.
That's always good :-)

I suspect, but do not know for sure, that many of these problems will
disappear if people will specify utf-8 for Python's default encoding in
sitecustomize.py.  Certainly, I have no problems with non-ascii characters
on my machines.  If that isn't convenient for people, we may have to add a
setting that will tell the qt gui which encoding to assume by default.  We
will then pass that as a the encoding param to g.toUnicode, for example.

Separate method should be used to put binary data to clipboard (in tk,
> it's probably always binary data?).
>
> We should use setMimeData of QClipboard to set binary data:
>
> http://doc.trolltech.com/4.5/qclipboard.html#setMimeData


When do we ever want to put binary data to the clipboard?  Are you calling
utf-8 encoded strings binary data?

Edward

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Ville M. Vainio

On Wed, Jun 17, 2009 at 6:34 PM, Ville M. Vainio wrote:

> I disagree about this - in fact I think we should never "convert" to
> unicode. We use unicode() to get python unicode objects from QStrings
> (i.e. no conversion happens). Calling a function that *possibly* does
> conversion is a recipe for trouble because it hides errors (as
> happened today).

Actually, what happened today (and what was "fixed" by doing utf8
conversion) was not really a fix at all. We just did a workaround that
incidentally works, but the bug revealed a logical fallacy in the
codebase (confusion of binary vs. unicode). I think we should fail as
loudly as possibly whenever something like this happens, instead of
sweeping the problem under the rug by "catch-all" functions like
g.toUnicode. The only canonical place to deal with non-unicode data is
when reading/writing binary files - or, as with this bug, when
reading/writing binary data to clipboard. The amount of conversions
should be few and far apart.

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Ville M. Vainio

On Wed, Jun 17, 2009 at 6:29 PM, Edward K. Ream wrote:

> I also think that all calls to unicode in qtGui.py should be replaced by
> g.toUnicode.  This must happen anyway to support Py3k.

I disagree about this - in fact I think we should never "convert" to
unicode. We use unicode() to get python unicode objects from QStrings
(i.e. no conversion happens). Calling a function that *possibly* does
conversion is a recipe for trouble because it hides errors (as
happened today).



-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Edward K. Ream
On Wed, Jun 17, 2009 at 10:14 AM, Ville M. Vainio wrote:

>
> On Wed, Jun 17, 2009 at 6:00 PM, Ville M. Vainio
> wrote:
>
> > This is still fundamentally a "wrong thing to do", so I emit a g.trace
> > warning as well.
>
> Suggested "correct" approach:


Thanks for your quick fix.  I don't have time this morning to review your
suggestion.  I'll do so asap.

I also think that all calls to unicode in qtGui.py should be replaced by
g.toUnicode.  This must happen anyway to support Py3k.

Edward

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Ville M. Vainio

On Wed, Jun 17, 2009 at 6:00 PM, Ville M. Vainio wrote:

> This is still fundamentally a "wrong thing to do", so I emit a g.trace
> warning as well.

Suggested "correct" approach:

In

Code-->Core classes-->@thin leoCommands.py-->class commands-->Command
handlers...-->Outline menu...--> Top Level... (Commands)-->Cut & Paste
Outlines-->copyOutline

Do not call replaceClipboardWith - rather, call

clipboardSetBinary("application/leo-outline", s)

On tk, that can call replaceClipboardWith directly.


In Command handlers...-->Outline menu...--> Top Level...
(Commands)-->Cut & Paste Outlines-->pasteOutline

It shouldn't call getTextFromClipboard, but rather a new method
getBinaryFromClipboard("application/leo-outline")

I think this will also eliminate accidental pasting of outline xml to nodes.

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Ville M. Vainio

On Wed, Jun 17, 2009 at 5:54 PM, Edward K. Ream wrote:

>> Doesn't this have to fail if the default encoding is ascii?  What happens
>> if you replace with:
>>
>>     try:
>>     return unicode(s,'utf-8')
>>     except Exception:
>>     return unicode(s,'utf-8',errors='replace')

It works. I committed and pushed.

This is still fundamentally a "wrong thing to do", so I emit a g.trace
warning as well.

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Edward K. Ream
On Wed, Jun 17, 2009 at 9:53 AM, Edward K. Ream  wrote:

>
> Doesn't this have to fail if the default encoding is ascii?  What happens
> if you replace with:
>
> try:
> return unicode(s,'utf-8')
> except Exception:
> return unicode(s,'utf-8',errors='replace')
>

Actually, the above is pretty similar to:

return g.toUnicode(s,'utf-8')

EKR

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Edward K. Ream
On Wed, Jun 17, 2009 at 9:38 AM, Ville M. Vainio  wrote:

>
> Culprit is this:
>
> 6867def toUnicode (self,s,encoding='utf-8',reportErrors=True):
> 6868
> 6869try:
> 6870return unicode(s)
> 6871except Exception:
> 6872 -> return ''


Thanks for your help.

Doesn't this have to fail if the default encoding is ascii?  What happens if
you replace with:

try:
return unicode(s,'utf-8')
except Exception:
return unicode(s,'utf-8',errors='replace')

Edward

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Ville M. Vainio

Our current clipboard approach has a fundamental problem: we are
treating clipboard as text (unicode), but the xml data (outline
structure) is not text. It's 8 bit binary data (that happens to be in
utf8).

Separate method should be used to put binary data to clipboard (in tk,
it's probably always binary data?).

We should use setMimeData of QClipboard to set binary data:

http://doc.trolltech.com/4.5/qclipboard.html#setMimeData

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Ville M. Vainio

On Wed, Jun 17, 2009 at 5:35 PM, Ville M. Vainio wrote:

>> Nothing should be reliant on that, but it may help you reproduce the problem.
>
> I enabled tracing in Qt gui-->@thin qtGui.py-->Gui wrapper-->class
> leoQtGui-->Clipboard (qtGui)
>
> ctrl+shift+c on a node that has body 'ää' shows:
>
> replaceClipboardWith: 0 

Culprit is this:

6867def toUnicode (self,s,encoding='utf-8',reportErrors=True):
6868
6869try:
6870return unicode(s)
6871except Exception:
6872 -> return ''


-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Ville M. Vainio

On Wed, Jun 17, 2009 at 5:30 PM, Ville M. Vainio wrote:
> On Wed, Jun 17, 2009 at 5:15 PM, Edward K. Ream wrote:
>
>> Works for me on 9.04.  What is your default string encoding?
>
> [~]|9> sys.getdefaultencoding()
>   <9> 'ascii'
>
> Nothing should be reliant on that, but it may help you reproduce the problem.

I enabled tracing in Qt gui-->@thin qtGui.py-->Gui wrapper-->class
leoQtGui-->Clipboard (qtGui)

ctrl+shift+c on a node that has body 'ää' shows:

replaceClipboardWith: 0 

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Ville M. Vainio

On Wed, Jun 17, 2009 at 5:15 PM, Edward K. Ream wrote:

> Works for me on 9.04.  What is your default string encoding?

[~]|9> sys.getdefaultencoding()
   <9> 'ascii'

Nothing should be reliant on that, but it may help you reproduce the problem.

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Edward K. Ream
On Wed, Jun 17, 2009 at 9:04 AM, Ville M. Vainio  wrote:

>
> > This works for me on xp and ubuntu.
>
> I can repro it on Ubuntu 9.04. Body ''


Works for me on 9.04.  What is your default string encoding?

Edward

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Ville M. Vainio

On Wed, Jun 17, 2009 at 5:00 PM, Edward K. Ream wrote:

>> Thanks for the original report and your help, Ville.  I'll fix this before
>> b2 and add a unit test :-)
>
> This works for me on xp and ubuntu.

I can repro it on Ubuntu 9.04. Body ''

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Edward K. Ream



On Jun 17, 8:12 am, "Edward K. Ream"  wrote:

> Thanks for the original report and your help, Ville.  I'll fix this before
> b2 and add a unit test :-)

This works for me on xp and ubuntu.

Please run Leo from a console window.  Do you see any unusual errors?

Please make the following changes in g.toUnicode:

- Just after the def line, add the line:

reportErrors = True

Recreate the bug.  Do you see any message?

You might also try setting sys.setdefaultencoding('utf-8') in
sitecustomize.py.  Does that make a difference?

Edward






--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Edward K. Ream
On Wed, Jun 17, 2009 at 6:10 AM, zpcspm  wrote:

>
> On Jun 17, 1:58 pm, "Ville M. Vainio"  wrote:
> > On Wed, Jun 17, 2009 at 1:10 PM, zpcspm wrote:
> > > I didn't fill (yet!) a bug report at launchpad. I'm a bit skeptical,
> > > because it doesn't always go wrong. If at least one more person will
> > > be able to reproduce this, then it will go to the bug tracker.
> >
> > Is that about unicode chars in body? Can you isolate the prob to
> > particular subtree?
>
> Good hint, thank you.
> Indeed I had a line of unicode chars in that subtree.
> Removing it fixed the issue.


Thanks for the original report and your help, Ville.  I'll fix this before
b2 and add a unit test :-)

Oh my,  maybe I should relax just a bit more and allow the b2 date to maybe
slip again.  I've got some (enjoyable) family matters to attend to today,
and more importantly, I would like to fix all urgent bugs before b2.  Still,
I'm shooting for Friday.

Edward

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Ville M. Vainio

On Wed, Jun 17, 2009 at 2:10 PM, zpcspm wrote:

> Good hint, thank you.
> Indeed I had a line of unicode chars in that subtree.
> Removing it fixed the issue.
> I'm still unhappy about how leo behaves in this situation.
> I can use the Tk GUI fine till this will be fixed, but maybe you guys
> can stick a debug message to be printed to the console in this
> situation?

Actually, that bug was fixed earlier, but seems it has broken again.
It's easy to fix (perhaps this time with a new unit test to go with
it).

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread zpcspm

On Jun 17, 1:58 pm, "Ville M. Vainio"  wrote:
> On Wed, Jun 17, 2009 at 1:10 PM, zpcspm wrote:
> > I didn't fill (yet!) a bug report at launchpad. I'm a bit skeptical,
> > because it doesn't always go wrong. If at least one more person will
> > be able to reproduce this, then it will go to the bug tracker.
>
> Is that about unicode chars in body? Can you isolate the prob to
> particular subtree?

Good hint, thank you.
Indeed I had a line of unicode chars in that subtree.
Removing it fixed the issue.
I'm still unhappy about how leo behaves in this situation.
I can use the Tk GUI fine till this will be fixed, but maybe you guys
can stick a debug message to be printed to the console in this
situation?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Re: Copy/paste bug in Qt GUI?

2009-06-17 Thread Ville M. Vainio

On Wed, Jun 17, 2009 at 1:10 PM, zpcspm wrote:

> I didn't fill (yet!) a bug report at launchpad. I'm a bit skeptical,
> because it doesn't always go wrong. If at least one more person will
> be able to reproduce this, then it will go to the bug tracker.

Is that about unicode chars in body? Can you isolate the prob to
particular subtree?

-- 
Ville M. Vainio
http://tinyurl.com/vainio

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---



Copy/paste bug in Qt GUI?

2009-06-17 Thread zpcspm

I'm experiencing some strange behaviour when using Qt GUI (current
trunk, r2050).

I had an outline open today, tried "Copy node", then "Paste node" from
Outline main menu and it didn't work. I have tried the commands "copy-
node" and "paste-node" instead, they didn't work as well.

I have tried one more time, to get some clear steps for reproducing
the behaviour, and this is what I've got:

Run leo with Qt GUI. It loads the default workbook.leo. Copy/paste
works! Open an existing outline from "Recent Files" menu. Copy/paste
doesn't work anymore.

I didn't fill (yet!) a bug report at launchpad. I'm a bit skeptical,
because it doesn't always go wrong. If at least one more person will
be able to reproduce this, then it will go to the bug tracker.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~--~~~~--~~--~--~---