Ejemplo n.º 1
0
 def onoffitem(label, active, cb):
     c = CheckMenuItem(label)
     c.set_draw_as_radio(True)
     c.set_active(active)
     set_sensitive(c, True)
     c.connect('activate', self.sound_submenu_activate, menu, cb)
     return c
Ejemplo n.º 2
0
        def set_clipboard_menu(*args):
            clipboard_submenu = gtk.Menu()
            clipboard_menu.set_submenu(clipboard_submenu)
            self.popup_menu_workaround(clipboard_submenu)
            c = self.client
            can_clipboard = c.server_supports_clipboard and c.client_supports_clipboard and c.server_supports_clipboard
            log(
                "set_clipboard_menu(%s) can_clipboard=%s, server=%s, client=%s",
                args, can_clipboard, c.server_supports_clipboard,
                c.client_supports_clipboard)
            clipboard_menu.set_sensitive(can_clipboard)
            LABEL_TO_NAME = {
                "Disabled": None,
                "Clipboard": "CLIPBOARD",
                "Primary": "PRIMARY",
                "Secondary": "SECONDARY"
            }
            from xpra.clipboard.translated_clipboard import TranslatedClipboardProtocolHelper
            for label, remote_clipboard in LABEL_TO_NAME.items():
                clipboard_item = CheckMenuItem(label)

                def remote_clipboard_changed(item):
                    assert can_clipboard
                    item = ensure_item_selected(clipboard_submenu, item)
                    label = item.get_label()
                    remote_clipboard = LABEL_TO_NAME.get(label)
                    old_state = self.client.clipboard_enabled
                    log(
                        "remote_clipboard_changed(%s) remote_clipboard=%s, old_state=%s",
                        item, remote_clipboard, old_state)
                    send_tokens = False
                    if remote_clipboard is not None:
                        #clipboard is not disabled
                        if self.client.clipboard_helper is None:
                            self.client.setup_clipboard_helper(
                                TranslatedClipboardProtocolHelper)
                        self.client.clipboard_helper.remote_clipboard = remote_clipboard
                        send_tokens = True
                        new_state = True
                    else:
                        self.client.clipboard_helper = None
                        send_tokens = False
                        new_state = False
                    log(
                        "remote_clipboard_changed(%s) label=%s, remote_clipboard=%s, old_state=%s, new_state=%s",
                        item, label, remote_clipboard, old_state, new_state)
                    if new_state != old_state:
                        self.client.clipboard_enabled = new_state
                        self.client.emit("clipboard-toggled")
                        send_tokens = True
                    if send_tokens and self.client.clipboard_helper:
                        self.client.clipboard_helper.send_all_tokens()
                active = isinstance(self.client.clipboard_helper, TranslatedClipboardProtocolHelper) \
                            and self.client.clipboard_helper.remote_clipboard==remote_clipboard
                clipboard_item.set_active(active)
                clipboard_item.set_sensitive(can_clipboard)
                clipboard_item.set_draw_as_radio(True)
                clipboard_item.connect("toggled", remote_clipboard_changed)
                clipboard_submenu.append(clipboard_item)
            clipboard_submenu.show_all()
Ejemplo n.º 3
0
 def checkitem(self, title, cb=None):
     """ Utility method for easily creating a CheckMenuItem """
     check_item = CheckMenuItem(title)
     if cb:
         check_item.connect("toggled", cb)
     check_item.show()
     return check_item
