def __station_status(self, object, sta, stat, msg, port): self.mainwindow.tabs["stations"].saw_station(sta, port, stat, msg) status = station_status.get_status_msgs()[stat] event = main_events.Event( None, "%s %s %s %s: %s" % (_("Station"), sta, _("is now"), status, msg)) self.mainwindow.tabs["event"].event(event)
def saw_station(self, station, port, status=0, smsg=""): status_changed = False if station == "CQCQCQ": return store = self.__view.get_model() ts = time.time() msg = "%s <b>%s</b> %s <i>%s</i>\r\n%s: <b>%s</b>" % \ (_("Station"), station, _("last seen at"), time.strftime("%X %x", time.localtime(ts)), _("Port"), port) status_val = station_status.get_status_msgs().get(status, "Unknown") if station not in self.__calls: if smsg: msg += "\r\nStatus: <b>%s</b> (<i>%s</i>)" % (status_val, smsg) self.__calls.append(station) store.append((station, ts, msg, status, smsg, port)) self.__view.queue_draw() status_changed = True self._update_station_count() else: iter = store.get_iter_first() while iter: call, _status, _smsg = store.get(iter, 0, 3, 4) if call == station: status_changed = (status and (_status != status) or \ (smsg and (_smsg != smsg))) if _status > 0 and status == 0: status = _status if not smsg: smsg = _smsg msg += "\r\nStatus: <b>%s</b> (<i>%s</i>)" % (status_val, smsg) store.set(iter, 1, ts, 2, msg, 3, status, 4, smsg, 5, port) break iter = store.iter_next(iter) if status_changed and status > 0 and \ self._config.getboolean("prefs", "chat_showstatus"): self.emit("incoming-chat-message", station, "CQCQCQ", "%s %s: %s (%s %s)" % (_("Now"), status_val, smsg, _("Port"), port))
def __init__(self, wtree, config): MainWindowTab.__init__(self, wtree, config, "main") frame, self.__view, = self._getw("stations_frame", "stations_view") store = Gtk.ListStore( gobject.TYPE_STRING, # Station gobject.TYPE_INT, # Timestamp gobject.TYPE_STRING, # Message gobject.TYPE_INT, # Status gobject.TYPE_STRING, # Status message gobject.TYPE_STRING) # Port store.set_sort_column_id(1, Gtk.SORT_DESCENDING) self.__view.set_model(store) try: self.__view.set_tooltip_column(2) except AttributeError: print("This version of GTK is old; disabling station tooltips") self.__view.connect("button_press_event", self._mouse_cb) def render_call(col, rend, model, iter): call, ts, status = model.get(iter, 0, 1, 3) sec = time.time() - ts hour = 3600 day = (hour * 24) if sec < 60: msg = call elif sec < hour: msg = "%s (%im)" % (call, (sec / 60)) elif sec < day: msg = "%s (%ih %im)" % (call, sec / 3600, (sec % 3600) / 60) else: msg = "%s (%id %ih)" % (call, sec / day, (sec % day) / 3600) if status == station_status.STATUS_ONLINE: color = "blue" elif status == station_status.STATUS_UNATTENDED: color = "#CC9900" elif status == station_status.STATUS_OFFLINE: color = "grey" else: color = "black" rend.set_property("markup", "<span color='%s'>%s</span>" % (color, msg)) r = Gtk.CellRendererText() col = Gtk.TreeViewColumn(_("Stations"), r, text=0) col.set_cell_data_func(r, render_call) self.__view.append_column(col) self.__calls = [] self._update_station_count() status, msg = self._getw("stations_status", "stations_smsg") try: status.set_tooltip_text( _("This is the state other stations will " + "see when requesting your status")) msg.set_tooltip_text( _("This is the message other stations will " + "see when requesting your status")) except AttributeError: pass def set_status(cb): self.__status = cb.get_active_text() self._config.set("state", "status_state", self.__status) def set_smsg(e): self.__smsg = e.get_text() self._config.set("state", "status_msg", self.__smsg) for s in sorted(station_status.get_status_msgs().values()): if s not in [_("Unknown"), _("Offline")]: status.append_text(s) status.connect("changed", set_status) msg.connect("changed", set_smsg) prev_status = self._config.get("state", "status_state") if not utils.combo_select(status, prev_status): utils.combo_select( status, list(station_status.get_status_msgs().values())[0]) msg.set_text(self._config.get("state", "status_msg")) set_status(status) set_smsg(msg) gobject.timeout_add(30000, self._update)
def __init__(self, wtree, config): MainWindowTab.__init__(self, wtree, config, "main") frame, self.__view, = self._getw("stations_frame", "stations_view") store = gtk.ListStore(gobject.TYPE_STRING, # Station gobject.TYPE_INT, # Timestamp gobject.TYPE_STRING, # Message gobject.TYPE_INT, # Status gobject.TYPE_STRING, # Status message gobject.TYPE_STRING) # Port store.set_sort_column_id(1, gtk.SORT_DESCENDING) self.__view.set_model(store) try: self.__view.set_tooltip_column(2) except AttributeError: print "This version of GTK is old; disabling station tooltips" self.__view.connect("button_press_event", self._mouse_cb) def render_call(col, rend, model, iter): call, ts, status = model.get(iter, 0, 1, 3) sec = time.time() - ts hour = 3600 day = (hour*24) if sec < 60: msg = call elif sec < hour: msg = "%s (%im)" % (call, (sec / 60)) elif sec < day: msg = "%s (%ih %im)" % (call, sec / 3600, (sec % 3600) / 60) else: msg = "%s (%id %ih)" % (call, sec / day, (sec % day) / 3600) if status == station_status.STATUS_ONLINE: color = "blue" elif status == station_status.STATUS_UNATTENDED: color = "#CC9900" elif status == station_status.STATUS_OFFLINE: color = "grey" else: color = "black" rend.set_property("markup", "<span color='%s'>%s</span>" % (color, msg)) r = gtk.CellRendererText() col = gtk.TreeViewColumn(_("Stations"), r, text=0) col.set_cell_data_func(r, render_call) self.__view.append_column(col) self.__calls = [] self._update_station_count() status, msg = self._getw("stations_status", "stations_smsg") try: status.set_tooltip_text(_("This is the state other stations will " + "see when requesting your status")) msg.set_tooltip_text(_("This is the message other stations will " + "see when requesting your status")) except AttributeError: pass def set_status(cb): self.__status = cb.get_active_text() self._config.set("state", "status_state", self.__status) def set_smsg(e): self.__smsg = e.get_text() self._config.set("state", "status_msg", self.__smsg) for s in sorted(station_status.get_status_msgs().values()): if s not in [_("Unknown"), _("Offline")]: status.append_text(s) status.connect("changed", set_status) msg.connect("changed", set_smsg) prev_status = self._config.get("state", "status_state") if not utils.combo_select(status, prev_status): utils.combo_select(status, station_status.get_status_msgs().values()[0]) msg.set_text(self._config.get("state", "status_msg")) set_status(status) set_smsg(msg) gobject.timeout_add(30000, self._update)