← Back to team overview

clicompanion-devs team mailing list archive

[Merge] lp:~dcaro/clicompanion/fix-623475 into lp:clicompanion

 

David Caro has proposed merging lp:~dcaro/clicompanion/fix-623475 into lp:clicompanion.

Requested reviews:
  CLI Companion Development Team (clicompanion-devs)
Related bugs:
  Bug #623475 in CLI Companion: "Wishlist: Ability to Abort/Cancel Command"
  https://bugs.launchpad.net/clicompanion/+bug/623475

For more details, see:
https://code.launchpad.net/~dcaro/clicompanion/fix-623475/+merge/88612

Added the job control options in the toplevel menu and the right-click menu, also reorganized the toplevel menu entries.
-- 
https://code.launchpad.net/~dcaro/clicompanion/fix-623475/+merge/88612
Your team CLI Companion Development Team is requested to review the proposed merge of lp:~dcaro/clicompanion/fix-623475 into lp:clicompanion.
=== modified file 'clicompanionlib/config.py'
--- clicompanionlib/config.py	2012-01-12 20:51:02 +0000
+++ clicompanionlib/config.py	2012-01-15 20:55:27 +0000
@@ -73,6 +73,7 @@
 ## shift+ctrl+D (not shift+ctrl+d). And the function keys go uppercase (F10).
 DEFAULT_KEY_BINDINGS = {
         'run_command': 'F4',
+        'cancel_command': 'ctrl+C',
         'add_command': 'F5',
         'remove_command': 'F6',
         'edit_command': 'unused',
@@ -95,6 +96,7 @@
 ## actibated
 KEY_BINDINGS = {
         'run_command': 'Run command',
+        'cancel_command': 'Cancel command',
         'add_command': 'Add command',
         'remove_command': 'Remove command',
         'edit_command': 'Edit command',

=== modified file 'clicompanionlib/menus_buttons.py'
--- clicompanionlib/menus_buttons.py	2012-01-08 00:48:43 +0000
+++ clicompanionlib/menus_buttons.py	2012-01-15 20:55:27 +0000
@@ -31,6 +31,18 @@
     __gsignals__ = {
          'run_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                              ()),
+         'cancel_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
+                             ()),
+         'stop_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
+                             ()),
+         'resume_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
+                             ()),
+         'background_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
+                             ()),
+         'foreground_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
+                             ()),
+         'bgrun_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
+                             ()),
          'add_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                              ()),
          'remove_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
@@ -49,77 +61,112 @@
 
     def __init__(self, config):
         gtk.MenuBar.__init__(self)
+
+        ##FILE MENU ##
+        file_menu = gtk.MenuItem(_("File"))
         menu = gtk.Menu()
-        #color = gtk.gdk.Color(65555, 62000, 65555)
-        #menu.modify_bg(gtk.STATE_NORMAL, color)
-        root_menu = gtk.MenuItem(_("File"))
-        root_menu.set_submenu(menu)
-
-        menu2 = gtk.Menu()
-        #color = gtk.gdk.Color(65555, 62000, 60000)
-        #menu2.modify_bg(gtk.STATE_NORMAL, color)
-        root_menu2 = gtk.MenuItem(_("Help"))
-        root_menu2.set_submenu(menu2)
-
-        ##FILE MENU ##
+        file_menu.set_submenu(menu)
+        ## Make 'User Preferences' file menu entry
+        menu_item5 = gtk.MenuItem(_("Preferences"))
+        menu.append(menu_item5)
+        menu_item5.connect("activate", lambda *x: self.emit('preferences'))
+        ## Make 'Quit' file menu entry
+        menu_item6 = gtk.MenuItem(_("Quit"))
+        menu.append(menu_item6)
+        menu_item6.connect("activate", lambda *x: self.emit('quit'))
+
+        ## Make 'Process' menu entry
+        p_menu = gtk.MenuItem(_("Process"))
+        proc_menu = gtk.Menu()
+        p_menu.set_submenu(proc_menu)
+        ## Submenu Abort
+        subitem = gtk.ImageMenuItem(gtk.STOCK_STOP)
+        subitem.set_label(_('Abort (Ctrl+c)'))
+        proc_menu.add(subitem)
+        subitem.connect('activate',
+                            lambda *x: self.emit('cancel_command'))
+        ## Submenu Pause
+        subitem = gtk.ImageMenuItem(gtk.STOCK_MEDIA_PAUSE)
+        subitem.set_label(_('Pause (Ctrl+s)'))
+        proc_menu.add(subitem)
+        subitem.connect('activate',
+                            lambda *x: self.emit('stop_command'))
+        ## Submenu Resume
+        subitem = gtk.ImageMenuItem(gtk.STOCK_MEDIA_PLAY)
+        subitem.set_label(_('Resume (Ctrl+q)'))
+        proc_menu.add(subitem)
+        subitem.connect('activate',
+                            lambda *x: self.emit('resume_command'))
+        ## Submenu Background Suspend
+        subitem = gtk.ImageMenuItem(gtk.STOCK_GOTO_BOTTOM)
+        subitem.set_label(_('Stop and Background (Ctrl+z)'))
+        proc_menu.add(subitem)
+        subitem.connect('activate',
+                            lambda *x: self.emit('background_command'))
+        ## Submenu Resume
+        subitem = gtk.ImageMenuItem(gtk.STOCK_GO_UP)
+        subitem.set_label(_('Foreground (%)'))
+        proc_menu.add(subitem)
+        subitem.connect('activate',
+                            lambda *x: self.emit('foreground_command'))
+        ## Submenu Resume
+        subitem = gtk.ImageMenuItem(gtk.STOCK_GO_DOWN)
+        subitem.set_label(_('Run background (% &)'))
+        proc_menu.add(subitem)
+        subitem.connect('activate',
+                            lambda *x: self.emit('bgrun_command'))
+
+
+        ## Command menu
+        c_menu = gtk.MenuItem(_("Command"))
+        com_menu = gtk.Menu()
+        c_menu.set_submenu(com_menu)
         ## Make 'Run' menu entry
         menu_item1 = gtk.MenuItem(_("Run Command"))
