public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Wiktor W Brodlo" <wiktor@brodlo.net>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/anaconda:master commit in: iw/
Date: Tue, 21 Jun 2011 12:15:33 +0000 (UTC)	[thread overview]
Message-ID: <2d5b7f2a1a865850301fb8d4a6c8cda217c80633.wiktor@gentoo> (raw)

commit:     2d5b7f2a1a865850301fb8d4a6c8cda217c80633
Author:     wiktor w brodlo <wiktor <AT> brodlo <DOT> net>
AuthorDate: Tue Jun 21 12:14:55 2011 +0000
Commit:     Wiktor W Brodlo <wiktor <AT> brodlo <DOT> net>
CommitDate: Tue Jun 21 12:14:55 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/anaconda.git;a=commit;h=2d5b7f2a

Changed the adbox (screenshots) to a vte terminal.

---
 iw/VirtualTerminal.py |  182 +++++++++++++++++++++++++++++++++++++++++++++++++
 iw/progress_gui.py    |   32 ++++++---
 2 files changed, 202 insertions(+), 12 deletions(-)

diff --git a/iw/VirtualTerminal.py b/iw/VirtualTerminal.py
new file mode 100644
index 0000000..cec8888
--- /dev/null
+++ b/iw/VirtualTerminal.py
@@ -0,0 +1,182 @@
+#!/usr/bin/env python
+#
+#      VirtualTerminal.py
+#
+#      Copyright 2007 Edward Andrew Robinson <earobinson@gmail>
+#
+#      This program is free software; you can redistribute it and/or modify
+#      it under the terms of the GNU General Public License as published by
+#      the Free Software Foundation; either version 2 of the License, or
+#      (at your option) any later version.
+#
+#      This program is distributed in the hope that it will be useful,
+#      but WITHOUT ANY WARRANTY; without even the implied warranty of
+#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#      GNU General Public License for more details.
+#
+#      You should have received a copy of the GNU General Public License
+#      along with this program; if not, write to the Free Software
+#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+# Imports
+import os
+import vte
+import gtk
+import time
+
+class VirtualTerminal(vte.Terminal):
+    def __init__(self, log_file = None, history_length = 5, prompt_watch = {}, prompt_auto_reply = True, icon = None):
+        # Set up terminal
+        vte.Terminal.__init__(self)
+
+        self.history = []
+        self.history_length = history_length
+        self.icon = icon
+        self.last_row_logged = 0
+        self.log_file = log_file
+        self.prompt_auto_reply = prompt_auto_reply
+        self.prompt_watch = prompt_watch
+
+        self.connect('eof', self.run_command_done_callback)
+        self.connect('child-exited', self.run_command_done_callback)
+        self.connect('cursor-moved', self.contents_changed_callback)
+
+        if False:
+            self.connect('char-size-changed', self.activate_action, 'char-size-changed')
+            #self.connect('child-exited', self.activate_action, 'child-exited')
+            self.connect('commit', self.activate_action, 'commit')
+            self.connect('contents-changed', self.activate_action, 'contents-changed')
+            #self.connect('cursor-moved', self.activate_action, 'cursor-moved')
+            self.connect('decrease-font-size', self.activate_action, 'decrease-font-size')
+            self.connect('deiconify-window', self.activate_action, 'deiconify-window')
+            self.connect('emulation-changed', self.activate_action, 'emulation-changed')
+            self.connect('encoding-changed', self.activate_action, 'encoding-changed')
+            #self.connect('eof', self.activate_action, 'eof')
+            self.connect('icon-title-changed', self.activate_action, 'icon-title-changed')
+            self.connect('iconify-window', self.activate_action, 'iconify-window')
+            self.connect('increase-font-size', self.activate_action, 'increase-font-size')
+            self.connect('lower-window', self.activate_action, 'lower-window')
+            self.connect('maximize-window', self.activate_action, 'maximize-window')
+            self.connect('move-window', self.activate_action, 'move-window')
+            self.connect('raise-window', self.activate_action, 'raise-window')
+            self.connect('refresh-window', self.activate_action, 'refresh-window')
+            self.connect('resize-window', self.activate_action, 'resize-window')
+            self.connect('restore-window', self.activate_action, 'restore-window')
+            self.connect('selection-changed', self.activate_action, 'selection-changed')
+            self.connect('status-line-changed', self.activate_action, 'status-line-changed')
+            self.connect('text-deleted', self.activate_action, 'text-deleted')
+            self.connect('text-inserted', self.activate_action, 'text-inserted')
+            self.connect('text-modified', self.activate_action, 'text-modified')
+            self.connect('text-scrolled', self.activate_action, 'text-scrolled')
+            self.connect('window-title-changed', self.activate_action, 'window-title-changed')
+
+    def activate_action(self, action, string):
+        print 'Action ' + action.get_name() + ' activated ' + str(string)
+
+    def capture_text(self,text,text2,text3,text4):
+        return True
+
+    def contents_changed_callback(self, terminal):
+        '''Gets the last line printed to the terminal, it will log
+        this line using self.log() (if the logger is on, and it will
+        also prompt this line using self.prompt() if the line needs
+        prompting'''
+        column,row = self.get_cursor_position()
+        if self.last_row_logged != row:
+            off = row-self.last_row_logged
+            text = self.get_text_range(row-off,0,row-1,-1,self.capture_text)
+            self.last_row_logged=row
+            text = text.strip()
+
+            # Log
+            self.log(text)
+
+            # Prompter
+            self.prompter()
+
+    def get_last_line(self):
+        terminal_text = self.get_text(self.capture_text)
+        terminal_text = terminal_text.split('\\\\n')
+        ii = len(terminal_text) - 1
+        while terminal_text[ii] == '':
+            ii = ii - 1
+        terminal_text = terminal_text[ii]
+
+        return terminal_text
+
+    def log(self, text):
+        '''if self.log_file is not None the the line will be logged to
+        self.log_file. This function also stors the info in self.histoy
+        if self.history_lenght > 0'''
+        if self.log_file != None:
+            date_string = time.strftime('[%d %b %Y %H:%M:%S] ', time.localtime())
+            file = open(self.log_file, 'a')
+            file.write(date_string + text + '\\\\n')
+            file.close
+
+        # Append to internal history
+        if self.history_length != 0:
+            if len(self.history) >= self.history_length:
+                self.history.pop(0)
+            self.history.append(text)
+
+    def prompter(self):
+        last_line = self.get_last_line()
+        if last_line in self.prompt_watch:
+            if self.prompt_auto_reply == False:
+                message = ''
+                for ii in self.prompt_watch[last_line]:
+                    message = message + self.history[self.history_length - 1 - ii]
+                if self.yes_no_question(message):
+                    self.feed_child('Yes\\\\n')
+                    # TODO not sure why this is needed twice
+                    self.feed_child('Yes\\\\n')
+                else:
+                    self.feed_child('No\\\\n')
+            else:
+                self.feed_child('Yes\\\\n')
+
+    def run_command(self, command_string):
+        '''run_command runs the command_string in the terminal. This
+        function will only return when self.thred_running is set to
+        True, this is done by run_command_done_callback'''
+        self.thread_running = True
+        spaces = ''
+        for ii in range(80 - len(command_string) - 2):
+            spaces = spaces + ' '
+        self.feed('$ ' + str(command_string) + spaces)
+        self.log('$ ' + str(command_string) + spaces)
+
+        command = command_string.split(' ')
+        pid =  self.fork_command(command=command[0], argv=command, directory=os.getcwd())
+
+        while self.thread_running:
+            #time.sleep(.01)
+            gtk.main_iteration()
+
+    def run_command_done_callback(self, terminal):
+        '''When called this function sets the thread as done allowing
+        the run_command function to exit'''
+        #print 'child done'
+        self.thread_running = False
+
+    def yes_no_question(self, message):
+        message = message.replace('\\\\n\\\\n', '[NEWLINE][NEWLINE]').replace('\\\\n', '').replace('[NEWLINE]', '\\\\n')
+
+        if message.find('?') == -1:
+            message = message + '\\\\n\\\\nDo you want to continue?'
+
+        type=gtk.MESSAGE_QUESTION
+        if message.lower().find('warning') != -1:
+            type=gtk.MESSAGE_WARNING
+
+        dialog = gtk.MessageDialog(parent=None, flags=0, type=type, buttons=gtk.BUTTONS_YES_NO, message_format=message)
+        dialog.set_icon(self.icon)
+        dialog.show_all()
+        responce = dialog.run()
+        dialog.destroy()
+
+        # Responce == yes
+        return responce == -8
+

