Python: network IDLE / Redo IDLE front-end when using the same back-end?

Is there an existing web application that allows multiple users to work with an interactive session such as IDLE at the same time?

Something like:

IDLE 2.6.4 Morgan: >>> letters = list("abcdefg") Morgan: >>> # now, how would you iterate over letters? Jack: >>> for char in letters: print "char %s" % char char a char b char c char d char e char f char g Morgan: >>> # nice nice 

If not, I would like to create it. Is there some kind of module that I can use that mimics an interactive session? I need an interface like this:

 def class InteractiveSession(): ''' An interactive Python session ''' def putLine(line): ''' Evaluates line ''' pass def outputLines(): ''' A list of all lines that have been output by the session ''' pass def currentVars(): ''' A dictionary of currently defined variables and their values ''' pass 

(Although this last function will be more of an additional function.)

To state my problem differently: I would like to create a new interface for IDLE. How can i do this?

UPDATE: Or maybe I can simulate IDLE via eval() ?

UPDATE 2: What if I did something like this:

  • I already have a GAE Python chat setup application that allows users to log in, create chats and chat with each other.

  • Instead of just storing incoming messages in a data warehouse, I could do something like this:


 def putLine(line, user, chat_room): ''' Evaluates line for the session used by chat_room ''' # get the interactive session for this chat room curr_vars = InteractiveSession.objects.where("chatRoom = %s" % chat_room).get() result = eval(prepared_line, curr_vars.state, {}) curr_vars.state = curr_globals curr_vars.lines.append((user, line)) if result: curr_vars.lines.append(('SELF', result.__str__())) curr_vars.put() 

InteractiveSession Model:

 def class InteractiveSession(db.Model): # a dictionary mapping variables to values # it looks like GAE doesn't actually have a dictionary field, so what would be best to use here? state = db.DictionaryProperty() # a transcript of the session # # a list of tuples of the form (user, line_entered) # # looks something like: # # [('Morgan', '# hello'), # ('Jack', 'x = []'), # ('Morgan', 'x.append(1)'), # ('Jack', 'x'), # ('SELF', '[1]')] lines = db.ListProperty() 

Can this work, or am I leaving / this approach is not feasible / am I duplicating work when I have to use something already built?

UPDATE 3 . Also, assuming everything else works, I would like to highlight the syntax. Ideally, I would have some kind of API or service that I could use to parse the code and fine-tune it accordingly.

 for c in "characters": 

will become:

 <span class="keyword">for</span> <span class="var">c</span> <span class="keyword">in</span> <span class="string>"characters"</span><span class="punctuation">:</span> 

Is there a good existing Python tool for this?

+6
python user-interface python-idle
source share
5 answers

I could implement something like this pretty quickly in Nevow . Obviously, access should be fairly limited, since doing something like this involves giving access to the Python console to someone through HTTP.

What I would do is create an Athena widget for the console, which used an instance of the custom subclass code.InteractiveInterpreter , which is common to all registered users.

UPDATE : Okay, so you have something like a chat in GAE. If you just send the lines to a subclass of code.InteractiveInterpreter that looks like this, it should work for you. Note: the interface is very similar to the InteractiveSession class that you describe:

 class SharedConsole(code.InteractiveInterpreter): def __init__(self): self.users = [] def write(self, data): # broadcast output to connected clients here for user in self.users: user.addOutput(data) class ConnectedUser(object): def __init__(self, sharedConsole): self.sharedConsole = sharedConsole sharedConsole.users.append(self) # reference look, should use weak refs def addOutput(self, data): pass # do GAE magic to send data to connected client # this is a hook for submitted code lines; call it from GAE when a user submits code def gotCommand(self, command): needsMore = self.sharedConsole.runsource(command) if needsMore: pass # tell the client to change the command line to a textarea # or otherwise add more lines of code to complete the statement 
+1
source share

The closest Python interpreter I know about what you are looking for in terms of interface is DreamPie . It has separate input and output areas very similar to the chat interface. In addition, DreamPie runs all the code in the subprocess. DreamPie also performs completion and syntax coloring, just like IDLE, which means it doesn't just pass input and output to / from the subprocess - it implemented the abstractions you are looking for.

If you want to develop a desktop application (rather than a web application), I recommend that you base your work on DreamPie and just add features with multiple interfaces.

Update. For syntax highlighting (including HTML) see the Pygments project. But this is a completely different matter; Please ask one question at a time.

+1
source share

As a proof of concept, you can put something together using sockets and a command line session.

0
source share

this is probably possible with the upcoming IPython implication using the 0MQ backend.

-one
source share

I would use ipython and screen . Using this method, you will have to create a shared login, but you can connect to a shared session. One of the drawbacks would be that you both would appear as the same user.

-one
source share

All Articles