-        menu.append(menu_item1)
+        com_menu.append(menu_item1)
         menu_item1.connect("activate", lambda *x: self.emit('run_command'))
-        menu_item1.show()
-
         ## Make 'Add' file menu entry
         menu_item2 = gtk.MenuItem(_("Add Command"))
-        menu.append(menu_item2)
+        com_menu.append(menu_item2)
         menu_item2.connect("activate", lambda *x: self.emit('add_command'))
-        menu_item2.show()
-
         ## Make 'Remove' file menu entry
         menu_item3 = gtk.MenuItem(_("Remove Command"))
-        menu.append(menu_item3)
+        com_menu.append(menu_item3)
         menu_item3.connect("activate", lambda *x: self.emit('remove_command'))
-        menu_item3.show()
 
+        ## Terminal menu
+        t_menu = gtk.MenuItem(_("Terminal"))
+        term_menu = gtk.Menu()
+        t_menu.set_submenu(term_menu)
         ## Make 'Add Tab' file menu entry
         menu_item4 = gtk.MenuItem(_("Add Tab"))
-        menu.append(menu_item4)
+        term_menu.append(menu_item4)
         menu_item4.connect("activate", lambda *x: self.emit('add_tab'))
-        menu_item4.show()
-
         ## Make 'Close Tab' file menu entry
         menu_item4 = gtk.MenuItem(_("Close Tab"))
-        menu.append(menu_item4)
+        term_menu.append(menu_item4)
         menu_item4.connect("activate", lambda *x: self.emit('close_tab'))
-        menu_item4.show()
-
-        ## Make 'User Preferences' file menu entry
-        menu_item5 = gtk.MenuItem(_("Preferences"))
-        menu.append(menu_item5)
-        menu_item5.connect("activate", lambda *x: self.emit('preferences'))
-        menu_item5.show()
-
-        ## Make 'Quit' file menu entry
-        menu_item6 = gtk.MenuItem(_("Quit"))
-        menu.append(menu_item6)
-        menu_item6.connect("activate", lambda *x: self.emit('quit'))
-        menu_item6.show()
+
 
         ## HELP MENU ##
+        help_menu = gtk.MenuItem(_("Help"))
+        menu2 = gtk.Menu()
+        help_menu.set_submenu(menu2)
         ## Make 'About' file menu entry
         menu_item11 = gtk.MenuItem(_("About"))
         menu2.append(menu_item11)
         menu_item11.connect("activate", lambda *x: cc_helpers.show_about())
-        menu_item11.show()
-
         ## Make 'Help' file menu entry
         menu_item22 = gtk.MenuItem(_("Help-online"))
         menu2.append(menu_item22)
         menu_item22.connect("activate", lambda *x: webbrowser.open(
                                         "http://launchpad.net/clicompanion";))
-        menu_item22.show()
 
-        self.append(root_menu)  # Menu bar(file)
-        self.append(root_menu2)  # Menu bar(help)
+        self.append(file_menu) 
+        self.append(c_menu)
+        self.append(p_menu)
+        self.append(t_menu)
+        self.append(help_menu)
         self.show_all()
 
 
@@ -127,6 +174,8 @@
     __gsignals__ = {
          'run_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                              ()),
+         'cancel_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
+                             ()),
          'add_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                              ()),
          'remove_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
@@ -156,6 +205,13 @@
         bbox.add(buttonRun)
         buttonRun.connect("clicked", lambda *x: self.emit('run_command'))
         buttonRun.set_tooltip_text(_("Click to run a highlighted command"))
