Skip to content

Commit

Permalink
Added stop and release menu items in gscan.
Browse files Browse the repository at this point in the history
  * Fixed icons not displaying in right-click menus in gscan
  • Loading branch information
dvalters committed Apr 5, 2017
1 parent 2e2ddd0 commit 4afd3df
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 10 deletions.
5 changes: 5 additions & 0 deletions bin/cylc-gscan
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ import gtk
import warnings
warnings.filterwarnings('ignore', 'use the new', Warning)

gtk.settings_get_default().set_long_property(
"gtk-button-images", True, "main")
gtk.settings_get_default().set_long_property(
"gtk-menu-images", True, "main")

from cylc.gui.gscan import ScanApp
from cylc.option_parsers import CylcOptionParser as COP
from cylc.owner import USER
Expand Down
2 changes: 2 additions & 0 deletions lib/cylc/gui/gscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ def _on_button_press_event(self, treeview, event):
self.HOST_COLUMN, self.OWNER_COLUMN, self.SUITE_COLUMN)
suite_keys.append((host, owner, suite))

# Add a cylc-stop command

if event.type == gtk.gdk._2BUTTON_PRESS:
if suite_keys:
launch_gcylc(suite_keys[0])
Expand Down
104 changes: 94 additions & 10 deletions lib/cylc/gui/scanutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,11 @@ def get_scan_menu(suite_keys,
for host, owner, suite in suite_keys:
gcylc_item = gtk.ImageMenuItem("Launch gcylc: %s - %s@%s" % (
suite.replace('_', '__'), owner, host))
img = gtk.image_new_from_stock("gcylc", gtk.ICON_SIZE_MENU)
gcylc_item.set_image(img)
gcylc_item._connect_args = (host, owner, suite)
img_gcylc = gtk.image_new_from_stock("gcylc", gtk.ICON_SIZE_MENU)
gcylc_item.set_image(img_gcylc)
gcylc_item.connect(
"button-press-event",
lambda b, e: launch_gcylc(b._connect_args))
lambda b, e: launch_gcylc((host, owner, suite)))
gcylc_item.show()
menu.append(gcylc_item)
if suite_keys:
Expand All @@ -107,6 +106,49 @@ def get_scan_menu(suite_keys,
sep_item.show()
menu.append(sep_item)

# Construct a cylc stop item to stop a suite
for host, owner, suite in suite_keys:
stoptask_item = gtk.ImageMenuItem('Stop')
img_stop = gtk.image_new_from_stock(gtk.STOCK_MEDIA_STOP,
gtk.ICON_SIZE_MENU)
stoptask_item.set_image(img_stop)
menu.append(stoptask_item)
stoptask_item.show()
stoptask_item.connect("button-press-event",
lambda b, e: call_cylc_command(
(host, owner, suite),
'stop'))

# Construct a cylc hold item to hold (pause) a suite
for host, owner, suite in suite_keys:
holdtask_item = gtk.ImageMenuItem('Hold')
img_hold = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PAUSE,
gtk.ICON_SIZE_MENU)
holdtask_item.set_image(img_hold)
menu.append(holdtask_item)
holdtask_item.show()
holdtask_item.connect("button-press-event",
lambda b, e: call_cylc_command(
(host, owner, suite),
'hold'))

# Construct a cylc release item to release a paused/stopped suite
for host, owner, suite in suite_keys:
unstoptask_item = gtk.ImageMenuItem('Release')
img_release = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PLAY,
gtk.ICON_SIZE_MENU)
unstoptask_item.set_image(img_release)
menu.append(unstoptask_item)
unstoptask_item.show()
unstoptask_item.connect("button-press-event",
lambda b, e: call_cylc_command(
(host, owner, suite),
'release'))

sep_item = gtk.SeparatorMenuItem()
sep_item.show()
menu.append(sep_item)

# Construct theme chooser items (same as cylc.gui.app_main).
theme_item = gtk.ImageMenuItem('Theme')
img = gtk.image_new_from_stock(gtk.STOCK_SELECT_COLOR, gtk.ICON_SIZE_MENU)
Expand Down Expand Up @@ -249,12 +291,9 @@ def _launch_hosts_dialog(existing_hosts, change_hosts_func):
dialog.destroy()


def launch_gcylc(key):
"""Launch gcylc for a given suite and host."""
host, owner, suite = key
args = ["--host=" + host, "--user=" + owner, suite]

# Get version of suite
def get_suite_version(args):
"""Gets the suite version given the host, owner, and suite arguments"""
# Make this into separate method - originally in launch_gcylc
f_null = open(os.devnull, "w")
if cylc.flags.debug:
stderr = sys.stderr
Expand All @@ -266,6 +305,18 @@ def launch_gcylc(key):
suite_version = proc.communicate()[0].strip()
proc.wait()

return suite_version


def launch_gcylc(key):
"""Launch gcylc for a given suite and host."""
host, owner, suite = key
args = ["--host=" + host, "--user=" + owner, suite]

# Get version of suite - now separate method get_suite_version()
f_null = open(os.devnull, "w")
suite_version = get_suite_version(args)

# Run correct version of "cylc gui", provided that "admin/cylc-wrapper" is
# installed.
env = None
Expand All @@ -283,6 +334,39 @@ def launch_gcylc(key):
Popen(["nohup"] + command, env=env, stdout=stdout, stderr=stderr)


def call_cylc_command(key, command_id):
"""Calls one of the Cylc commands (such as 'stop', 'hold', etc...).
Args:
key (tuple): The key containing host, owner, and suite
command_id (str): A string giving the Cylc command.
Example:
call_cylc_command(key, "stop")
"""
host, owner, suite = key
args = ["--host=" + host, "--user=" + owner, suite]

# Get version of suite
f_null = open(os.devnull, "w")
suite_version = get_suite_version(args)

env = None
if suite_version != CYLC_VERSION:
env = dict(os.environ)
env["CYLC_VERSION"] = suite_version
command = ["cylc", command_id] + args

if cylc.flags.debug:
stdout = sys.stdout
stderr = sys.stderr
Popen(command, env=env, stdout=stdout, stderr=stderr)
else:
stdout = f_null
stderr = stdout
Popen(["nohup"] + command, env=env, stdout=stdout, stderr=stderr)


def update_suites_info(
hosts=None, timeout=None, owner_pattern=None, name_pattern=None,
prev_results=None):
Expand Down

0 comments on commit 4afd3df

Please sign in to comment.