Hello,
I would like to build a text widget featuring a width less than the
width of a character.
Example:
set myfont {-family {Courier New} -size 10 -weight normal \
-slant roman -underline 0 -overstrike 0}
text .t -bd 0 -bg red -font $myfont -width 1
pack .t
The text widget now has -width 1 (one character in the given font).
How can I give it a smaller width? Is this possible?
Thanks,
Francois
|
|
0
|
|
|
|
Reply
|
Francois
|
3/26/2011 9:18:30 PM |
|
Francois Vogel <fsvogelnew5NOSPAM@free.fr> writes:
>Hello,
>
>I would like to build a text widget featuring a width less than the
>width of a character.
>
>Example:
>
> set myfont {-family {Courier New} -size 10 -weight normal \
> -slant roman -underline 0 -overstrike 0}
> text .t -bd 0 -bg red -font $myfont -width 1
> pack .t
>
>The text widget now has -width 1 (one character in the given font).
>
>How can I give it a smaller width? Is this possible?
>
>Thanks,
>Francois
RTFM
"-width
Specifies the desired width for the window in units of characters in
the font given by the -font option. If the font does not have a uniform
width then the width of the character �0� is used in translating from
character units to screen units."
--
Pat Thoyts http://www.patthoyts.tk/
PGP fingerprint 2C 6E 98 07 2C 59 C8 97 10 CE 11 E6 04 E0 B9 DD
|
|
0
|
|
|
|
Reply
|
Pat
|
3/26/2011 10:09:53 PM
|
|
Pat Thoyts <patthoyts@users.sourceforge.net> wrote:
> Francois Vogel <fsvogelnew5NOSPAM@free.fr> writes:
>>I would like to build a text widget featuring a width less than the
>>width of a character.
>>Example:
>> set myfont {-family {Courier New} -size 10 -weight normal \
>> -slant roman -underline 0 -overstrike 0}
>> text .t -bd 0 -bg red -font $myfont -width 1
>> pack .t
>>The text widget now has -width 1 (one character in the given font).
>>How can I give it a smaller width? Is this possible?
> RTFM
> "-width
> Specifies the desired width for the window in units of characters in
> the font given by the -font option. If the font does not have a uniform
> width then the width of the character “0” is used in translating from
> character units to screen units."
I don't see, how this quote answers Francois' question. Is it meant as
a (somewhat oververbose) "no"?
Anyway, if you (the OP) intend to display only parts of letters, you could
try using a canvas text-item instead. Or, if you need the text widget's
features, embed the text-widget in the canvas.
|
|
0
|
|
|
|
Reply
|
Andreas
|
3/26/2011 11:55:47 PM
|
|
I won't claim to understand why you want this. I'll just approach it
as a puzzle. :-)
My first reaction is to put the text widget inside a frame, turn off
geometry propagation on the frame, and then explicitly set the width
of the frame:
font create myFont -family {Courier New} -size 10 -weight normal \
-slant roman -underline 0 -overstrike 0
frame .f -width 10
pack propagate .f false
pack .f -side left -fill y
text .f.t -bg red -bd 0 -highlightthickness 0 -font myFont
pack .f.t -expand true -fill both
# winfo width .f.t returns 10
Doing the same with grid is left as an exercise for the reader...
Ken Jones
President, Avia Training and Consulting
www.avia-training.com
866-825-4357
|
|
0
|
|
|
|
Reply
|
Ken
|
3/27/2011 1:50:34 AM
|
|
Andreas Leitgeb said on 27/03/2011 00:55:
> Anyway, if you (the OP) intend to display only parts of letters, you could
> try using a canvas text-item instead. Or, if you need the text widget's
> features, embed the text-widget in the canvas.
Thanks for your answer. I guess this would work. I will however try
Ken's proposal first since it looks simpler to me.
Regards,
Francois
|
|
0
|
|
|
|
Reply
|
Francois
|
3/27/2011 6:44:50 PM
|
|
Ken Jones, Avia Training said on 27/03/2011 03:50:
> I won't claim to understand why you want this. I'll just approach it
> as a puzzle. :-)
Well I can try to explain if it can be of any interest.
I have written (with others) a text editor on top of the text widget:
http://sourceforge.net/p/scipad
During editing I want to display a visual clue in the margin showing
what lines were modified since opening of the file displayed in the
text widget, or since last save of this file.
This visual clue I would like to take the shape of a thin vertical
line, the color of which being changed depending on the edit actions,
or saving action.
This feature is pretty much the same as in the MS Visual C++
development environment. I don't know if there is something similar in
the Linux world, sorry for not providing an example.
So far I have implemented this by packing a text widget on the left of
my main text widget, setting its -width to 1, filling it with lines
having just one space and tagging the spaces facing the required lines
with text tags having -background {the desired color}.
I have to to use a text widget for the margin since the font used in
the main text widget is not necessarily the same for all its lines,
thus consecutive lines may show different line heights, which should
be reflected in the (blank but with colored tags) lines of the margin
otherwise the colored tags would no longer face the lines they are
identifying.
This implementation works. Pretty well. Including scrolling, peer
widgets and whatever.
The only remaining thing I would like to improve is the width of this
margin. By RTFM (yes Pat, I did again before posting) I definitely
checked that I can't do it with a text widget alone. I posted then my
question to this group and prompted for original ideas about how to
display a text widget with a smaller width. Perhaps I should have
explained why in my original post.
> My first reaction is to put the text widget inside a frame, turn off
> geometry propagation on the frame, and then explicitly set the width
> of the frame
This looks VERY interesting. Many thanks for sharing the idea and the
example code. It looks easy, and very feasible to integrate in my
existing framework. Simply a brilliant idea. That was the kind of
ideas I was looking for.
Thanks again, Ken, and others who have thought about a way of
achieving this.
Best regards,
Francois
|
|
0
|
|
|
|
Reply
|
Francois
|
3/27/2011 7:12:14 PM
|
|
Why not use a canvas widget with colored rectangles. Use bbox on the lines
of the text widget to get the height of the line and make your rectangle on
the canvas the at the same y top and bottom coords with their x coords being
the width of the canvas?
On 3/27/11 2:12 PM, Francois Vogel wrote:
> Ken Jones, Avia Training said on 27/03/2011 03:50:
>> I won't claim to understand why you want this. I'll just approach it
>> as a puzzle. :-)
>
> Well I can try to explain if it can be of any interest.
>
> I have written (with others) a text editor on top of the text widget:
> http://sourceforge.net/p/scipad
>
> During editing I want to display a visual clue in the margin showing what
> lines were modified since opening of the file displayed in the text widget,
> or since last save of this file.
>
> This visual clue I would like to take the shape of a thin vertical line, the
> color of which being changed depending on the edit actions, or saving action.
>
> This feature is pretty much the same as in the MS Visual C++ development
> environment. I don't know if there is something similar in the Linux world,
> sorry for not providing an example.
>
> So far I have implemented this by packing a text widget on the left of my
> main text widget, setting its -width to 1, filling it with lines having just
> one space and tagging the spaces facing the required lines with text tags
> having -background {the desired color}.
>
> I have to to use a text widget for the margin since the font used in the
> main text widget is not necessarily the same for all its lines, thus
> consecutive lines may show different line heights, which should be reflected
> in the (blank but with colored tags) lines of the margin otherwise the
> colored tags would no longer face the lines they are identifying.
>
> This implementation works. Pretty well. Including scrolling, peer widgets
> and whatever.
>
> The only remaining thing I would like to improve is the width of this
> margin. By RTFM (yes Pat, I did again before posting) I definitely checked
> that I can't do it with a text widget alone. I posted then my question to
> this group and prompted for original ideas about how to display a text
> widget with a smaller width. Perhaps I should have explained why in my
> original post.
>
>
>> My first reaction is to put the text widget inside a frame, turn off
>> geometry propagation on the frame, and then explicitly set the width
>> of the frame
>
> This looks VERY interesting. Many thanks for sharing the idea and the
> example code. It looks easy, and very feasible to integrate in my existing
> framework. Simply a brilliant idea. That was the kind of ideas I was looking
> for.
>
> Thanks again, Ken, and others who have thought about a way of achieving this.
> Best regards,
> Francois
--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+------------------------------------------------------------------------+
|
|
0
|
|
|
|
Reply
|
Gerald
|
3/27/2011 7:25:40 PM
|
|
Gerald W. Lester said on 27/03/2011 21:25:
> Why not use a canvas widget with colored rectangles. Use bbox on the
> lines of the text widget to get the height of the line and make your
> rectangle on the canvas the at the same y top and bottom coords with
> their x coords being the width of the canvas?
Yes, this popped in my mind later too (but I thought at using a line
item, not a rectangle item of a canvas).
I may try this kind of things in canvases in the event Ken's idea
turns out to be unpractical for me. Or would there be any substantial
advantage in using canvas items over the solution I described based on
a text widget?
Thanks,
Francois
|
|
0
|
|
|
|
Reply
|
Francois
|
3/27/2011 7:33:10 PM
|
|
On 3/27/11 2:33 PM, Francois Vogel wrote:
> Gerald W. Lester said on 27/03/2011 21:25:
>> Why not use a canvas widget with colored rectangles. Use bbox on the
>> lines of the text widget to get the height of the line and make your
>> rectangle on the canvas the at the same y top and bottom coords with
>> their x coords being the width of the canvas?
>
> Yes, this popped in my mind later too (but I thought at using a line item,
> not a rectangle item of a canvas).
>
> I may try this kind of things in canvases in the event Ken's idea turns out
> to be unpractical for me. Or would there be any substantial advantage in
> using canvas items over the solution I described based on a text widget?
Just giving a different approach -- do not know if one is better then another.
--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester@kng-consulting.net |
+------------------------------------------------------------------------+
|
|
0
|
|
|
|
Reply
|
Gerald
|
3/28/2011 12:30:55 AM
|
|
On Mar 27, 2:33=A0pm, Francois Vogel <fsvogelnew5NOS...@free.fr> wrote:
> I may try this kind of things in canvases in the event Ken's idea
> turns out to be unpractical for me. Or would there be any substantial
> advantage in using canvas items over the solution I described based on
> a text widget?
The advantage is, you don't have to use some sort of kludgy hack to
get a text widget that is half a character wide. Plus, by using a
canvas you can do many more things quite easily if the need arises.
For example, you could easily add line numbers with this approach.
Also, if your main text widget has lines of differing height (perhaps
due to embedded windows or different sized fonts) it becomes much
harder to keep your narrow text widget in sync.
The canvas approach is definitely the right approach here.
Here's a wiki page that shows how to do line numbers. Just replace the
numbers with vertical bars and you're done:
http://wiki.tcl.tk/20916
|
|
0
|
|
|
|
Reply
|
Bryan
|
3/28/2011 1:58:45 PM
|
|
|
9 Replies
202 Views
(page loaded in 3.02 seconds)
|