Ejemplo n.º 4
0
def populate_encodingsmenu(encodings_submenu, get_current_encoding, set_encoding, encodings, server_encodings):
    encodings_submenu.get_current_encoding = get_current_encoding
    encodings_submenu.set_encoding = set_encoding
    encodings_submenu.encodings = encodings
    encodings_submenu.server_encodings = server_encodings
    encodings_submenu.index_to_encoding = {}
    encodings_submenu.encoding_to_index = {}
    NAME_TO_ENCODING = {}
    for i, encoding in enumerate(encodings):
        name = ENCODINGS_TO_NAME.get(encoding, encoding)
        descr = ENCODINGS_HELP.get(encoding)
        NAME_TO_ENCODING[name] = encoding
        encoding_item = CheckMenuItem(name)
        if descr:
            if encoding not in server_encodings:
                descr += "\n(not available on this server)"
            encoding_item.set_tooltip_text(descr)
        def encoding_changed(item):
            ensure_item_selected(encodings_submenu, item)
            enc = NAME_TO_ENCODING.get(item.get_label())
            log("encoding_changed(%s) enc=%s, current=%s", item, enc, encodings_submenu.get_current_encoding())
            if enc is not None and encodings_submenu.get_current_encoding()!=enc:
                encodings_submenu.set_encoding(enc)
        log("make_encodingsmenu(..) encoding=%s, current=%s, active=%s", encoding, get_current_encoding(), encoding==get_current_encoding())
        encoding_item.set_active(encoding==get_current_encoding())
        sensitive = encoding in server_encodings
        if not sensitive and HIDE_DISABLED_MENU_ENTRIES:
            continue
        set_sensitive(encoding_item, encoding in server_encodings)
        encoding_item.set_draw_as_radio(True)
        encoding_item.connect("toggled", encoding_changed)
        encodings_submenu.append(encoding_item)
        encodings_submenu.index_to_encoding[i] = encoding
        encodings_submenu.encoding_to_index[encoding] = i
    encodings_submenu.show_all()
Ejemplo n.º 5
0
    def make_compressionmenu(self):
        self.compression = self.menuitem("Compression", "compressed.png",
                                         "Network packet compression", None)
        self.compression.set_sensitive(False)
        self.compression_submenu = gtk.Menu()
        self.compression.set_submenu(self.compression_submenu)
        self.popup_menu_workaround(self.compression_submenu)
        compression_options = {0: "None"}

        def set_compression(item):
            item = ensure_item_selected(self.compression_submenu, item)
            c = int(item.get_label().replace("None", "0"))
            if c != self.client.compression_level:
                log("setting compression level to %s", c)
                self.client.set_deflate_level(c)

        for i in range(0, 10):
            c = CheckMenuItem(str(compression_options.get(i, i)))
            c.set_draw_as_radio(True)
            c.set_active(i == self.client.compression_level)
            c.connect('activate', set_compression)
            self.compression_submenu.append(c)

        def enable_compressionmenu(self):
            self.compression.set_sensitive(True)
            self.compression_submenu.show_all()

        self.client.connect("handshake-complete", enable_compressionmenu)
        return self.compression
Ejemplo n.º 6
0
    def make_compressionmenu(self):
        self.compression = self.menuitem("Compression", "compressed.png", "Network packet compression", None)
        self.compression.set_sensitive(False)
        self.compression_submenu = gtk.Menu()
        self.compression.set_submenu(self.compression_submenu)
        self.popup_menu_workaround(self.compression_submenu)
        compression_options = {0: "None"}

        def set_compression(item):
            item = ensure_item_selected(self.compression_submenu, item)
            c = int(item.get_label().replace("None", "0"))
            if c != self.client.compression_level:
                debug("setting compression level to %s", c)
                self.client.set_deflate_level(c)

        for i in range(0, 10):
            c = CheckMenuItem(str(compression_options.get(i, i)))
            c.set_draw_as_radio(True)
            c.set_active(i == self.client.compression_level)
            c.connect("activate", set_compression)
            self.compression_submenu.append(c)

        def enable_compressionmenu(self):
            self.compression.set_sensitive(True)
            self.compression_submenu.show_all()

        self.client.connect("handshake-complete", enable_compressionmenu)
        return self.compression
Ejemplo n.º 7
0
 def checkitem(self, title, cb=None):
     """ Utility method for easily creating a CheckMenuItem """
     check_item = CheckMenuItem(title)
     if cb:
         check_item.connect("toggled", cb)
     check_item.show()
     return check_item