+
+        # Cancel button
+        buttonCancel = gtk.Button(stock=gtk.STOCK_CANCEL)
+        bbox.add(buttonCancel)
+        buttonCancel.connect("clicked", lambda *x: self.emit('cancel_command'))
+        buttonCancel.set_tooltip_text(_("Click to cancel the running command"))
+        
         # Add button
         buttonAdd = gtk.Button(stock=gtk.STOCK_ADD)
         bbox.add(buttonAdd)

=== modified file 'clicompanionlib/plugins.py'
--- clicompanionlib/plugins.py	2012-01-11 20:16:12 +0000
+++ clicompanionlib/plugins.py	2012-01-15 20:55:27 +0000
@@ -148,6 +148,8 @@
     __gsignals__ = {
          'run_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                              (str, str, str)),
+         'cancel_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
+                             ()),
          'add_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                              (str, str, str)),
          'remove_command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,

=== modified file 'clicompanionlib/tabs.py'
--- clicompanionlib/tabs.py	2012-01-12 20:51:02 +0000
+++ clicompanionlib/tabs.py	2012-01-15 20:55:27 +0000
@@ -223,7 +223,7 @@
             menuPopup3.set_label(_('Rename'))
             popupMenu.add(menuPopup3)
             menuPopup3.connect('activate', lambda x: self.rename())
-            ## right-click popup menu Add Tab
+            ## right-click popup menu Configure
             menuPopup3 = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES)
             menuPopup3.set_label(_('Configure'))
             popupMenu.add(menuPopup3)
@@ -233,6 +233,48 @@
             menuPopup3.set_label(_('Add tab'))
             popupMenu.add(menuPopup3)
             menuPopup3.connect('activate', lambda x: self.emit('add_tab'))
+            ## right-click popup menu Process
+            menu_signal = gtk.ImageMenuItem(gtk.STOCK_JUMP_TO)
+            menu_signal.set_label(_('Process'))
+            submenu_signal = gtk.Menu()
+            menu_signal.set_submenu(submenu_signal)
+            popupMenu.add(menu_signal)
+            ## Submenu Abort
+            subitem = gtk.ImageMenuItem(gtk.STOCK_STOP)
+            subitem.set_label(_('Abort (Ctrl+c)'))
+            submenu_signal.add(subitem)
+            subitem.connect('activate',
+                                lambda *x: self.cancel_command())
+            ## Submenu Pause
+            subitem = gtk.ImageMenuItem(gtk.STOCK_MEDIA_PAUSE)
+            subitem.set_label(_('Pause (Ctrl+s)'))
+            submenu_signal.add(subitem)
+            subitem.connect('activate',
+                                lambda *x: self.stop_command())
+            ## Submenu Resume
+            subitem = gtk.ImageMenuItem(gtk.STOCK_MEDIA_PLAY)
+            subitem.set_label(_('Resume (Ctrl+q)'))
+            submenu_signal.add(subitem)
+            subitem.connect('activate',
+                                lambda *x: self.resume_command())
+            ## Submenu Background Suspend
+            subitem = gtk.ImageMenuItem(gtk.STOCK_GOTO_BOTTOM)
+            subitem.set_label(_('Stop and Background (Ctrl+z)'))
+            submenu_signal.add(subitem)
+            subitem.connect('activate',
+                                lambda *x: self.background_command())
+            ## Submenu Foreground
+            subitem = gtk.ImageMenuItem(gtk.STOCK_GO_UP)
+            subitem.set_label(_('Foreground (%)'))
+            submenu_signal.add(subitem)
+            subitem.connect('activate',
+                                lambda *x: self.foreground_command())
+            ## Submenu Background run
+            subitem = gtk.ImageMenuItem(gtk.STOCK_GO_DOWN)
+            subitem.set_label(_('Run in background (% &)'))
+            submenu_signal.add(subitem)
+            subitem.connect('activate',
+                                lambda *x: self.bgrun_command())
             ## right-click popup menu Profiles
             menuit_prof = gtk.MenuItem()
             menuit_prof.set_label(_('Profiles'))
@@ -301,6 +343,24 @@
         self.show()
         self.grab_focus()
 
+    def cancel_command(self):
+        self.vte.feed_child(chr(3))
+
+    def stop_command(self):
+        self.vte.feed_child(chr(19))
+
+    def resume_command(self):
+        self.vte.feed_child(chr(17))
+
+    def background_command(self):
+        self.vte.feed_child(chr(26))
+
+    def foreground_command(self):
+        self.vte.feed_child('%\n')
+
+    def bgrun_command(self):
+        self.vte.feed_child('% &\n')
+
     def change_profile(self, profile):
         dbg(profile)
         self.profile = 'profile::' + profile
