google-code-export / ulipad

Automatically exported from code.google.com/p/ulipad
0 stars 0 forks source link

Feature request: Count data bytes when selecting some text #259

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hope ulipad can count how many bytes are selected when user is selecting some 
text.

What steps will reproduce the problem?
1. Open a text file
2. Select some text

What is the expected output? What do you see instead?
I hope in somewhere in the status bar can tell me, how many bytes I've 
selected. Ultraedit has this feature.

Original issue reported on code.google.com by RayLuo....@gmail.com on 2 Sep 2010 at 4:06

GoogleCodeExporter commented 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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago

Original comment by limo...@gmail.com on 9 Sep 2010 at 2:56