Ejemplo n.º 8
0
 def checkitem(self, title, cb=None, active=False):
     from xpra.gtk_common.gtk_util import CheckMenuItem
     check_item = CheckMenuItem(title)
     check_item.set_active(active)
     if cb:
         check_item.connect("toggled", cb)
     check_item.show()
     return check_item
Ejemplo n.º 9
0
    def add_top_bar_widgets(self, hbox):
        #use an event box so we can style it:
        b = gtk.HBox()
        eb = gtk.EventBox()
        eb.add(b)
        eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(red=0, green=0, blue=0))
        white = gtk.gdk.Color(red=60000, green=63000, blue=65000)
        hbox.pack_start(eb, expand=True, fill=True)
        for i, l in {
                "encoding.png": "Encoding",
                "speed.png": "Speed",
                "information.png": "Information",
                "keyboard.png": "Keyboard",
                "clipboard.png": "Clipboard"
        }.items():
            icon = self._client.get_pixbuf(i)

            def clicked(*args):
                self.info("clicked(%s)", args)

            button = imagebutton(l,
                                 icon,
                                 clicked_callback=clicked,
                                 label_color=white)
            button.set_relief(gtk.RELIEF_NONE)
            b.add(button)
        icon = self._client.get_pixbuf("xpra.png")
        submenu = gtk.Menu()
        for l, a, s, r in (
            ("Check Option 1", True, True, False),
            ("Disabled Option", True, False, False),
            ("Radio 1", True, True, True),
            ("Radio 2", False, True, True),
        ):
            item = CheckMenuItem(l)

            def item_changed(item):
                self.info("item_changed(%s)", item)

            item.set_active(a)
            item.set_sensitive(s)
            item.set_draw_as_radio(r)
            item.connect("toggled", item_changed)
            submenu.append(item)
        submenu.show_all()

        def show_menu(btn, *args):
            self.info("show_menu(%s, %s)", btn, args)
            submenu.popup(None, None, None, 1, 0)

        menu_button = imagebutton("Xpra",
                                  icon,
                                  clicked_callback=show_menu,
                                  label_color=white)
        menu_button.set_relief(gtk.RELIEF_NONE)
        menu_button.show_all()
        b.add(menu_button)
Ejemplo n.º 10
0
 def onoffitem(label, active, cb):
     c = CheckMenuItem(label)
     c.set_draw_as_radio(True)
     c.set_active(active)
     def submenu_uncheck(item, menu):
         if not menu.ignore_events:
             ensure_item_selected(menu, item)
     c.connect('activate', submenu_uncheck, menu)
     def check_enabled(item):
         if not menu.ignore_events and item.get_active():
             cb()
     c.connect('activate', check_enabled)
     return c
