class Syskit::GUI::JobStatusDisplay

Constants

INTERMEDIATE_TERMINAL_STATES

Attributes

exceptions[R]
job[R]
notifications[R]
ui_drop[R]
ui_job_actions[R]
ui_notifications[R]
ui_restart[R]
ui_start[R]
ui_state[R]

Public Class Methods

new(job, batch_manager) click to toggle source
Calls superclass method
# File lib/syskit/gui/job_status_display.rb, line 18
def initialize(job, batch_manager)
    super(nil)
    @batch_manager = batch_manager
    @job = job
    @exceptions = Array.new
    @notifications = Hash.new
    @show_actions = true

    create_ui
    connect_to_hooks
    hide_job_actions
end

Public Instance Methods

connect_to_hooks() click to toggle source
# File lib/syskit/gui/job_status_display.rb, line 134
def connect_to_hooks
    ui_drop.connect(SIGNAL('clicked()')) do
        @batch_manager.drop_job(self)
        if @actions_immediate
            @batch_manager.process
        end
    end
    ui_restart.connect(SIGNAL('clicked()')) do
        arguments = job.action_arguments.dup
        arguments.delete(:job_id)
        if @batch_manager.create_new_job(job.action_name, arguments)
            @batch_manager.drop_job(self)
            if @actions_immediate
                @batch_manager.process
            end
        end
    end
    ui_start.connect(SIGNAL('clicked()')) do
        arguments = job.action_arguments.dup
        arguments.delete(:job_id)
        if @batch_manager.create_new_job(job.action_name, arguments)
            if @actions_immediate
                @batch_manager.process
            end
        end
    end
    job.on_progress do |state|
        update_state(state)
    end
    job.on_exception do |kind, exception|
        exceptions << exception.exception
        notify('exceptions', "#{exceptions.size} exceptions")
        emit exceptionEvent
    end
end
create_ui() click to toggle source
# File lib/syskit/gui/job_status_display.rb, line 42
def create_ui
    self.focus_policy = Qt::ClickFocus
    @ui_state = JobStateLabel.new name: label
    if job.state
        ui_state.update_state(job.state.upcase)
    end

    @ui_job_actions = Qt::Widget.new(self)
    hlayout    = Qt::HBoxLayout.new(ui_job_actions)
    @actions_buttons = Hash[
        'Drop' => Qt::PushButton.new("Drop", self),
        'Restart' => Qt::PushButton.new("Restart", self),
        "Start Again" => Qt::PushButton.new("Start Again", self)
    ]
    hlayout.add_widget(@ui_drop    = @actions_buttons['Drop'])
    hlayout.add_widget(@ui_restart = @actions_buttons['Restart'])
    hlayout.add_widget(@ui_start   = @actions_buttons['Start Again'])

    ui_start.hide
    hlayout.set_contents_margins(0, 0, 0, 0)

    @ui_notifications = Qt::Label.new("", self)
    ui_notifications.hide

    vlayout = Qt::VBoxLayout.new(self)
    vlayout.add_widget ui_state
    vlayout.add_widget ui_job_actions
    vlayout.add_widget ui_notifications
end
enterEvent(event) click to toggle source
Calls superclass method
# File lib/syskit/gui/job_status_display.rb, line 110
def enterEvent(event)
    super
    if show_actions?
        show_job_actions
        self.focus = Qt::OtherFocusReason
    end
end
hide_job_actions() click to toggle source
# File lib/syskit/gui/job_status_display.rb, line 102
def hide_job_actions
    ui_job_actions.hide
    s = size
    s.height = size_hint.height
    self.size = s
end
keyPressEvent(event) click to toggle source
Calls superclass method
# File lib/syskit/gui/job_status_display.rb, line 72
def keyPressEvent(event)
    make_actions_immediate(event.key == Qt::Key_Control)
    super
end
keyReleaseEvent(event) click to toggle source
Calls superclass method
# File lib/syskit/gui/job_status_display.rb, line 77
def keyReleaseEvent(event)
    make_actions_immediate(false)
    super
end
label() click to toggle source
# File lib/syskit/gui/job_status_display.rb, line 38
def label
    "##{job.job_id} #{job.action_name}"
end
leaveEvent(event) click to toggle source
Calls superclass method
# File lib/syskit/gui/job_status_display.rb, line 118
def leaveEvent(event)
    super
    if show_actions?
        hide_job_actions
    end
end
make_actions_immediate(enable) click to toggle source
# File lib/syskit/gui/job_status_display.rb, line 82
def make_actions_immediate(enable)
    @actions_immediate = enable
    if enable
        @actions_buttons.each do |text, btn|
            btn.text = "#{text} Now"
        end
    else
        @actions_buttons.each do |text, btn|
            btn.text = text
        end
    end
end
mousePressEvent(event) click to toggle source
# File lib/syskit/gui/job_status_display.rb, line 125
def mousePressEvent(event)
    emit clicked
    event.accept
end
mouseReleaseEvent(event) click to toggle source
# File lib/syskit/gui/job_status_display.rb, line 129
def mouseReleaseEvent(event)
    event.accept
end
notify(key, text) click to toggle source
# File lib/syskit/gui/job_status_display.rb, line 191
def notify(key, text)
    notifications[key] = text
    ui_notifications.show
    ui_notifications.text = "<small>#{notifications.values.join(", ")}</small>"
end
show_job_actions() click to toggle source
# File lib/syskit/gui/job_status_display.rb, line 95
def show_job_actions
    ui_job_actions.show
    s = size
    s.height = size_hint.height
    self.size = s
end
update_state(state) click to toggle source
# File lib/syskit/gui/job_status_display.rb, line 170
def update_state(state)
    if INTERMEDIATE_TERMINAL_STATES.include?(ui_state.current_state)
        ui_state.update_state(
            "#{ui_state.current_state},
                #{state.upcase}",
            color: ui_state.current_color)
    else
        ui_state.update_state(state.upcase)
    end

    if state == Roby::Interface::JOB_DROPPED
        ui_drop.hide
        ui_restart.hide
        ui_start.show
    elsif Roby::Interface.terminal_state?(state)
        ui_drop.hide
        ui_restart.hide
        ui_start.show
    end
end