Questions for making editable text area using ogl

Hi

Now I have created draggable, resizable shapes. Then I want to create
editable text area in shapes.
First,the text area should be along with its shape, if the shape changes
size, text area also changes its size. Second, user double click text area,
the text area should show its boundary in other color.
Third, after second action, user could input text in text area
In the end , user click the area outside the text area, the boundary of text
area disappeared.

Questions below:

1 To create text area, there are shapeRegion ,TextShape to use, I want to
know which one is good to use ?

2 To add text area into shape, I will use CompositeShape, to make text area
as child of shape. But can I make shapeRegion as child of shape if I choose
shapeRegion to create text area?

3 How to make user text in text area?
  When double click text area, the text area should set cursor , how to do
this? can I just use TestArea.SetText(text) ,text = Text .

4 How to make the text area in multiline? I mean, if the text reach the
boundary of text area, how to make the text over boundary begin from
another line automatically?

5 I use When creating text area, I use SetColor, and when double clicking
test area, I use GetColor to show the boundary of text area . Is that the
right way ?

Hope you can give me some advice :slight_smile:

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Questions-for-making-editable-text-area-using-ogl-tp5717210.html
Sent from the wxPython-users mailing list archive at Nabble.com.

I tried to add ShapeRegion as a child onto a shape,but it doesn't work.
Error shows:
File "D:\Python27\lib\site-packages\wx-2.9.3-msw\wx\lib\ogl\_composit.py",
line 544, in AddChild
    child.SetParent(self)
AttributeError: 'ShapeRegion' object has no attribute 'SetParent'

It seems that ShapeRegion can't be a child of other shape. So, what
ShapeRegion can be used for?

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Questions-for-making-editable-text-area-using-ogl-tp5717210p5717220.html
Sent from the wxPython-users mailing list archive at Nabble.com.

I have solved some problems, and now update my questions

*Update questions and some solutions *
Sol1: ShapeRegion doesn't work well, I use TextShape, but the bad thing is I
can't get its boundary. Can I?
Q1: What's more, I want to know the use of ShapeRegion. When to use this
class?

Sol2: Just use CompositeShape, add TextShape as a child. And use
SetSensitivityFilter() to make TextShape sensitive to related events.
Q2 : In CompositeShape, there is always a method to be used, as the
following code:
*constraint = ogl.Constraint(ogl.CONSTRAINT_CENTRED_VERTICALLY,
constraining_shape, [textShape])
self.AddConstraint(constraint)*
I found, if I don't use constraint, the compositeshape also works well, I
don't have a good understand of the using of constraint, can you tell me
when to use it?

What's more, I found shape1.SetParent(shape2) can also realize something
like compositeshape does, but there are difference. I can't combine shape1
and shape2 together so move them together. So can you tell me the use of
SetParent() ?

When comes to SetSensitivityFilter(),the doc says:

SetSensitivityFilter(self, sens=15, recursive=False)
Set the shape to be sensitive or insensitive to specific mouse operations.
sens is a bitlist of the following:
OP_CLICK_LEFT
OP_CLICK_RIGHT
OP_DRAG_LEFT
OP_DRAG_RIGHT
OP_ALL (equivalent to a combination of all the above).

But what does sens = 15 mean? And usually, we use SetSensitivityFilter(0),
what does '0' mean?

Q3:How to make user text in text area?
  When double click text area, the text area should set cursor , how to do
this?
  I think I should make a Text object, and them use TestArea.SetText(text)
,text = Text .
  Now I'm not familiar with Text class. There is TextAttr
:http://wxpython.org/docs/api/wx.TextAttr-class.html. Should I use this?

Q4: How to make the text area in multiline? I mean, if the text reach the
boundary of text area, how to make the text over boundary begin from
another line automatically?

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Questions-for-making-editable-text-area-using-ogl-tp5717210p5717230.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Why not? A TextShape is exactly the same as a RectangleShape,
except that it doesn’t draw its border. You can call GetWidth and
GetHeight on it. Now, the width and height don’t automatically
update to fit the text you put in there, unless you use
SetFormatMode(FORMAT_SIZE_TO_CONTENTS). You can use FormatText to
add your text to it; in that case, it updates the width and height
as needed.
I think you’re just seeing part of the evolution of the library
here. ShapeRegion used to be is a base class that holds information
common to many different kinds of shapes. A larger shape would be
composed of a number of ShapeRegions. In the current design, Shape
is the base class, and you use child/parent relationships to group
them. So ShapeRegions may never come up for you.
Well, you use it when you need to constrain the position of one
object relative to another. For example, if object A should always
be positioned immediately to the right of object B with the centers
lined up, you’d use CONSTRAINT_CENTRED_VERTICALLY and
CONSTRAINT_RIGHT_OF.

A few minutes with the interpreter would have answered this question
much more quickly than this list. The comments are giving you the
clue. As it said, that parameter is a bitmask, where each bit turns
on or off one of the operations.
So OP_ALL, or 15, is the sum of all of the individual bits.

I’m not sure you’re going to be able to do this automatically. You
might be able to create a normal wx.TextCtrl and place it near your
object, then set the focus to that control, and hide the TextCtrl
when they press “enter”. Alternatively, you can display a text box
yourself (using a rectangular shape), capture the individual key
presses yourself, and build up the string character by character.