Ejemplo n.º 11
0
 def set_clipboard_menu(*args):
     clipboard_submenu = gtk.Menu()
     clipboard_menu.set_submenu(clipboard_submenu)
     self.popup_menu_workaround(clipboard_submenu)
     c = self.client
     can_clipboard = c.server_supports_clipboard and c.client_supports_clipboard and c.server_supports_clipboard
     debug("set_clipboard_menu(%s) can_clipboard=%s, server=%s, client=%s", args, can_clipboard, c.server_supports_clipboard, c.client_supports_clipboard)
     clipboard_menu.set_sensitive(can_clipboard)
     LABEL_TO_NAME = {"Disabled"  : None,
                     "Clipboard" : "CLIPBOARD",
                     "Primary"   : "PRIMARY",
                     "Secondary" : "SECONDARY"}
     from xpra.clipboard.translated_clipboard import TranslatedClipboardProtocolHelper
     for label, remote_clipboard in LABEL_TO_NAME.items():
         clipboard_item = CheckMenuItem(label)
         def remote_clipboard_changed(item):
             assert can_clipboard
             item = ensure_item_selected(clipboard_submenu, item)
             label = item.get_label()
             remote_clipboard = LABEL_TO_NAME.get(label)
             old_state = self.client.clipboard_enabled
             debug("remote_clipboard_changed(%s) remote_clipboard=%s, old_state=%s", item, remote_clipboard, old_state)
             send_tokens = False
             if remote_clipboard is not None:
                 #clipboard is not disabled
                 if self.client.clipboard_helper is None:
                     self.client.setup_clipboard_helper(TranslatedClipboardProtocolHelper)
                 self.client.clipboard_helper.remote_clipboard = remote_clipboard
                 send_tokens = True
                 new_state = True
             else:
                 self.client.clipboard_helper = None
                 send_tokens = False
                 new_state = False
             debug("remote_clipboard_changed(%s) label=%s, remote_clipboard=%s, old_state=%s, new_state=%s",
                      item, label, remote_clipboard, old_state, new_state)
             if new_state!=old_state:
                 self.client.clipboard_enabled = new_state
                 self.client.emit("clipboard-toggled")
                 send_tokens = True
             if send_tokens and self.client.clipboard_helper:
                 self.client.clipboard_helper.send_all_tokens()
         active = isinstance(self.client.clipboard_helper, TranslatedClipboardProtocolHelper) \
                     and self.client.clipboard_helper.remote_clipboard==remote_clipboard
         clipboard_item.set_active(active)
         clipboard_item.set_sensitive(can_clipboard)
         clipboard_item.set_draw_as_radio(True)
         clipboard_item.connect("toggled", remote_clipboard_changed)
         clipboard_submenu.append(clipboard_item)
     clipboard_submenu.show_all()
Ejemplo n.º 12
0
 def scalingitem(scalingvalue=1.0):
     pct = iround(100.0*scalingvalue)
     label = {100 : "None"}.get(pct, "%i%%" % pct)
     c = CheckMenuItem(label)
     c.scalingvalue = scalingvalue
     c.set_draw_as_radio(True)
     c.set_active(scalecmp(scalingvalue))
     def scaling_activated(item):
         if scaling_submenu.updating:
             return
         ensure_item_selected(scaling_submenu, item)
         self.client.scaleset(item.scalingvalue, item.scalingvalue)
     c.connect('activate', scaling_activated)
     return c
Ejemplo n.º 13
0
 def onoffitem(label, active, cb):
     c = CheckMenuItem(label)
     c.set_draw_as_radio(True)
     c.set_active(active)
     def activate_cb(item, *args):
         webcamlog("activate_cb(%s, %s) ignore_events=%s", item, menu, menu.ignore_events)
         if not menu.ignore_events:
             try:
                 menu.ignore_events = True
                 ensure_item_selected(menu, item)
                 cb()
             finally:
                 menu.ignore_events = False
     c.connect("toggled", activate_cb, menu)
     return c
Ejemplo n.º 14
0
def populate_encodingsmenu(encodings_submenu, get_current_encoding, set_encoding, encodings, server_encodings):
    encodings_submenu.get_current_encoding = get_current_encoding
    encodings_submenu.set_encoding = set_encoding
    encodings_submenu.encodings = encodings
    encodings_submenu.server_encodings = server_encodings
    encodings_submenu.index_to_encoding = {}
    encodings_submenu.encoding_to_index = {}
    NAME_TO_ENCODING = {}
    i = 0
    for encoding in encodings:
        name = ENCODINGS_TO_NAME.get(encoding, encoding)
        descr = ENCODINGS_HELP.get(encoding)
        NAME_TO_ENCODING[name] = encoding
        encoding_item = CheckMenuItem(name)
        if descr:
            if encoding not in server_encodings:
                descr += "\n(not available on this server)"
            set_tooltip_text(encoding_item, descr)

        def encoding_changed(oitem):
            debug("encoding_changed(%s)", oitem)
            item = ensure_item_selected(encodings_submenu, oitem)
            enc = NAME_TO_ENCODING.get(item.get_label())
            debug(
                "encoding_changed(%s) item=%s, enc=%s, current=%s",
                oitem,
                item,
                enc,
                encodings_submenu.get_current_encoding(),
            )
            if enc is not None and encodings_submenu.get_current_encoding() != enc:
                encodings_submenu.set_encoding(enc)

        debug(
            "make_encodingsmenu(..) encoding=%s, current=%s, active=%s",
            encoding,
            get_current_encoding(),
            encoding == get_current_encoding(),
        )
        encoding_item.set_active(encoding == get_current_encoding())
        encoding_item.set_sensitive(encoding in server_encodings)
        encoding_item.set_draw_as_radio(True)
        encoding_item.connect("toggled", encoding_changed)
        encodings_submenu.append(encoding_item)
        encodings_submenu.index_to_encoding[i] = encoding
        encodings_submenu.encoding_to_index[encoding] = i
        i += 1
    encodings_submenu.show_all()