diff --git a/iw/progress_gui.py b/iw/progress_gui.py
index bfbd19e..75c8523 100644
--- a/iw/progress_gui.py
+++ b/iw/progress_gui.py
@@ -33,6 +33,8 @@ import language
 import logging
 log = logging.getLogger("anaconda")
 
+from VirtualTerminal import VirtualTerminal
+
 class InstallProgressWindow (InstallWindow):
     windowTitle = N_("Installing Packages")
 
@@ -122,25 +124,31 @@ class InstallProgressWindow (InstallWindow):
 	    self.intf.icw.prevClicked()
 	    return
 
-        self.pixmaps = self._getRnotes()
+        #self.pixmaps = self._getRnotes()
 
 	# Create vbox to contain components of UI
         vbox = gtk.VBox (False, 12)
 
         # Create rnote area
-        self.adpix = None
+	# Gentoo uses the rnote area for emerge progress.
+        #self.adpix = None
         self.adbox = None
-        pix = gui.readImageFromFile(self.pixmaps[0])
-        if pix:
-            frame = gtk.Frame()
-            frame.set_shadow_type(gtk.SHADOW_NONE)
-            box = gtk.EventBox()
-            self.adpix = pix
-            box.add(self.adpix)
-            self.adbox = box
-            frame.add(box)
-            vbox.pack_start(frame, True, True)
 
