Question about implementing multi-thread-input in TextCtrl?

Hi all,

Does someone know how to implement multi-thread-input in the TextCtrl?
I mean, I use a thread to write text to textctrl, and I also can

input without changing the insertion focus.

I want to make a collaboration edit effect and I do not know how to.

Thank you for your reading.

Hi all,

Does someone know how to implement multi-thread-input in the TextCtrl?
I mean, I use a thread to write text to textctrl, and I also can

input without changing the insertion focus.

This sounds like a bad idea to me and potentially confusing to the user. Still you could do it by keeping track of your cursor position and when an update from the thread came in, make sure to reset the position. You should see one of the following for more info on threads and wxPython:

···

On Monday, July 23, 2012 11:31:22 AM UTC-5, hanks wrote:

I want to make a collaboration edit effect and I do not know how to.

Thank you for your reading.

Thank you for your reply, I just want to try to implement the effect
about multi-users work in the same document at the same time.

I use this kind of function in google docs, and it is a good experience,
so i want to try it, but i think maybe text control in wxpxthon can not

support multi-user.

···

Zhou Han
Tel:13426421648

Email:zhouhan315@gmail.com

On Tue, Jul 24, 2012 at 2:08 AM, Mike Driscoll kyosohma@gmail.com wrote:

On Monday, July 23, 2012 11:31:22 AM UTC-5, hanks wrote:

Hi all,

Does someone know how to implement multi-thread-input in the TextCtrl?
I mean, I use a thread to write text to textctrl, and I also can

input without changing the insertion focus.

This sounds like a bad idea to me and potentially confusing to the user. Still you could do it by keeping track of your cursor position and when an update from the thread came in, make sure to reset the position. You should see one of the following for more info on threads and wxPython:

I want to make a collaboration edit effect and I do not know how to.

Thank you for your reading.

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Hi,

Thank you for your reply, I just want to try to implement the effect
about multi-users work in the same document at the same time.

I use this kind of function in google docs, and it is a good experience,
so i want to try it, but i think maybe text control in wxpxthon can not
support multi-user.

If your starting and getting stuck with the TextCtrl then I think your
approaching this problem from the wrong starting point. The
multi-threaded input to the text control will be about the most
trivial part of such an application. You are going to need a lot of
other layers before you get to the UI.

i.e) communications layer for relaying changes between all connected
participants which will probably involve sockets and rolling your own
communication protocol. Then your going to need to have a way to
manage and resolving conflicting differences when more than one user
are making changes to the same text at the same time, way to order
messages to make sure they are relayed and recieved by all clients in
the correct order.

The TextControl can definitaly be leveraged to do this though I would
suggest the wx.stc.StyledTextCtrl instead as it has a better (more
convenient) api for manipulating the text in the control.

But back to your question, I would start with something along these
lines to see how well it worked. More complex buffering and timing
techinques may be necessary depending on how many users you plan to
support at one time:
1) UI thread running as normal stand alone text editor.
2) Communications thread running in background sending/recieving data
from other connected clients.
3) Communications thread posts incoming changes to a Queue on the UI thread
4) Use a Timer/OnIdle messages in the UI thread to check the Queue periodically.
5) Process the data messages in the queue and 'replay' them in to the
current buffer as appropriate.

Cody

···

On Mon, Jul 23, 2012 at 9:27 PM, Hanks <zhouhan315@gmail.com> wrote:

Hanks wrote:

Thank you for your reply, I just want to try to implement the effect
about multi-users work in the same document at the same time.

I use this kind of function in google docs, and it is a good experience,
so i want to try it, but i think maybe text control in wxpxthon can not
support multi-user.

I don't think you are thinking this through. How would that happen?
How does it become "multi-user"? Where will the multiple users come
from? If you're talking about requests coming in from a network, then
it's NOT multiple users. Those all get funneled into your application,
and it's strictly up to your application to decide how update the text
box. You can certainly design your application so the updates get sent
to the main thread.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

To Tim:

Thank for your reply, I actually want to implement a application
that can support users with collaboration editor by network, it just