Ejemplo n.º 15
0
        def onoffitem(label, active, cb):
            c = CheckMenuItem(label)
            c.set_draw_as_radio(True)
            c.set_active(active)

            def submenu_uncheck(item, menu):
                if not menu.ignore_events:
                    ensure_item_selected(menu, item)

            c.connect('activate', submenu_uncheck, menu)

            def check_enabled(item):
                if not menu.ignore_events and item.get_active():
                    cb()

            c.connect('activate', check_enabled)
            return c
Ejemplo n.º 16
0
def make_encodingsmenu(get_current_encoding, set_encoding, encodings,
                       server_encodings):
    encodings_submenu = gtk.Menu()
    encodings_submenu.get_current_encoding = get_current_encoding
    encodings_submenu.set_encoding = set_encoding
    encodings_submenu.encodings = encodings
    encodings_submenu.server_encodings = server_encodings
    encodings_submenu.index_to_encoding = {}
    encodings_submenu.encoding_to_index = {}
    NAME_TO_ENCODING = {}
    i = 0
    cur = get_current_encoding()
    cur = {"h264": "x264", "vp8": "vpx"}.get(cur, cur)
    for encoding in encodings:
        name = ENCODINGS_TO_NAME.get(encoding, encoding)
        descr = ENCODINGS_HELP.get(encoding)
        NAME_TO_ENCODING[name] = encoding
        encoding_item = CheckMenuItem(name)
        if descr:
            if encoding not in server_encodings:
                descr += "\n(not available on this server)"
            set_tooltip_text(encoding_item, descr)

        def encoding_changed(oitem):
            item = ensure_item_selected(encodings_submenu, oitem)
            enc = NAME_TO_ENCODING.get(item.get_label())
            debug("encoding_changed(%s) item=%s, enc=%s, current=%s", oitem,
                  item, enc, encodings_submenu.get_current_encoding())
            if enc is not None and encodings_submenu.get_current_encoding(
            ) != enc:
                encodings_submenu.set_encoding(enc)

        debug("make_encodingsmenu(..) encoding=%s, current=%s, active=%s",
              encoding, get_current_encoding(),
              encoding == get_current_encoding())
        encoding_item.set_active(encoding == cur)
        encoding_item.set_sensitive(encoding in server_encodings)
        encoding_item.set_draw_as_radio(True)
        encoding_item.connect("toggled", encoding_changed)
        encodings_submenu.append(encoding_item)
        encodings_submenu.index_to_encoding[i] = encoding
        encodings_submenu.encoding_to_index[encoding] = i
        i += 1
    encodings_submenu.show_all()
    return encodings_submenu
Ejemplo n.º 17
0
 def populate_menu(options, value, set_fn):
     found_match = False
     items = {}
     if value and value > 0 and value not in options:
         options[value] = "%s%%" % value
     for s in sorted(options.keys()):
         t = options.get(s)
         qi = CheckMenuItem(t)
         qi.set_draw_as_radio(True)
         candidate_match = s >= max(0, value)
         qi.set_active(not found_match and candidate_match)
         found_match |= candidate_match
         qi.connect('activate', set_fn, submenu)
         if s > 0:
             set_tooltip_text(qi, "%s%%" % s)
         submenu.append(qi)
         items[s] = qi
     return items
