def btn(label, tooltip, callback, icon_name=None): btn = gtk.Button(label) btn.set_tooltip_text(tooltip) btn.connect("clicked", callback) if icon_name: icon = self.get_icon(icon_name) if icon: btn.set_image(scaled_image(icon, 24)) hbox.pack_start(btn) return btn
def get_image(self, icon_name, size=None): try: pixbuf = self.get_pixbuf(icon_name) log("get_image(%s, %s) pixbuf=%s", icon_name, size, pixbuf) if not pixbuf: return None return scaled_image(pixbuf, size) except: log.error("get_image(%s, %s)", icon_name, size, exc_info=True) return None
def btn(self, label, tooltip, callback, icon_name=None): btn = Gtk.Button(label) settings = btn.get_settings() settings.set_property('gtk-button-images', True) btn.set_tooltip_text(tooltip) btn.connect("clicked", callback) icon = get_icon_pixbuf(icon_name) if icon: btn.set_image(scaled_image(icon, 24)) return btn
def get_image(self, icon_name, size=None): from xpra.gtk_common.gtk_util import scaled_image try: pixbuf = self.get_pixbuf(icon_name) traylog("get_image(%s, %s) pixbuf=%s", icon_name, size, pixbuf) if not pixbuf: return None return scaled_image(pixbuf, size) except: traylog.error("get_image(%s, %s)", icon_name, size, exc_info=True) return None
def populate_table(self): log("populate_table: %i records", len(self.records)) if self.table: self.vbox.remove(self.table) self.table = None if not self.records: self.table = gtk.Label("No sessions found") self.vbox.add(self.table) self.table.show() return tb = TableBuilder(1, 6, False) tb.add_row(gtk.Label("Host"), gtk.Label("Session"), gtk.Label("Platform"), gtk.Label("Type"), gtk.Label("URI"), gtk.Label("Connect")) self.table = tb.get_table() self.vbox.add(self.table) self.table.resize(1 + len(self.records), 5) #group them by uuid d = OrderedDict() for i, (interface, protocol, name, stype, domain, host, address, port, text) in enumerate(self.records): uuid = text.get("uuid", "") display = text.get("display", "") platform = text.get("platform", "") dtype = text.get("type", "") if domain == "local" and host.endswith(".local"): host = host[:-len(".local")] key = (uuid, uuid or i, host, display, platform, dtype) d.setdefault(key, []).append((interface, protocol, name, stype, domain, host, address, port, text)) for key, recs in d.items(): if type(key) == tuple: uuid, _, host, display, platform, dtype = key else: display = key uuid, host, platform, dtype = None, None, sys.platform, None title = uuid if display: title = display label = gtk.Label(title) if uuid != title: label.set_tooltip_text(uuid) #try to use an icon for the platform: platform_icon_name = self.get_platform_icon_name(platform) if platform_icon_name: pwidget = scaled_image( self.get_pixbuf("%s.png" % platform_icon_name), 24) pwidget.set_tooltip_text(platform) else: pwidget = gtk.Label(platform) w, c = self.make_connect_widgets(recs, address, port, display) tb.add_row(gtk.Label(host), label, pwidget, gtk.Label(dtype), w, c) self.table.show_all()
def get_image(self, icon_name, size=None): try: pixbuf = get_icon(icon_name) debug("get_image(%s, %s) pixbuf=%s", icon_name, size, pixbuf) if not pixbuf: return None if size: return scaled_image(pixbuf, size) return gtk.image_new_from_pixbuf(pixbuf) except: log.error("get_image(%s, %s)", icon_name, size, exc_info=True) return None
def get_appimage(app_name, icondata=None, menu_icon_size=24): pixbuf = None if app_name and not icondata: #try to load from our icons: nstr = bytestostr(app_name).lower() icon_filename = os.path.join(get_icon_dir(), "%s.png" % nstr) if os.path.exists(icon_filename): pixbuf = GdkPixbuf.Pixbuf.new_from_file(icon_filename) if not pixbuf and icondata: #gtk pixbuf loader: try: loader = GdkPixbuf.PixbufLoader() loader.write(icondata) loader.close() pixbuf = loader.get_pixbuf() except Exception as e: log("pixbuf loader failed", exc_info=True) log.error("Error: failed to load icon data for '%s':", bytestostr(app_name)) log.error(" %s", e) log.error(" data=%s", repr_ellipsized(icondata)) if not pixbuf and icondata: #let's try pillow: try: from xpra.codecs.pillow.decoder import open_only img = open_only(icondata) has_alpha = img.mode == "RGBA" width, height = img.size rowstride = width * (3 + int(has_alpha)) pixbuf = get_pixbuf_from_data(img.tobytes(), has_alpha, width, height, rowstride) return scaled_image(pixbuf, icon_size=menu_icon_size) except Exception: log.error("Error: failed to load icon data for %s", bytestostr(app_name), exc_info=True) log.error(" data=%s", repr_ellipsized(icondata)) if pixbuf: return scaled_image(pixbuf, icon_size=menu_icon_size) return None
def get_image(self, icon_name, size=None): try: if not icon_name: return None icon_filename = get_icon_filename(icon_name) if not icon_filename: return None pixbuf = pixbuf_new_from_file(icon_filename) if not pixbuf: return None return scaled_image(pixbuf, size) except Exception: log.error("get_image(%s, %s)", icon_name, size, exc_info=True) return None
def btn(self, label, tooltip, code, icon_name=None): btn = gtk.Button(label) settings = btn.get_settings() settings.set_property('gtk-button-images', True) if tooltip: btn.set_tooltip_text(tooltip) def btn_clicked(*_args): log("%s button clicked, returning %s", label, code) self.exit_code = code self.quit() btn.set_size_request(100, 48) btn.connect("clicked", btn_clicked) btn.set_can_focus(True) isdefault = label[:1].upper()!=label[:1] btn.set_can_default(isdefault) if isdefault: self.window.set_default(btn) self.window.set_focus(btn) if icon_name: icon = self.get_icon(icon_name) if icon: btn.set_image(scaled_image(icon, 24)) return btn
def scaled_image(self, pixbuf, icon_size=None): if not icon_size: icon_size = self.get_icon_size() return scaled_image(pixbuf, icon_size, icon_size)
def create_window(self): self.window = gtk.Window() self.window.connect("destroy", self.destroy) self.window.set_default_size(400, 260) self.window.set_border_width(20) self.window.set_title("Xpra Launcher") self.window.modify_bg(STATE_NORMAL, gdk.Color(red=65535, green=65535, blue=65535)) self.window.set_position(WIN_POS_CENTER) vbox = gtk.VBox(False, 0) vbox.set_spacing(15) #top row: hbox = gtk.HBox(False, 0) # About dialog (and window icon): icon_pixbuf = self.get_icon("xpra.png") if icon_pixbuf: self.window.set_icon(icon_pixbuf) logo_button = self.image_button("", "About", icon_pixbuf, about) hbox.pack_start(logo_button, expand=False, fill=False) # Bug report tool link: icon_pixbuf = self.get_icon("bugs.png") self.bug_tool = None if icon_pixbuf: def bug(*_args): if self.bug_tool==None: from xpra.client.gtk_base.bug_report import BugReport self.bug_tool = BugReport() self.bug_tool.init(show_about=False) self.bug_tool.show() bug_button = self.image_button("", "Bug Report", icon_pixbuf, bug) hbox.pack_start(bug_button, expand=False, fill=False) # Session browser link: icon_pixbuf = self.get_icon("mdns.png") self.mdns_gui = None if icon_pixbuf and self.has_mdns(): def mdns(*_args): if self.mdns_gui==None: from xpra.client.gtk_base.mdns_gui import mdns_sessions self.mdns_gui = mdns_sessions(self.config) def close_mdns(): self.mdns_gui.destroy() self.mdns_gui = None self.mdns_gui.do_quit = close_mdns else: self.mdns_gui.present() mdns_button = self.image_button("", "Browse Sessions", icon_pixbuf, mdns) hbox.pack_start(mdns_button, expand=False, fill=False) # Title label = gtk.Label("Connect to xpra server") label.modify_font(pango.FontDescription("sans 14")) hbox.pack_start(label, expand=True, fill=True) vbox.pack_start(hbox) # Mode: hbox = gtk.HBox(False, 20) hbox.set_spacing(20) hbox.pack_start(gtk.Label("Mode: ")) self.mode_combo = gtk.combo_box_new_text() for x in self.get_connection_modes(): self.mode_combo.append_text(x.upper()) self.mode_combo.connect("changed", self.mode_changed) hbox.pack_start(self.mode_combo) vbox.pack_start(hbox) # Username@Host:Port hbox = gtk.HBox(False, 0) hbox.set_spacing(5) self.username_entry = gtk.Entry() self.username_entry.set_max_length(128) self.username_entry.set_width_chars(16) self.username_entry.connect("changed", self.validate) self.username_entry.set_tooltip_text("username") self.username_label = gtk.Label("@") self.host_entry = gtk.Entry() self.host_entry.set_max_length(128) self.host_entry.set_width_chars(24) self.host_entry.connect("changed", self.validate) self.host_entry.set_tooltip_text("hostname") self.ssh_port_entry = gtk.Entry() self.ssh_port_entry.set_max_length(5) self.ssh_port_entry.set_width_chars(5) self.ssh_port_entry.connect("changed", self.validate) self.ssh_port_entry.set_tooltip_text("SSH port") self.port_entry = gtk.Entry() self.port_entry.set_max_length(5) self.port_entry.set_width_chars(5) self.port_entry.connect("changed", self.validate) self.port_entry.set_tooltip_text("port/display") hbox.pack_start(self.username_entry) hbox.pack_start(self.username_label) hbox.pack_start(self.host_entry) hbox.pack_start(self.ssh_port_entry) hbox.pack_start(gtk.Label(":")) hbox.pack_start(self.port_entry) vbox.pack_start(hbox) # Password hbox = gtk.HBox(False, 0) hbox.set_spacing(20) self.password_entry = gtk.Entry() self.password_entry.set_max_length(128) self.password_entry.set_width_chars(30) self.password_entry.set_text("") self.password_entry.set_visibility(False) self.password_entry.connect("changed", self.password_ok) self.password_entry.connect("changed", self.validate) self.password_label = gtk.Label("Password: "******"Disable Strict Host Key Check") self.nostrict_host_check.set_active(False) al = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0) al.add(self.nostrict_host_check) hbox.pack_start(al) vbox.pack_start(hbox) # Info Label self.info = gtk.Label() self.info.set_line_wrap(True) self.info.set_size_request(360, -1) self.info.modify_fg(STATE_NORMAL, red) vbox.pack_start(self.info) #hide encoding options by default self.encoding_combo = None self.encoding_options_check = None self.encoding_box = None if not PYTHON3: #not implemented for gtk3, where we can't use set_menu()... hbox = gtk.HBox(False, 0) hbox.set_spacing(20) self.encoding_options_check = gtk.CheckButton("Advanced Encoding Options") self.encoding_options_check.connect("toggled", self.encoding_options_toggled) self.encoding_options_check.set_active(False) al = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0) al.add(self.encoding_options_check) hbox.pack_start(al) vbox.pack_start(hbox) self.encoding_box = gtk.VBox() vbox.pack_start(self.encoding_box) # Encoding: hbox = gtk.HBox(False, 20) hbox.set_spacing(20) hbox.pack_start(gtk.Label("Encoding: ")) self.encoding_combo = OptionMenu() def get_current_encoding(): return self.config.encoding def set_new_encoding(e): self.config.encoding = e encodings = ["auto"]+[x for x in PREFERED_ENCODING_ORDER if x in self.client.get_encodings()] server_encodings = encodings es = make_encodingsmenu(get_current_encoding, set_new_encoding, encodings, server_encodings) self.encoding_combo.set_menu(es) set_history_from_active(self.encoding_combo) hbox.pack_start(self.encoding_combo) self.encoding_box.pack_start(hbox) self.encoding_combo.connect("changed", self.encoding_changed) # Quality hbox = gtk.HBox(False, 20) hbox.set_spacing(20) self.quality_label = gtk.Label("Quality: ") hbox.pack_start(self.quality_label) self.quality_combo = OptionMenu() def set_min_quality(q): self.config.min_quality = q def set_quality(q): self.config.quality = q def get_min_quality(): return self.config.min_quality def get_quality(): return self.config.quality sq = make_min_auto_menu("Quality", MIN_QUALITY_OPTIONS, QUALITY_OPTIONS, get_min_quality, get_quality, set_min_quality, set_quality) self.quality_combo.set_menu(sq) set_history_from_active(self.quality_combo) hbox.pack_start(self.quality_combo) self.encoding_box.pack_start(hbox) # Speed hbox = gtk.HBox(False, 20) hbox.set_spacing(20) self.speed_label = gtk.Label("Speed: ") hbox.pack_start(self.speed_label) self.speed_combo = OptionMenu() def set_min_speed(s): self.config.min_speed = s def set_speed(s): self.config.speed = s def get_min_speed(): return self.config.min_speed def get_speed(): return self.config.speed ss = make_min_auto_menu("Speed", MIN_SPEED_OPTIONS, SPEED_OPTIONS, get_min_speed, get_speed, set_min_speed, set_speed) self.speed_combo.set_menu(ss) set_history_from_active(self.speed_combo) hbox.pack_start(self.speed_combo) self.encoding_box.pack_start(hbox) self.encoding_box.hide() # Buttons: hbox = gtk.HBox(False, 20) vbox.pack_start(hbox) #Save: self.save_btn = gtk.Button("Save") self.save_btn.set_tooltip_text("Save settings to a session file") self.save_btn.connect("clicked", self.save_clicked) hbox.pack_start(self.save_btn) #Load: self.load_btn = gtk.Button("Load") self.load_btn.set_tooltip_text("Load settings from a session file") self.load_btn.connect("clicked", self.load_clicked) hbox.pack_start(self.load_btn) # Connect button: self.button = gtk.Button("Connect") self.button.connect("clicked", self.connect_clicked) connect_icon = self.get_icon("retry.png") if connect_icon: self.button.set_image(scaled_image(connect_icon, 24)) hbox.pack_start(self.button) def accel_close(*_args): gtk.main_quit() add_close_accel(self.window, accel_close) vbox.show_all() self.encoding_options_toggled() self.window.vbox = vbox self.window.add(vbox)
def create_window(self): self.window = gtk.Window() self.window.connect("destroy", self.destroy) self.window.set_default_size(400, 300) self.window.set_border_width(20) self.window.set_title("Xpra Launcher") self.window.modify_bg(STATE_NORMAL, gdk.Color(red=65535, green=65535, blue=65535)) icon_pixbuf = self.get_icon("xpra.png") if icon_pixbuf: self.window.set_icon(icon_pixbuf) self.window.set_position(WIN_POS_CENTER) vbox = gtk.VBox(False, 0) vbox.set_spacing(15) # Title hbox = gtk.HBox(False, 0) if icon_pixbuf: logo_button = gtk.Button("") settings = logo_button.get_settings() settings.set_property('gtk-button-images', True) logo_button.connect("clicked", about) logo_button.set_tooltip_text("About") image = gtk.Image() image.set_from_pixbuf(icon_pixbuf) logo_button.set_image(image) hbox.pack_start(logo_button, expand=False, fill=False) icon_pixbuf = self.get_icon("bugs.png") self.bug_tool = None if icon_pixbuf: bug_button = gtk.Button("") settings = bug_button.get_settings() settings.set_property('gtk-button-images', True) def bug(*args): if self.bug_tool == None: from xpra.client.gtk_base.bug_report import BugReport self.bug_tool = BugReport() self.bug_tool.init(show_about=False) self.bug_tool.show() bug_button.connect("clicked", bug) bug_button.set_tooltip_text("Bug Report") image = gtk.Image() image.set_from_pixbuf(icon_pixbuf) bug_button.set_image(image) hbox.pack_start(bug_button, expand=False, fill=False) label = gtk.Label("Connect to xpra server") label.modify_font(pango.FontDescription("sans 14")) hbox.pack_start(label, expand=True, fill=True) vbox.pack_start(hbox) # Mode: hbox = gtk.HBox(False, 20) hbox.set_spacing(20) hbox.pack_start(gtk.Label("Mode: ")) self.mode_combo = gtk.combo_box_new_text() #self.mode_combo.get_model().clear() self.mode_combo.append_text("TCP") if "AES" in ENCRYPTION_CIPHERS: self.mode_combo.append_text("TCP + AES") self.mode_combo.append_text("SSH") self.mode_combo.connect("changed", self.mode_changed) hbox.pack_start(self.mode_combo) vbox.pack_start(hbox) self.encoding_combo = None if not PYTHON3: #not implemented for gtk3, where we can't use set_menu()... # Encoding: hbox = gtk.HBox(False, 20) hbox.set_spacing(20) hbox.pack_start(gtk.Label("Encoding: ")) self.encoding_combo = OptionMenu() def get_current_encoding(): return self.config.encoding def set_new_encoding(e): self.config.encoding = e encodings = [ x for x in PREFERED_ENCODING_ORDER if x in self.client.get_encodings() ] server_encodings = encodings es = make_encodingsmenu(get_current_encoding, set_new_encoding, encodings, server_encodings) self.encoding_combo.set_menu(es) set_history_from_active(self.encoding_combo) hbox.pack_start(self.encoding_combo) vbox.pack_start(hbox) self.encoding_combo.connect("changed", self.encoding_changed) # Quality hbox = gtk.HBox(False, 20) hbox.set_spacing(20) self.quality_label = gtk.Label("Quality: ") hbox.pack_start(self.quality_label) self.quality_combo = OptionMenu() def set_min_quality(q): self.config.min_quality = q def set_quality(q): self.config.quality = q def get_min_quality(): return self.config.min_quality def get_quality(): return self.config.quality sq = make_min_auto_menu("Quality", MIN_QUALITY_OPTIONS, QUALITY_OPTIONS, get_min_quality, get_quality, set_min_quality, set_quality) self.quality_combo.set_menu(sq) set_history_from_active(self.quality_combo) hbox.pack_start(self.quality_combo) vbox.pack_start(hbox) # Speed hbox = gtk.HBox(False, 20) hbox.set_spacing(20) self.speed_label = gtk.Label("Speed: ") hbox.pack_start(self.speed_label) self.speed_combo = OptionMenu() def set_min_speed(s): self.config.min_speed = s def set_speed(s): self.config.speed = s def get_min_speed(): return self.config.min_speed def get_speed(): return self.config.speed ss = make_min_auto_menu("Speed", MIN_SPEED_OPTIONS, SPEED_OPTIONS, get_min_speed, get_speed, set_min_speed, set_speed) self.speed_combo.set_menu(ss) set_history_from_active(self.speed_combo) hbox.pack_start(self.speed_combo) vbox.pack_start(hbox) # Username@Host:Port hbox = gtk.HBox(False, 0) hbox.set_spacing(5) self.username_entry = gtk.Entry() self.username_entry.set_max_length(128) self.username_entry.set_width_chars(16) self.username_entry.connect("changed", self.validate) self.username_entry.set_tooltip_text("SSH username") self.username_label = gtk.Label("@") self.host_entry = gtk.Entry() self.host_entry.set_max_length(128) self.host_entry.set_width_chars(24) self.host_entry.connect("changed", self.validate) self.host_entry.set_tooltip_text("hostname") self.ssh_port_entry = gtk.Entry() self.ssh_port_entry.set_max_length(5) self.ssh_port_entry.set_width_chars(5) self.ssh_port_entry.connect("changed", self.validate) self.ssh_port_entry.set_tooltip_text("SSH port") self.port_entry = gtk.Entry() self.port_entry.set_max_length(5) self.port_entry.set_width_chars(5) self.port_entry.connect("changed", self.validate) self.port_entry.set_tooltip_text("port/display") hbox.pack_start(self.username_entry) hbox.pack_start(self.username_label) hbox.pack_start(self.host_entry) hbox.pack_start(self.ssh_port_entry) hbox.pack_start(gtk.Label(":")) hbox.pack_start(self.port_entry) vbox.pack_start(hbox) # Password hbox = gtk.HBox(False, 0) hbox.set_spacing(20) self.password_entry = gtk.Entry() self.password_entry.set_max_length(128) self.password_entry.set_width_chars(30) self.password_entry.set_text("") self.password_entry.set_visibility(False) self.password_entry.connect("changed", self.password_ok) self.password_entry.connect("changed", self.validate) self.password_label = gtk.Label("Password: "******"Save") self.save_btn.set_tooltip_text("Save settings to a session file") self.save_btn.connect("clicked", self.save_clicked) hbox.pack_start(self.save_btn) #Load: self.load_btn = gtk.Button("Load") self.load_btn.set_tooltip_text("Load settings from a session file") self.load_btn.connect("clicked", self.load_clicked) hbox.pack_start(self.load_btn) # Connect button: self.button = gtk.Button("Connect") self.button.connect("clicked", self.connect_clicked) connect_icon = self.get_icon("retry.png") if connect_icon: self.button.set_image(scaled_image(connect_icon, 24)) hbox.pack_start(self.button) def accel_close(*args): gtk.main_quit() add_close_accel(self.window, accel_close) vbox.show_all() self.window.vbox = vbox self.window.add(vbox)
def populate_table(self): log("populate_table: %i records", len(self.records)) if self.table: self.vbox.remove(self.table) self.table = None if not self.records: self.table = gtk.Label("No sessions found") self.vbox.add(self.table) self.table.show() self.set_size_request(440, 200) return self.set_size_request(-1, -1) tb = TableBuilder(1, 6, False) labels = [ gtk.Label(x) for x in ( "Host", "Display", "Name", "Platform", "Type", "URI", "Connect", "Open in Browser", ) ] tb.add_row(*labels) self.table = tb.get_table() self.vbox.add(self.table) self.table.resize(1 + len(self.records), 5) #group them by uuid d = OrderedDict() session_names = {} for i, record in enumerate(self.records): interface, protocol, name, stype, domain, host, address, port, text = record td = typedict(text) log("populate_table: record[%i]=%s", i, record) uuid = td.strget("uuid", "") display = td.strget("display", "") platform = td.strget("platform", "") dtype = td.strget("type", "") if domain == "local" and host.endswith(".local"): host = host[:-len(".local")] key = (uuid, uuid or i, host, display, platform, dtype) log("populate_table: key[%i]=%s", i, key) d.setdefault(key, []).append((interface, protocol, name, stype, domain, host, address, port, text)) #older servers expose the "session-name" as "session": td = typedict(text) session_name = td.strget("name", "") or td.strget("session", "") if session_name: session_names[key] = session_name for key, recs in d.items(): if isinstance(key, tuple): uuid, _, host, display, platform, dtype = key else: display = key uuid, host, platform, dtype = None, None, sys.platform, None title = uuid if display: title = display label = gtk.Label(title) if uuid != title: label.set_tooltip_text(uuid) #try to use an icon for the platform: platform_icon_name = self.get_platform_icon_name(platform) pwidget = None if platform_icon_name: pwidget = scaled_image( self.get_pixbuf("%s.png" % platform_icon_name), 28) if pwidget: pwidget.set_tooltip_text(platform_icon_name) if not pwidget: pwidget = gtk.Label(platform) w, c, b = self.make_connect_widgets(key, recs, address, port, display) session_name = session_names.get(key, "") tb.add_row(gtk.Label(host), label, gtk.Label(session_name), pwidget, gtk.Label(dtype), w, c, b) self.table.show_all()
def create_window(self): self.window = gtk.Window() self.window.connect("destroy", self.destroy) self.window.set_default_size(400, 300) self.window.set_border_width(20) self.window.set_title("Xpra Launcher") self.window.modify_bg(STATE_NORMAL, gdk.Color(red=65535, green=65535, blue=65535)) icon_pixbuf = self.get_icon("xpra.png") if icon_pixbuf: self.window.set_icon(icon_pixbuf) self.window.set_position(WIN_POS_CENTER) vbox = gtk.VBox(False, 0) vbox.set_spacing(15) # Title hbox = gtk.HBox(False, 0) if icon_pixbuf: logo_button = gtk.Button("") settings = logo_button.get_settings() settings.set_property('gtk-button-images', True) logo_button.connect("clicked", about) logo_button.set_tooltip_text("About") image = gtk.Image() image.set_from_pixbuf(icon_pixbuf) logo_button.set_image(image) hbox.pack_start(logo_button, expand=False, fill=False) icon_pixbuf = self.get_icon("bugs.png") self.bug_tool = None if icon_pixbuf: bug_button = gtk.Button("") settings = bug_button.get_settings() settings.set_property('gtk-button-images', True) def bug(*args): if self.bug_tool==None: from xpra.client.gtk_base.bug_report import BugReport self.bug_tool = BugReport() self.bug_tool.init(show_about=False) self.bug_tool.show() bug_button.connect("clicked", bug) bug_button.set_tooltip_text("Bug Report") image = gtk.Image() image.set_from_pixbuf(icon_pixbuf) bug_button.set_image(image) hbox.pack_start(bug_button, expand=False, fill=False) label = gtk.Label("Connect to xpra server") label.modify_font(pango.FontDescription("sans 14")) hbox.pack_start(label, expand=True, fill=True) vbox.pack_start(hbox) # Mode: hbox = gtk.HBox(False, 20) hbox.set_spacing(20) hbox.pack_start(gtk.Label("Mode: ")) self.mode_combo = gtk.combo_box_new_text() #self.mode_combo.get_model().clear() self.mode_combo.append_text("TCP") if "AES" in ENCRYPTION_CIPHERS: self.mode_combo.append_text("TCP + AES") self.mode_combo.append_text("SSH") self.mode_combo.connect("changed", self.mode_changed) hbox.pack_start(self.mode_combo) vbox.pack_start(hbox) self.encoding_combo = None if not PYTHON3: #not implemented for gtk3, where we can't use set_menu()... # Encoding: hbox = gtk.HBox(False, 20) hbox.set_spacing(20) hbox.pack_start(gtk.Label("Encoding: ")) self.encoding_combo = OptionMenu() def get_current_encoding(): return self.config.encoding def set_new_encoding(e): self.config.encoding = e encodings = [x for x in PREFERED_ENCODING_ORDER if x in self.client.get_encodings()] server_encodings = encodings es = make_encodingsmenu(get_current_encoding, set_new_encoding, encodings, server_encodings) self.encoding_combo.set_menu(es) set_history_from_active(self.encoding_combo) hbox.pack_start(self.encoding_combo) vbox.pack_start(hbox) self.encoding_combo.connect("changed", self.encoding_changed) # Quality hbox = gtk.HBox(False, 20) hbox.set_spacing(20) self.quality_label = gtk.Label("Quality: ") hbox.pack_start(self.quality_label) self.quality_combo = OptionMenu() def set_min_quality(q): self.config.min_quality = q def set_quality(q): self.config.quality = q def get_min_quality(): return self.config.min_quality def get_quality(): return self.config.quality sq = make_min_auto_menu("Quality", MIN_QUALITY_OPTIONS, QUALITY_OPTIONS, get_min_quality, get_quality, set_min_quality, set_quality) self.quality_combo.set_menu(sq) set_history_from_active(self.quality_combo) hbox.pack_start(self.quality_combo) vbox.pack_start(hbox) # Speed hbox = gtk.HBox(False, 20) hbox.set_spacing(20) self.speed_label = gtk.Label("Speed: ") hbox.pack_start(self.speed_label) self.speed_combo = OptionMenu() def set_min_speed(s): self.config.min_speed = s def set_speed(s): self.config.speed = s def get_min_speed(): return self.config.min_speed def get_speed(): return self.config.speed ss = make_min_auto_menu("Speed", MIN_SPEED_OPTIONS, SPEED_OPTIONS, get_min_speed, get_speed, set_min_speed, set_speed) self.speed_combo.set_menu(ss) set_history_from_active(self.speed_combo) hbox.pack_start(self.speed_combo) vbox.pack_start(hbox) # Username@Host:Port hbox = gtk.HBox(False, 0) hbox.set_spacing(5) self.username_entry = gtk.Entry() self.username_entry.set_max_length(128) self.username_entry.set_width_chars(16) self.username_entry.connect("changed", self.validate) self.username_entry.set_tooltip_text("SSH username") self.username_label = gtk.Label("@") self.host_entry = gtk.Entry() self.host_entry.set_max_length(128) self.host_entry.set_width_chars(24) self.host_entry.connect("changed", self.validate) self.host_entry.set_tooltip_text("hostname") self.ssh_port_entry = gtk.Entry() self.ssh_port_entry.set_max_length(5) self.ssh_port_entry.set_width_chars(5) self.ssh_port_entry.connect("changed", self.validate) self.ssh_port_entry.set_tooltip_text("SSH port") self.port_entry = gtk.Entry() self.port_entry.set_max_length(5) self.port_entry.set_width_chars(5) self.port_entry.connect("changed", self.validate) self.port_entry.set_tooltip_text("port/display") hbox.pack_start(self.username_entry) hbox.pack_start(self.username_label) hbox.pack_start(self.host_entry) hbox.pack_start(self.ssh_port_entry) hbox.pack_start(gtk.Label(":")) hbox.pack_start(self.port_entry) vbox.pack_start(hbox) # Password hbox = gtk.HBox(False, 0) hbox.set_spacing(20) self.password_entry = gtk.Entry() self.password_entry.set_max_length(128) self.password_entry.set_width_chars(30) self.password_entry.set_text("") self.password_entry.set_visibility(False) self.password_entry.connect("changed", self.password_ok) self.password_entry.connect("changed", self.validate) self.password_label = gtk.Label("Password: "******"Save") self.save_btn.set_tooltip_text("Save settings to a session file") self.save_btn.connect("clicked", self.save_clicked) hbox.pack_start(self.save_btn) #Load: self.load_btn = gtk.Button("Load") self.load_btn.set_tooltip_text("Load settings from a session file") self.load_btn.connect("clicked", self.load_clicked) hbox.pack_start(self.load_btn) # Connect button: self.button = gtk.Button("Connect") self.button.connect("clicked", self.connect_clicked) connect_icon = self.get_icon("retry.png") if connect_icon: self.button.set_image(scaled_image(connect_icon, 24)) hbox.pack_start(self.button) def accel_close(*args): gtk.main_quit() add_close_accel(self.window, accel_close) vbox.show_all() self.window.vbox = vbox self.window.add(vbox)
def do_create_window(self): self.window = Gtk.Window() self.window.set_border_width(20) self.window.connect("delete-event", self.destroy) self.window.set_default_size(400, 260) self.window.set_title("Xpra Launcher") self.window.set_position(Gtk.WindowPosition.CENTER) self.window.set_wmclass("xpra-launcher-gui", "Xpra-Launcher-GUI") add_close_accel(self.window, self.destroy) icon = get_icon_pixbuf("connect.png") if icon: self.window.set_icon(icon) hb = Gtk.HeaderBar() hb.set_show_close_button(True) hb.props.title = "Session Launcher" self.window.set_titlebar(hb) hb.add(self.button("About", "help-about", about)) self.bug_tool = None def bug(*_args): if self.bug_tool is None: from xpra.client.gtk_base.bug_report import BugReport self.bug_tool = BugReport() self.bug_tool.init(show_about=False) self.bug_tool.show() hb.add(self.button("Bug Report", "bugs", bug)) if has_mdns(): self.mdns_gui = None def mdns(*_args): if self.mdns_gui is None: from xpra.client.gtk_base.mdns_gui import mdns_sessions self.mdns_gui = mdns_sessions(self.config) def close_mdns(): self.mdns_gui.destroy() self.mdns_gui = None self.mdns_gui.do_quit = close_mdns else: self.mdns_gui.present() hb.add(self.button("Browse Sessions", "mdns", mdns)) hb.show_all() vbox = Gtk.VBox(False, 0) vbox.set_spacing(15) # Title label = Gtk.Label("Connect to xpra server") label.modify_font(Pango.FontDescription("sans 14")) vbox.pack_start(label) # Mode: hbox = Gtk.HBox(False, 5) self.mode_combo = Gtk.ComboBoxText() for x in self.get_connection_modes(): self.mode_combo.append_text(x.upper()) self.mode_combo.connect("changed", self.mode_changed) hbox.pack_start(Gtk.Label("Mode: "), False, False) hbox.pack_start(self.mode_combo, False, False) align_hbox = Gtk.Alignment(xalign=.5) align_hbox.add(hbox) vbox.pack_start(align_hbox) # Username@Host:Port (ssh -> ssh, proxy) vbox_proxy = Gtk.VBox(False, 15) hbox = Gtk.HBox(False, 5) self.proxy_vbox = vbox_proxy self.proxy_username_entry = Gtk.Entry() self.proxy_username_entry.set_max_length(128) self.proxy_username_entry.set_width_chars(16) self.proxy_username_entry.connect("changed", self.validate) self.proxy_username_entry.connect("activate", self.connect_clicked) self.proxy_username_entry.set_tooltip_text("username") self.proxy_host_entry = Gtk.Entry() self.proxy_host_entry.set_max_length(128) self.proxy_host_entry.set_width_chars(24) self.proxy_host_entry.connect("changed", self.validate) self.proxy_host_entry.connect("activate", self.connect_clicked) self.proxy_host_entry.set_tooltip_text("hostname") self.proxy_port_entry = Gtk.Entry() self.proxy_port_entry.set_max_length(5) self.proxy_port_entry.set_width_chars(5) self.proxy_port_entry.connect("changed", self.validate) self.proxy_port_entry.connect("activate", self.connect_clicked) self.proxy_port_entry.set_tooltip_text("SSH port") hbox.pack_start(Gtk.Label("Proxy: "), False, False) hbox.pack_start(self.proxy_username_entry, True, True) hbox.pack_start(Gtk.Label("@"), False, False) hbox.pack_start(self.proxy_host_entry, True, True) hbox.pack_start(self.proxy_port_entry, False, False) vbox_proxy.pack_start(hbox) # Password hbox = Gtk.HBox(False, 5) self.proxy_password_hbox = hbox self.proxy_password_entry = Gtk.Entry() self.proxy_password_entry.set_max_length(128) self.proxy_password_entry.set_width_chars(30) self.proxy_password_entry.set_text("") self.proxy_password_entry.set_visibility(False) self.proxy_password_entry.connect("changed", self.password_ok) self.proxy_password_entry.connect("changed", self.validate) self.proxy_password_entry.connect("activate", self.connect_clicked) hbox.pack_start(Gtk.Label("Proxy Password"), False, False) hbox.pack_start(self.proxy_password_entry, True, True) vbox_proxy.pack_start(hbox) # Private key hbox = Gtk.HBox(False, 5) self.pkey_hbox = hbox self.proxy_key_label = Gtk.Label("Proxy private key path (PPK):") self.proxy_key_entry = Gtk.Entry() self.proxy_key_browse = Gtk.Button("Browse") self.proxy_key_browse.connect("clicked", self.proxy_key_browse_clicked) hbox.pack_start(self.proxy_key_label, False, False) hbox.pack_start(self.proxy_key_entry, True, True) hbox.pack_start(self.proxy_key_browse, False, False) vbox_proxy.pack_start(hbox) # Check boxes hbox = Gtk.HBox(False, 5) self.check_boxes_hbox = hbox self.password_scb = Gtk.CheckButton("Server password same as proxy") self.password_scb.set_mode(True) self.password_scb.set_active(True) self.password_scb.connect("toggled", self.validate) align_password_scb = Gtk.Alignment(xalign=1.0) align_password_scb.add(self.password_scb) self.username_scb = Gtk.CheckButton("Server username same as proxy") self.username_scb.set_mode(True) self.username_scb.set_active(True) self.username_scb.connect("toggled", self.validate) align_username_scb = Gtk.Alignment(xalign=0.0) align_username_scb.add(self.username_scb) hbox.pack_start(align_username_scb, True, True) hbox.pack_start(align_password_scb, True, True) vbox_proxy.pack_start(hbox) # condiditonal stuff that goes away for "normal" ssh vbox.pack_start(vbox_proxy) # Username@Host:Port (main) hbox = Gtk.HBox(False, 5) self.username_entry = Gtk.Entry() self.username_entry.set_max_length(128) self.username_entry.set_width_chars(16) self.username_entry.connect("changed", self.validate) self.username_entry.connect("activate", self.connect_clicked) self.username_entry.set_tooltip_text("server username") self.host_entry = Gtk.Entry() self.host_entry.set_max_length(128) self.host_entry.set_width_chars(24) self.host_entry.connect("changed", self.validate) self.host_entry.connect("activate", self.connect_clicked) self.host_entry.set_tooltip_text("server hostname or IP address") self.ssh_port_entry = Gtk.Entry() self.ssh_port_entry.set_max_length(5) self.ssh_port_entry.set_width_chars(5) self.ssh_port_entry.connect("changed", self.validate) self.ssh_port_entry.connect("activate", self.connect_clicked) self.ssh_port_entry.set_tooltip_text("SSH port") self.port_entry = Gtk.Entry() self.port_entry.set_max_length(5) self.port_entry.set_width_chars(5) self.port_entry.connect("changed", self.validate) self.port_entry.connect("activate", self.connect_clicked) self.port_entry.set_tooltip_text("port/display") hbox.pack_start(Gtk.Label("Server:"), False, False) hbox.pack_start(self.username_entry, True, True) hbox.pack_start(Gtk.Label("@"), False, False) hbox.pack_start(self.host_entry, True, True) hbox.pack_start(self.ssh_port_entry, False, False) hbox.pack_start(Gtk.Label(":"), False, False) hbox.pack_start(self.port_entry, False, False) vbox.pack_start(hbox) # Password hbox = Gtk.HBox(False, 5) self.password_hbox = hbox self.password_entry = Gtk.Entry() self.password_entry.set_max_length(128) self.password_entry.set_width_chars(30) self.password_entry.set_text("") self.password_entry.set_visibility(False) self.password_entry.connect("changed", self.password_ok) self.password_entry.connect("changed", self.validate) self.password_entry.connect("activate", self.connect_clicked) hbox.pack_start(Gtk.Label("Server Password:"******"Disable Strict Host Key Check") self.nostrict_host_check.set_active(False) al = Gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0.0, yscale=0) al.add(self.nostrict_host_check) hbox.pack_start(al) vbox.pack_start(hbox) # Info Label self.info = Gtk.Label() self.info.set_line_wrap(True) self.info.set_size_request(360, -1) self.info.modify_fg(Gtk.StateType.NORMAL, red) vbox.pack_start(self.info) # Buttons: hbox = Gtk.HBox(False, 20) vbox.pack_start(hbox) #Save: self.save_btn = Gtk.Button("Save") self.save_btn.set_tooltip_text("Save settings to a session file") self.save_btn.connect("clicked", self.save_clicked) hbox.pack_start(self.save_btn) #Load: self.load_btn = Gtk.Button("Load") self.load_btn.set_tooltip_text("Load settings from a session file") self.load_btn.connect("clicked", self.load_clicked) hbox.pack_start(self.load_btn) # Connect button: self.connect_btn = Gtk.Button("Connect") self.connect_btn.connect("clicked", self.connect_clicked) connect_icon = get_icon_pixbuf("retry.png") if connect_icon: self.connect_btn.set_image(scaled_image(connect_icon, 24)) hbox.pack_start(self.connect_btn) vbox.show_all() self.window.vbox = vbox self.window.add(vbox)