There are a lot of options. You’ll have a rectangular shape with a
text string. The text for that shape (SetText) is a list of
strings, where each string is presented on a new line. So, you
could format it yourself. Alternatively, you can use SetFormatMode
with FORMAT_SIZE_TO_CONTENTS to have it split the string up to fit
the shape.

···

Gabrielle wrote:


I have solved some problems, and now update my questions
Sol1: ShapeRegion doesn't work well, I use TextShape, but the bad thing is I
can't get its boundary. Can I?
Q1: What's more, I want to know the use of ShapeRegion. When to use this
class?
Q2 : In CompositeShape, there is always a method to be used, as the
following code:
*constraint = ogl.Constraint(ogl.CONSTRAINT_CENTRED_VERTICALLY,
constraining_shape, [textShape])
self.AddConstraint(constraint)*
I found, if I don't use constraint, the compositeshape also works well, I
don't have a good understand of the using of constraint, can you tell me
when to use it?

When comes to SetSensitivityFilter(),the doc says:
SetSensitivityFilter(self, sens=15, recursive=False)
Set the shape to be sensitive or insensitive to specific mouse operations.
sens is a bitlist of the following:
OP_CLICK_LEFT
OP_CLICK_RIGHT
OP_DRAG_LEFT
OP_DRAG_RIGHT
OP_ALL (equivalent to a combination of all the above).
But what does sens = 15 mean? And usually, we use SetSensitivityFilter(0),
what does '0' mean?

C:\tmp>python

  Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32

bit (Intel)] on win32

  Type "help", "copyright", "credits" or "license" for more

information.

  >>> import wx.lib.ogl

  >>> wx.lib.ogl.OP_CLICK_LEFT

  1

  >>> wx.lib.ogl.OP_CLICK_RIGHT

  2

  >>> wx.lib.ogl.OP_DRAG_LEFT

  4

  >>> wx.lib.ogl.OP_DRAG_RIGHT

  8

  >>> wx.lib.ogl.OP_ALL

  15

  >>>
  Q3:How to make user text in text area? When double click text area, the text area should set cursor , how to do
this? I think I should make a Text object, and them use TestArea.SetText(text)
,text = Text . Now I'm not familiar with Text class. There is TextAttr
:. Should I use this?
Q4: How to make the text area in multiline? I mean, if the text reach the
boundary of text area, how to make the text over boundary begin from
another line automatically?
-- Tim Roberts, Providenza & Boekelheide, Inc.

http://wxpython.org/docs/api/wx.TextAttr-class.htmltimr@probo.com

text_test.py
<http://wxpython-users.1045709.n5.nabble.com/file/n5717245/text_test.py>

Hi Tim

I tried to use TextCtrl, and here are some thoughts and problems to share:

1: It's impossible to add textCtrl object onto shape directly for it needs a
window parent. So I create textCtrl object in my canvas class.
2: I think there is no need to use TextShape anymore, for shapes have
default text region, I can put text of textCtrl object into default text
region of shapes.
3: If I don't use TextShape, and if I use
shape.SetFormatMode(ogl.FORMAT_SIZE_TO_CONTENTS), the text shown in shape be
in the same format as in the textCtrl, that is to say, if text in textCtrl
is in single line, the text in shape is also in single line, and the shape
will adjust its size to fit the text length. And then,at the same time,
shape.FormatText is useless.

Questions come:
Q1: Based on 1,2,3, if I resize the shape, for example, I drag the top of
the shape, shape changes, but the start point of text in shape won't change,
then , it looks strange. Do you understand what I mean? Do you have any
idea to solve this? I wonder, if I still use textShape, does it can help to
solve this problem? I mean, maybe it can adjust the start point of text
automatically. Or maybe I need a update_text method to response to resizing
shape.

4: Based on 1 and 2, I wrote some codes in the below:

*#add shapes*
        shape = ExecutionShape()
        #shape.SetFormatMode(ogl.FORMAT_SIZE_TO_CONTENTS)
        self.MyAddShape(shape,100,100,'')
        width = shape.GetWidth()
        height = shape.GetHeight()
        x =shape.GetX
        y =shape.GetY
*#create textCtrl. *
        basicText = wx.TextCtrl( self,-1, "hello, today i will talk about my
project, the flow chart design tool. i will talk about these four topoics",
                                size=(width, height),
                                style = wx.BORDER_NONE)
     * # put the textCtrl onto shape's position.*
        pos = basicText.XYToPosition(x,y)# ?? it returns long, why still
show error?
        basicText.ShowPosition(pos)
        basicText.Hide(True) # it will be showed when event is triggered.
        
        # get the text in TextCtrl, it will return a string
        string = basicText.GetLineText(1)
        # shape format text. The string in basicText in single line will be
showed in multiline
        shape.FormatText(dc,string)

Questions:
pos = basicText.XYToPosition(x,y)
this method will return long type, but when I run the code, it will show
error,
TypeError: in method 'TextAreaBase_XYToPosition', expected argument 2 of
type 'long'

I don't know why...

What's more, if I want to set a multiline textCtrl, how to make the scroller
invisible? Is there a method to do this? I didn't found it.

The attachment is related testing code , it has error as I said.
And I want to make a event to control the visibility of textCtrl object, and
update the text in shape. The pseudo code is also in attachment. Would you
please have look and give me some advice?

Thanks

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Questions-for-making-editable-text-area-using-ogl-tp5717210p5717245.html
Sent from the wxPython-users mailing list archive at Nabble.com.