likes google docs does, now the key problem for me is how to solve
‘multi-insertion’ to the text control, like you said ‘how to update the
text box’, so I just simulated request from network with threads and

random data for the first step.

It is a little hard for me now, thank you for your advice.

···

Zhou Han

Tel:13426421648
Email:zhouhan315@gmail.com

On Wed, Jul 25, 2012 at 12:26 AM, Tim Roberts timr@probo.com wrote:

Hanks wrote:

Thank you for your reply, I just want to try to implement the effect

about multi-users work in the same document at the same time.

I use this kind of function in google docs, and it is a good experience,

so i want to try it, but i think maybe text control in wxpxthon can not

support multi-user.

I don’t think you are thinking this through. How would that happen?

How does it become “multi-user”? Where will the multiple users come

from? If you’re talking about requests coming in from a network, then

it’s NOT multiple users. Those all get funneled into your application,

and it’s strictly up to your application to decide how update the text

box. You can certainly design your application so the updates get sent

to the main thread.

Tim Roberts, timr@probo.com

Providenza & Boekelheide, Inc.

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

To Cody,

Thank you for your advice, I read it for several times, it seems to be
work for me,^_^. The key point is how to solve communications among

threads, and how to rerange them to the text control.
I will try the styledtextctrl. Thank you~~

···

Zhou Han

Tel:13426421648
Email:zhouhan315@gmail.com

On Tue, Jul 24, 2012 at 9:22 PM, Cody codyprecord@gmail.com wrote:

Hi,

On Mon, Jul 23, 2012 at 9:27 PM, Hanks zhouhan315@gmail.com wrote:

Thank you for your reply, I just want to try to implement the effect

about multi-users work in the same document at the same time.

I use this kind of function in google docs, and it is a good experience,

so i want to try it, but i think maybe text control in wxpxthon can not

support multi-user.

If your starting and getting stuck with the TextCtrl then I think your

approaching this problem from the wrong starting point. The

multi-threaded input to the text control will be about the most

trivial part of such an application. You are going to need a lot of

other layers before you get to the UI.

i.e) communications layer for relaying changes between all connected

participants which will probably involve sockets and rolling your own

communication protocol. Then your going to need to have a way to

manage and resolving conflicting differences when more than one user

are making changes to the same text at the same time, way to order

messages to make sure they are relayed and recieved by all clients in

the correct order.

The TextControl can definitaly be leveraged to do this though I would

suggest the wx.stc.StyledTextCtrl instead as it has a better (more

convenient) api for manipulating the text in the control.

But back to your question, I would start with something along these

lines to see how well it worked. More complex buffering and timing

techinques may be necessary depending on how many users you plan to

support at one time:

  1. UI thread running as normal stand alone text editor.

  2. Communications thread running in background sending/recieving data

from other connected clients.

  1. Communications thread posts incoming changes to a Queue on the UI thread

  2. Use a Timer/OnIdle messages in the UI thread to check the Queue periodically.

  3. Process the data messages in the queue and ‘replay’ them in to the

current buffer as appropriate.

Cody

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Hanks wrote:

        Thank you for your advice, I read it for several times, it

seems to be

        work for me,^_^. The key point is how to solve

communications among

        threads, and how to rerange them to the text control.

        I will try the styledtextctrl.
Threads are irrelevant here.  Go to a whiteboard and sketch out a

diagram of how this application has to work. I think you do not
understand yet how it must operate.

You will need a server.  Unless your collaborators happen to be

inside the same corporate network, you cannot connect them directly,
peer-to-peer. Corporate routers and firewalls do not allow that.
You would have a server that all of the clients connect to.

So, user A types a couple of characters in a text box.  Your app

will have to detect that, and send a message to the server that says
“hey, user A just typed ‘xxx’ in text box 23”. Your server will
then forward that to all the clients that are listening.

User B's application will receive that message over a socket

(presumably). The socket handler function just has to send that as
a custom message to your main window. There are several ways in wx
to send yourself a message. Your main window will then receive this
message in its event handler, and can go set the value in the text
box. Because you used a message, you KNOW that the message handler
is running in the main thread, and is thus allows to touch the UI.

I believe you could also do this with the "pubsub" module.
···
-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com