Ejemplo n.º 18
0
 def populate_menu(options, value, set_fn):
     found_match = False
     items = {}
     if value and value>0 and value not in options:
         options[value] = "%s%%" % value
     for s in sorted(options.keys()):
         t = options.get(s)
         qi = CheckMenuItem(t)
         qi.set_draw_as_radio(True)
         candidate_match = s>=max(0, value)
         qi.set_active(not found_match and candidate_match)
         found_match |= candidate_match
         qi.connect('activate', set_fn, submenu)
         if s>0:
             set_tooltip_text(qi, "%s%%" % s)
         submenu.append(qi)
         items[s] = qi
     return items
Ejemplo n.º 19
0
 def add_top_bar_widgets(self, hbox):
     #use an event box so we can style it:
     b = gtk.HBox()
     eb = gtk.EventBox()
     eb.add(b)
     eb.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(red=0, green=0, blue=0))
     white = gtk.gdk.Color(red=60000, green=63000, blue=65000)
     hbox.pack_start(eb, expand=True, fill=True)
     for i,l in {"encoding.png"  : "Encoding",
               "speed.png"       : "Speed",
               "information.png" : "Information",
               "keyboard.png"    : "Keyboard",
               "clipboard.png"   : "Clipboard"}.items():
         icon = self._client.get_pixbuf(i)
         def clicked(*args):
             self.info("clicked(%s)", args)
         button = imagebutton(l, icon, clicked_callback=clicked, label_color=white)
         button.set_relief(gtk.RELIEF_NONE)
         b.add(button)
     icon = self._client.get_pixbuf("xpra.png")
     submenu = gtk.Menu()
     for l, a, s, r in (
                        ("Check Option 1", True, True, False),
                        ("Disabled Option", True, False, False),
                        ("Radio 1", True, True, True),
                        ("Radio 2", False, True, True),
                        ):
         item = CheckMenuItem(l)
         def item_changed(item):
             self.info("item_changed(%s)", item)
         item.set_active(a)
         item.set_sensitive(s)
         item.set_draw_as_radio(r)
         item.connect("toggled", item_changed)
         submenu.append(item)
     submenu.show_all()
     def show_menu(btn, *args):
         self.info("show_menu(%s, %s)", btn, args)
         submenu.popup(None, None, None, 1, 0)
     menu_button = imagebutton("Xpra", icon, clicked_callback=show_menu, label_color=white)
     menu_button.set_relief(gtk.RELIEF_NONE)
     menu_button.show_all()
     b.add(menu_button)
Ejemplo n.º 20
0
 def set_clipboard_menu(*args):
     clipboard_submenu = gtk.Menu()
     clipboard_menu.set_submenu(clipboard_submenu)
     self.popup_menu_workaround(clipboard_submenu)
     c = self.client
     can_clipboard = self._can_handle_clipboard()
     clipboardlog("set_clipboard_menu(%s) can_clipboard=%s, server=%s, client=%s", args, can_clipboard, c.server_supports_clipboard, c.client_supports_clipboard)
     set_sensitive(clipboard_menu, can_clipboard)
     for label in CLIPBOARD_LABELS:
         remote_clipboard = CLIPBOARD_LABEL_TO_NAME[label]
         clipboard_item = CheckMenuItem(label)
         ch = self.client.clipboard_helper
         active = bool(ch) and isinstance(ch, TranslatedClipboardProtocolHelper) \
                     and ch.remote_clipboard==remote_clipboard
         clipboard_item.set_active(active)
         set_sensitive(clipboard_item, can_clipboard)
         clipboard_item.set_draw_as_radio(True)
         def remote_clipboard_changed(item):
             self.remote_clipboard_changed(item, clipboard_submenu)
         clipboard_item.connect("toggled", remote_clipboard_changed)
         clipboard_submenu.append(clipboard_item)
     clipboard_submenu.show_all()