+	self.terminal = VirtualTerminal()
+
+        #pix = gui.readImageFromFile(self.pixmaps[0])
+        #if pix:
+        frame = gtk.Frame()
+        frame.set_shadow_type(gtk.SHADOW_NONE)
+        box = gtk.EventBox()
+        #    self.adpix = pix
+        box.add(self.terminal)
+        self.adbox = box
+        frame.add(box)
+        vbox.pack_start(frame, True, True)
+
+	# Just an example for now
+	self.terminal.run_command('/bin/bash')
 
 	self.progress = gtk.ProgressBar()
         vbox.pack_start(self.progress, False, False)



             reply	other threads:[~2011-06-21 12:15 UTC|newest]

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-21 12:15 Wiktor W Brodlo [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-08-21  0:03 [gentoo-commits] proj/anaconda:master commit in: iw/ Wiktor W Brodlo
2011-08-21  0:03 Wiktor W Brodlo
2011-08-21  0:03 Wiktor W Brodlo
2011-08-21  0:03 Wiktor W Brodlo
2011-08-11 12:58 Wiktor W Brodlo
2011-08-04  2:16 Wiktor W Brodlo
2011-08-04  2:16 Wiktor W Brodlo
2011-08-04  2:16 Wiktor W Brodlo
2011-08-03 11:30 Wiktor W Brodlo
2011-08-03  9:47 Wiktor W Brodlo
2011-08-03  9:31 Wiktor W Brodlo
2011-08-03  9:16 Wiktor W Brodlo
2011-08-03  8:59 Wiktor W Brodlo
2011-08-03  8:51 Wiktor W Brodlo
2011-08-03  8:40 Wiktor W Brodlo
2011-08-03  2:52 Wiktor W Brodlo
2011-08-01  9:47 Wiktor W Brodlo
2011-08-01  9:39 Wiktor W Brodlo
2011-08-01  9:32 Wiktor W Brodlo
2011-08-01  9:09 Wiktor W Brodlo
2011-08-01  8:58 Wiktor W Brodlo
2011-08-01  1:59 Wiktor W Brodlo
2011-08-01  1:50 Wiktor W Brodlo
2011-08-01  1:41 Wiktor W Brodlo
2011-08-01  1:32 Wiktor W Brodlo
2011-08-01  1:24 Wiktor W Brodlo
2011-08-01  1:01 Wiktor W Brodlo
2011-08-01  0:53 Wiktor W Brodlo
2011-08-01  0:44 Wiktor W Brodlo
2011-08-01  0:35 Wiktor W Brodlo
2011-08-01  0:28 Wiktor W Brodlo
2011-08-01  0:17 Wiktor W Brodlo
2011-07-30  3:16 Wiktor W Brodlo
2011-07-26 11:38 Wiktor W Brodlo
2011-07-26 11:27 Wiktor W Brodlo
2011-07-26 11:12 Wiktor W Brodlo
2011-07-23  0:18 Wiktor W Brodlo
2011-07-22 21:22 Wiktor W Brodlo
2011-07-22 19:34 Wiktor W Brodlo
2011-07-22 19:27 Wiktor W Brodlo
2011-07-22 19:16 Wiktor W Brodlo
2011-07-21 21:37 Wiktor W Brodlo
2011-07-21 21:21 Wiktor W Brodlo
2011-07-21 20:40 Wiktor W Brodlo
2011-07-21 16:40 Wiktor W Brodlo
2011-07-21 15:21 Wiktor W Brodlo
2011-07-21 15:04 Wiktor W Brodlo
2011-07-21 14:47 Wiktor W Brodlo
2011-07-21 14:36 Wiktor W Brodlo
2011-07-21 14:19 Wiktor W Brodlo
2011-07-21 13:47 Wiktor W Brodlo
2011-07-21 13:42 Wiktor W Brodlo
2011-07-21 12:43 Wiktor W Brodlo
2011-07-10  1:44 Wiktor W Brodlo
2011-07-09 22:43 Wiktor W Brodlo
2011-07-09 19:20 Wiktor W Brodlo
2011-07-09 19:06 Wiktor W Brodlo
2011-07-09 18:43 Wiktor W Brodlo
2011-07-08 16:18 Wiktor W Brodlo
2011-07-08 15:42 Wiktor W Brodlo
2011-07-07 20:35 Wiktor W Brodlo
2011-07-07 20:22 Wiktor W Brodlo
2011-07-07 18:58 Wiktor W Brodlo
2011-07-07 18:58 Wiktor W Brodlo
2011-07-05 12:36 Wiktor W Brodlo
2011-07-05 12:33 Wiktor W Brodlo
2011-07-05 12:22 Wiktor W Brodlo
2011-07-05 12:07 Wiktor W Brodlo
2011-07-04 16:32 Wiktor W Brodlo
2011-07-04 16:19 Wiktor W Brodlo
2011-07-04 15:16 Wiktor W Brodlo
2011-07-04 14:53 Wiktor W Brodlo
2011-07-04 14:40 Wiktor W Brodlo
2011-07-04 14:18 Wiktor W Brodlo
2011-07-04 14:17 Wiktor W Brodlo
2011-07-04 12:56 Wiktor W Brodlo
2011-07-04 12:42 Wiktor W Brodlo
2011-07-03 19:28 Wiktor W Brodlo
2011-07-03 19:21 Wiktor W Brodlo
2011-07-03 19:06 Wiktor W Brodlo
2011-07-03 18:59 Wiktor W Brodlo
2011-07-03 17:52 Wiktor W Brodlo
2011-07-03 17:15 Wiktor W Brodlo
2011-07-03 16:49 Wiktor W Brodlo
2011-07-03 16:41 Wiktor W Brodlo
2011-07-03 16:00 Wiktor W Brodlo
2011-07-03 15:54 Wiktor W Brodlo
2011-07-01  2:03 Wiktor W Brodlo
2011-06-21 13:40 Wiktor W Brodlo
2011-06-21 13:12 Wiktor W Brodlo
2011-06-21 13:04 Wiktor W Brodlo
2011-06-21 12:56 Wiktor W Brodlo
2011-06-21 12:43 Wiktor W Brodlo
2011-06-21 12:40 Wiktor W Brodlo
2011-06-20 19:28 Wiktor W Brodlo
2011-06-20 19:07 Wiktor W Brodlo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2d5b7f2a1a865850301fb8d4a6c8cda217c80633.wiktor@gentoo \
    --to=wiktor@brodlo.net \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox