Closed GoogleCodeExporter closed 9 years ago
I don't know how to count bytes, because like chinese characters, for different
encoding will get different number.
Original comment by limo...@gmail.com
on 2 Sep 2010 at 4:10
I am just asking to count "bytes", not "characters". So you don't need to
consider Chinese characters at all.
Just count the ascii bytes. That will be useful when developing some
network-packet send-and-receive programs. And in many network protocols we need
to count how many bytes are going to be transmitted during a sample session.
Original comment by RayLuo....@gmail.com
on 8 Sep 2010 at 4:16
So, for ascii, characters count will be the same as unicode count. But for
unicode especially chinese character, one chinese character in gtk encoding
will be 2 bytes, but in utf-8 encoding will be 3 bytes.
And you can count the selection text youself right now like this:
open shell windows, and enter
len(app.frame.document.GetSelectedText())
Original comment by limo...@gmail.com
on 8 Sep 2010 at 4:27
Well, that helps a bit. So I put following line inside a script named count.py
and assign it CTRL+0.
win.messagewindow.SetText( 'Selected %d bytes' % len(app.frame.document.GetSelectedText()) )
That is better, but I still need to open message window by myself. Can it be
open automatically? How?
Or, can the message be output as a tooltip at document window then
automatically disappear? Or can the message be output in the status bar of the
document window? Either way I don't have to manually open-and/or-close message
window.
Original comment by RayLuo....@gmail.com
on 8 Sep 2010 at 7:13
Ok, I manage to find the best User-Experience solution (so far) myself. Put the
following line in count.py and put it as a script, assign hot key CTRL+0
app.frame.document.CallTipShow(
app.frame.document.GetCurrentPos(),
'Selected %d bytes' % len(app.frame.document.GetSelectedText()) )
But I still think this feature should better be builtin feature of Ulipad: when
selecting some content, automatically display selected bytes on the status bar.
Take it or not.
Thanks anyway.
Original comment by RayLuo....@gmail.com
on 8 Sep 2010 at 7:29
Yes, just write script like this:
{{{
def run(win):
from common import setmessage
setmessage(win, 'Selected %d bytes' % len(app.frame.document.GetSelectedText()) )
run(win)
}}}
Original comment by limo...@gmail.com
on 8 Sep 2010 at 7:30
There are two problems need to be resolved:
1. How to count the "bytes" I prefer unicode character count.
2. Where to display, and how to display, for example, below is statusbar, just
like:
[ ][Line: xx][Column:
xx][Line ending: \n][Encoding:UTF-8]
so which position would you like, for example add new column after Column, and
which is the best prompt, an example:
[ ][Line: xx][Column:
xx][Selected:xx][Line ending: \n][Encoding:UTF-8]
Original comment by limo...@gmail.com
on 8 Sep 2010 at 7:41
Answer.
0. I don't know why but here on my Ulipad4, your code "from common import
setmessage" doesn't work at all. Did you try it?
1. I said that before, no need to worry about unicode or not. That is a problem
for user (and they are developer too), not for you. You just need to do
"len(app.frame.document.GetSelectedText())" and let your user to learn how it
works. Besides, the current implementation can count unicode already. Didn't
you try that?
3. Whatever position in statusbar is a good position! Your example is good! Go
ahead!
Original comment by RayLuo....@gmail.com
on 8 Sep 2010 at 7:57
0. should be from modules.common import setmessage
1. becase GetSelectedText() will return unicode string.
2. OK
Original comment by limo...@gmail.com
on 8 Sep 2010 at 8:01
already in svn , just try it. But I used UpdateUI event, becaseu I can't find a
better event to process the selected text changing event, so I don't know if
this will make the CPU high.
Original comment by limo...@gmail.com
on 8 Sep 2010 at 8:26
Original comment by limo...@gmail.com
on 9 Sep 2010 at 2:56
Original issue reported on code.google.com by
RayLuo....@gmail.com
on 2 Sep 2010 at 4:06