@@ -445,12 +505,37 @@
         if self.get_n_pages() == 1:
             self.emit('quit')
 
-    def run_command(self, cmd, ui, desc):
-        ## get the current notebook page so the function knows which terminal
-        ## to run the command in.
+    def get_page(self):
+        ## get the current notebook page
         pagenum = self.get_current_page()
-        page = self.get_nth_page(pagenum)
-        page.run_command(cmd, ui, desc)
+        return self.get_nth_page(pagenum)
+
+    def run_command(self, cmd, ui, desc):
+        self.get_page().run_command(cmd, ui, desc)
+        self.focus()
+
+    def cancel_command(self):
+        self.get_page().cancel_command()
+        self.focus()
+
+    def stop_command(self):
+        self.get_page().stop_command()
+        self.focus()
+
+    def resume_command(self):
+        self.get_page().resume_command()
+        self.focus()
+
+    def background_command(self):
+        self.get_page().background_command()
+        self.focus()
+
+    def foreground_command(self):
+        self.get_page().foreground_command()
+        self.focus()
+
+    def bgrun_command(self):
+        self.get_page().bgrun_command()
         self.focus()
 
     def update_all_term_config(self, config=None):
@@ -467,11 +552,7 @@
         tab.update_config(config)
 
     def copy(self):
-        page = self.get_current_page()
-        term = self.get_nth_page(page)
-        term.vte.copy_clipboard()
+        self.get_page().vte.copy_clipboard()
 
     def paste(self, text):
-        page = self.get_current_page()
-        term = self.get_nth_page(page)
-        term.vte.feed_child(text)
+        self.get_page().vte.feed_child(text)

=== modified file 'clicompanionlib/view.py'
--- clicompanionlib/view.py	2012-01-12 20:51:02 +0000
+++ clicompanionlib/view.py	2012-01-15 20:55:27 +0000
@@ -296,21 +296,37 @@
         self.vpane.pack2(self.l_vbox, True, True)
         self.add(self.vpane)
 
-        ## signals
+        ## signals from the tab plugins (LocalCommandsList and so)
         self.cmd_notebook.connect('run_command',
             lambda wdg, *args: self.term_notebook.run_command(*args))
         self.cmd_notebook.connect('show_man',
                 lambda wgt, cmd: cc_helpers.ManPage(cmd).run())
         self.cmd_notebook.connect('quit', lambda *x: gtk.main_quit())
+        ## Signals from the terminals notebook
         self.term_notebook.connect('quit', lambda *x: gtk.main_quit())
         self.term_notebook.connect('preferences', lambda *x: self.edit_pref())
+        ## expander
         self.expander.connect('notify::expanded',
                 lambda *x: self.expanded_cb())
+        ## Signals on the main window
         self.connect("delete_event", self.delete_event)
         self.connect("key-press-event", self.key_clicked)
+        ## Signals from the menus
         menu_bar.connect('quit', lambda *x: gtk.main_quit())
         menu_bar.connect('run_command',
                 lambda *x: self.cmd_notebook.run_command())
+        menu_bar.connect('cancel_command',
+                lambda *x: self.term_notebook.cancel_command())
+        menu_bar.connect('stop_command',
+                lambda *x: self.term_notebook.stop_command())
+        menu_bar.connect('resume_command',
+                lambda *x: self.term_notebook.resume_command())
+        menu_bar.connect('background_command',
+                lambda *x: self.term_notebook.background_command())
+        menu_bar.connect('foreground_command',
+                lambda *x: self.term_notebook.foreground_command())
+        menu_bar.connect('bgrun_command',
+                lambda *x: self.term_notebook.bgrun_command())
         menu_bar.connect('add_command',
                 lambda *x: self.cmd_notebook.add_command())
         menu_bar.connect('edit_command',
@@ -320,9 +336,12 @@
         menu_bar.connect('preferences', lambda *x: self.edit_pref())
         menu_bar.connect('add_tab', lambda *x: self.term_notebook.add_tab())
         menu_bar.connect('close_tab', lambda *x: self.term_notebook.quit_tab())
+        ## signals from the buttons
         self.button_box.connect('quit', lambda *x: gtk.main_quit())
         self.button_box.connect('run_command',
                 lambda *x: self.cmd_notebook.run_command())
+        self.button_box.connect('cancel_command',
+                lambda *x: self.cmd_notebook.cancel_command())
         self.button_box.connect('add_command',
                 lambda *x: self.cmd_notebook.add_command())
         self.button_box.connect('edit_command',
@@ -441,6 +460,9 @@
     def run_command(self):
         self.cmd_notebook.run_command()
 
+    def cancel_command(self):
+        self.cmd_notebook.cancel_command()
+
     def add_command(self):
         self.cmd_notebook.add_command()