def update(self, update_time=None): """Update the Applet.""" suite_host_tuples = [] statuses = copy.deepcopy(self.statuses) stop_summaries = copy.deepcopy(self.stop_summaries) for host in self.hosts: suites = (statuses.get(host, {}).keys() + stop_summaries.get(host, {}).keys()) for suite in suites: suite_host_tuples.append((suite, host)) suite_host_tuples.sort() for child in self.dot_hbox.get_children(): self.dot_hbox.remove(child) number_mode = (not self.is_compact and len(suite_host_tuples) > self.MAX_INDIVIDUAL_SUITES) suite_statuses = {} compact_suite_statuses = [] for suite, host in suite_host_tuples: if suite in statuses.get(host, {}): status_map = statuses[host][suite] is_stopped = False else: info = stop_summaries[host][suite] status_map, suite_time = info is_stopped = True status = extract_group_state(status_map.keys(), is_stopped=is_stopped) if number_mode: suite_statuses.setdefault(is_stopped, {}) suite_statuses[is_stopped].setdefault(status, []) suite_statuses[is_stopped][status].append( (suite, host, status_map.items())) elif self.is_compact: compact_suite_statuses.append((suite, host, status, status_map.items(), is_stopped)) else: self._add_image_box([(suite, host, status, status_map.items(), is_stopped)]) if number_mode: for is_stopped in sorted(suite_statuses.keys()): statuses = suite_statuses[is_stopped].items() statuses.sort(lambda x, y: cmp(len(y[1]), len(x[1]))) for status, suite_host_states_tuples in statuses: label = gtk.Label( str(len(suite_host_states_tuples)) + ":") label.show() self.dot_hbox.pack_start(label, expand=False, fill=False) suite_info_tuples = [] for suite, host, task_states in suite_host_states_tuples: suite_info_tuples.append((suite, host, status, task_states, is_stopped)) self._add_image_box(suite_info_tuples) if self.is_compact: if not compact_suite_statuses: # No suites running or stopped. self.gcylc_image.show() return False self.gcylc_image.hide() self._add_image_box(compact_suite_statuses) return False
def update(self, update_time=None): """Update the Applet.""" suite_host_tuples = [] statuses = copy.deepcopy(self.statuses) stop_summaries = copy.deepcopy(self.stop_summaries) for host in self.hosts: suites = (statuses.get(host, {}).keys() + stop_summaries.get(host, {}).keys()) for suite in suites: suite_host_tuples.append((suite, host)) suite_host_tuples.sort() for child in self.dot_hbox.get_children(): self.dot_hbox.remove(child) number_mode = (not self.is_compact and len(suite_host_tuples) > self.MAX_INDIVIDUAL_SUITES) suite_statuses = {} compact_suite_statuses = [] for suite, host in suite_host_tuples: if suite in statuses.get(host, {}): status_map = statuses[host][suite] is_stopped = False else: info = stop_summaries[host][suite] status_map, suite_time = info is_stopped = True status = extract_group_state(status_map.keys(), is_stopped=is_stopped) if number_mode: suite_statuses.setdefault(is_stopped, {}) suite_statuses[is_stopped].setdefault(status, []) suite_statuses[is_stopped][status].append( (suite, host, status_map.items())) elif self.is_compact: compact_suite_statuses.append( (suite, host, status, status_map.items(), is_stopped)) else: self._add_image_box([(suite, host, status, status_map.items(), is_stopped)]) if number_mode: for is_stopped in sorted(suite_statuses.keys()): statuses = suite_statuses[is_stopped].items() statuses.sort(lambda x, y: cmp(len(y[1]), len(x[1]))) for status, suite_host_states_tuples in statuses: label = gtk.Label(str(len(suite_host_states_tuples)) + ":") label.show() self.dot_hbox.pack_start(label, expand=False, fill=False) suite_info_tuples = [] for suite, host, task_states in suite_host_states_tuples: suite_info_tuples.append( (suite, host, status, task_states, is_stopped)) self._add_image_box(suite_info_tuples) if self.is_compact: if not compact_suite_statuses: # No suites running or stopped. self.gcylc_image.show() return False self.gcylc_image.hide() self._add_image_box(compact_suite_statuses) return False
def _add_image_box(self, suite_host_info_tuples): image_eb = gtk.EventBox() image_eb.show() is_all_stopped = False running_status_list = [] status_list = [] suite_host_tuples = [] for info_tuple in suite_host_info_tuples: suite, host, status, task_states, is_stopped = info_tuple suite_host_tuples.append((suite, host)) if not is_stopped: running_status_list.append(status) status_list.append(status) if running_status_list: status = extract_group_state(running_status_list, is_stopped=False) image = self.dots.get_image(status, is_stopped=False) else: status = extract_group_state(status_list, is_stopped=True) image = self.dots.get_image(status, is_stopped=True) image.show() image_eb.add(image) image_eb._connect_args = suite_host_tuples image_eb.connect("button-press-event", self._on_button_press_event) text_format = "%s - %s - %s" long_text_format = text_format + "\n Tasks: %s\n" text = "" tip_vbox = gtk.VBox() # Only used in PyGTK 2.12+ tip_vbox.show() for info_tuple in suite_host_info_tuples: suite, host, status, task_states, is_stopped = info_tuple task_states.sort(lambda x, y: cmp(len(y[1]), len(x[1]))) tip_hbox = gtk.HBox() tip_hbox.show() state_info = [] for state_name, tasks in task_states: state_info.append(str(len(tasks)) + " " + state_name) image = self.dots.get_image(state_name, is_stopped=is_stopped) image.show() tip_hbox.pack_start(image, expand=False, fill=False) states_text = ", ".join(state_info) if status is None: suite_summary = "?" else: suite_summary = status if is_stopped: suite_summary = "stopped with " + suite_summary tip_label = gtk.Label(text_format % (suite, suite_summary, host)) tip_label.show() tip_hbox.pack_start(tip_label, expand=False, fill=False, padding=5) tip_vbox.pack_start(tip_hbox, expand=False, fill=False) text += long_text_format % (suite, suite_summary, host, states_text) text = text.rstrip() if hasattr(gtk, "Tooltip"): image_eb.set_has_tooltip(True) image_eb.connect("query-tooltip", self._on_img_tooltip_query, tip_vbox) else: self._set_tooltip(image_eb, text) self.dot_hbox.pack_start(image_eb, expand=False, fill=False, padding=1)