예제 #1
0
    def __init__(self):
        # Default connection options
        self.config = make_defaults_struct()
        self.config.ssh_port = "22"
        # what we save by default:
        self.config_keys = set(
            [
                "username",
                "password",
                "host",
                "port",
                "mode",
                "ssh_port",
                "encoding",
                "quality",
                "min-quality",
                "speed",
                "min-speed",
            ]
        )
        if is_gtk3():
            self.config.client_toolkit = "gtk3"
        else:
            self.config.client_toolkit = "gtk2"

        def raise_exception(*args):
            raise Exception(*args)

        self.client = make_client(raise_exception, self.config)
        self.client.init(self.config)
        self.exit_code = None
예제 #2
0
    def __init__(self, title="Title", prompt="", info=[], icon="", buttons=[]):
        if is_gtk3():
            self.window = gtk.Window(type=WINDOW_TOPLEVEL)
        else:
            self.window = gtk.Window(WINDOW_TOPLEVEL)
        window_defaults(self.window)
        self.window.set_position(WIN_POS_CENTER)
        self.window.connect("destroy", self.quit)
        self.window.set_default_size(400, 150)
        self.window.set_title(title)
        self.window.set_modal(True)

        if icon:
            icon_pixbuf = self.get_icon(icon)
            if icon_pixbuf:
                self.window.set_icon(icon_pixbuf)

        vbox = gtk.VBox(False, 0)
        vbox.set_spacing(10)

        def al(label, font="sans 14", xalign=0):
            l = gtk.Label(label)
            l.modify_font(pango.FontDescription(font))
            al = gtk.Alignment(xalign=xalign, yalign=0.5, xscale=0.0, yscale=0)
            al.add(l)
            vbox.add(al)

        #window title is visible so this would be redundant:
        #al(title, "sans 18", 0.5)
        al(prompt, "sans 14")
        self.password_input = gtk.Entry()
        self.password_input.set_max_length(255)
        self.password_input.set_width_chars(32)
        self.password_input.connect('activate', self.activate)
        self.password_input.set_visibility(False)
        vbox.add(self.password_input)

        # Buttons:
        self.exit_code = 0
        hbox = gtk.HBox(False, 0)
        al = gtk.Alignment(xalign=1, yalign=0.5, xscale=0, yscale=0)
        al.add(hbox)
        vbox.pack_start(al)
        for label, isdefault, cb in [
            ("Confirm", True, self.activate),
            ("Cancel", False, self.quit),
        ]:
            b = self.btn(label, isdefault, cb)
            hbox.pack_start(b)

        add_close_accel(self.window, self.quit)
        vbox.show_all()
        self.window.add(vbox)
예제 #3
0
    def __init__(self, title="Title", prompt="", info=(), icon="", buttons=()):
        if is_gtk3():
            self.window = gtk.Window(type=WINDOW_POPUP)
        else:
            self.window = gtk.Window(WINDOW_POPUP)
        window_defaults(self.window)
        self.window.set_position(WIN_POS_CENTER)
        self.window.connect("delete-event", self.quit)
        self.window.set_default_size(400, 150)
        self.window.set_title(title)
        #self.window.set_modal(True)

        if icon:
            icon_pixbuf = self.get_icon(icon)
            if icon_pixbuf:
                self.window.set_icon(icon_pixbuf)

        vbox = gtk.VBox(False, 0)
        vbox.set_spacing(10)

        def al(label, font="sans 14", xalign=0):
            l = gtk.Label(label)
            l.modify_font(pango.FontDescription(font))
            if label.startswith("WARNING"):
                red = color_parse("red")
                l.modify_fg(STATE_NORMAL, red)
            al = gtk.Alignment(xalign=xalign, yalign=0.5, xscale=0.0, yscale=0)
            al.add(l)
            vbox.add(al)

        al(title, "sans 18", 0.5)
        al(info, "sans 14")
        al(prompt, "sans 14")

        # Buttons:
        self.exit_code = 0
        if buttons:
            hbox = gtk.HBox(False, 0)
            al = gtk.Alignment(xalign=1, yalign=0.5, xscale=0, yscale=0)
            al.add(hbox)
            vbox.pack_start(al)
            for label, code in buttons:
                b = self.btn(label, "", code)
                hbox.pack_start(b)

        add_close_accel(self.window, self.quit)
        vbox.show_all()
        self.window.add(vbox)
예제 #4
0
def take_png_screenshot(window):
    log("grabbing screenshot")
    w, h = window.get_geometry()[2:4]
    pixbuf = get_pixbuf_from_window(window, 0, 0, w, h)
    buf = []

    def save_to_memory(data, *_args, **_kwargs):
        buf.append(strtobytes(data))
        return True

    if is_gtk3():
        pixbuf.save_to_callbackv(save_to_memory, None, "png", [], [])
    else:
        pixbuf.save_to_callback(save_to_memory, "png", {}, buf)
    rowstride = w * 3
    return w, h, "png", rowstride, b"".join(buf)
예제 #5
0
파일: keymap.py 프로젝트: DiGuoZhiMeng/Xpra
def get_gtk_keymap(ignore_keys=(None, "VoidSymbol", "0xffffff")):
    """
        Augment the keymap we get from gtk.gdk.keymap_get_default()
        by adding the keyval_name.
        We can also ignore some keys
    """
    from xpra.gtk_common.gtk_util import keymap_get_for_display, display_get_default, import_gdk, is_gtk3
    gdk = import_gdk()
    display = display_get_default()
    if not display:
        return ()
    keymap = keymap_get_for_display(display)
    log(
        "keymap_get_for_display(%s)=%s, direction=%s, bidirectional layouts: %s",
        display, keymap, keymap.get_direction(), keymap.have_bidi_layouts())
    keycodes = []
    for i in range(0, 2**8):
        entries = keymap.get_entries_for_keycode(i)
        log("get_entries_for_keycode(%s)=%s", i, entries)
        if not entries:
            continue
        if is_gtk3():
            found, keys, keyvals = entries
            if not found:
                continue
            for j, key in enumerate(keys):
                keyval = keyvals[j]
                keycode = key.keycode
                name = gdk.keyval_name(keyval)
                name = KEY_TRANSLATIONS.get((name, keyval, keycode), name)
                group = key.group or 0
                if name not in ignore_keys:
                    keycodes.append((keyval or 0, name or "", keycode
                                     or 0, group, key.level or 0))
        else:
            #gtk2:
            for keyval, keycode, group, level in entries:
                #assert keycode==i
                name = gdk.keyval_name(keyval)
                name = KEY_TRANSLATIONS.get((name, keyval, keycode), name)
                if name not in ignore_keys:
                    keycodes.append((keyval or 0, name or "", keycode
                                     or 0, group or 0, level or 0))
    log("get_gtk_keymap(%s)=%s (keymap=%s)", ignore_keys, keycodes, keymap)
    return keycodes
예제 #6
0
파일: keymap.py 프로젝트: rudresh2319/Xpra
def get_gtk_keymap(ignore_keys=[None, "VoidSymbol"]):
    """
        Augment the keymap we get from gtk.gdk.keymap_get_default()
        by adding the keyval_name.
        We can also ignore some keys
    """
    from xpra.gtk_common.gtk_util import get_default_keymap, import_gdk, is_gtk3
    gdk = import_gdk()
    keymap = get_default_keymap()
    keycodes = []
    for i in range(0, 2**8):
        entries = keymap.get_entries_for_keycode(i)
        log("%s.get_entries_for_keycode(%s)=%s", keymap, i, entries)
        if not entries:
            continue
        if is_gtk3():
            found, keys, keyvals = entries
            if not found:
                continue
            for i in range(len(keys)):
                key = keys[i]
                keyval = keyvals[i]
                name = gdk.keyval_name(keyval)
                if name not in ignore_keys:
                    keycodes.append((nn(keyval), nn(name), nn(key.keycode),
                                     nn(key.group), nn(key.level)))
        else:
            #gtk2:
            for keyval, keycode, group, level in entries:
                #assert keycode==i
                name = gdk.keyval_name(keyval)
                #ugly workaround for "period" key on win32 (see ticket 588)
                #which is reported as "period" instead of "KP_Decimal",
                #despite being on the numeric keypad just like all the other KP_* keys...
                if name == "period" and keyval == 46 and keycode == 110:
                    name = "KP_Decimal"
                elif name == "dead_tilde" and keyval == 65107 and keycode == 50:
                    name = "asciitilde"
                elif name == "dead_grave" and keyval == 65104 and keycode == 55:
                    name = "grave"
                if name not in ignore_keys:
                    keycodes.append((nn(keyval), nn(name), nn(keycode),
                                     nn(group), nn(level)))
    log("get_gtk_keymap(%s)=%s (keymap=%s)", ignore_keys, keycodes, keymap)
    return keycodes
예제 #7
0
파일: keymap.py 프로젝트: svn2github/Xpra
def get_gtk_keymap(ignore_keys=[None, "VoidSymbol", "0xffffff"]):
    """
        Augment the keymap we get from gtk.gdk.keymap_get_default()
        by adding the keyval_name.
        We can also ignore some keys
    """
    from xpra.gtk_common.gtk_util import get_default_keymap, import_gdk, is_gtk3

    gdk = import_gdk()
    keymap = get_default_keymap()
    log(
        "get_default_keymap()=%s, direction=%s, bidirectional layouts: %s",
        keymap,
        keymap.get_direction(),
        keymap.have_bidi_layouts(),
    )
    keycodes = []
    for i in range(0, 2 ** 8):
        entries = keymap.get_entries_for_keycode(i)
        log("get_entries_for_keycode(%s)=%s", i, entries)
        if not entries:
            continue
        if is_gtk3():
            found, keys, keyvals = entries
            if not found:
                continue
            for i in range(len(keys)):
                key = keys[i]
                keyval = keyvals[i]
                keycode = key.keycode
                name = gdk.keyval_name(keyval)
                name = KEY_TRANSLATIONS.get((name, keyval, keycode), name)
                if name not in ignore_keys:
                    keycodes.append((keyval or 0, name or "", keycode or 0, key.group or 0, key.level or 0))
        else:
            # gtk2:
            for keyval, keycode, group, level in entries:
                # assert keycode==i
                name = gdk.keyval_name(keyval)
                name = KEY_TRANSLATIONS.get((name, keyval, keycode), name)
                if name not in ignore_keys:
                    keycodes.append((keyval or 0, name or "", keycode or 0, group or 0, level or 0))
    log("get_gtk_keymap(%s)=%s (keymap=%s)", ignore_keys, keycodes, keymap)
    return keycodes
예제 #8
0
파일: keymap.py 프로젝트: svn2github/Xpra
def get_gtk_keymap(ignore_keys=[None, "VoidSymbol"]):
    """
        Augment the keymap we get from gtk.gdk.keymap_get_default()
        by adding the keyval_name.
        We can also ignore some keys
    """
    from xpra.gtk_common.gtk_util import get_default_keymap, import_gdk, is_gtk3
    gdk = import_gdk()
    keymap = get_default_keymap()
    keycodes=[]
    for i in range(0, 2**8):
        entries = keymap.get_entries_for_keycode(i)
        log("%s.get_entries_for_keycode(%s)=%s", keymap, i, entries)
        if not entries:
            continue
        if is_gtk3():
            found, keys, keyvals = entries
            if not found:
                continue
            for i in range(len(keys)):
                key = keys[i]
                keyval = keyvals[i]
                name = gdk.keyval_name(keyval)
                if name not in ignore_keys:
                    keycodes.append((nn(keyval), nn(name), nn(key.keycode), nn(key.group), nn(key.level)))
        else:
            #gtk2:
            for keyval, keycode, group, level in entries:
                #assert keycode==i
                name = gdk.keyval_name(keyval)
                #ugly workaround for "period" key on win32 (see ticket 588)
                #which is reported as "period" instead of "KP_Decimal",
                #despite being on the numeric keypad just like all the other KP_* keys...
                if name=="period" and keyval==46 and keycode==110:
                    name = "KP_Decimal"
                elif name=="dead_tilde" and keyval==65107 and keycode==50:
                    name = "asciitilde"
                elif name=="dead_grave" and keyval==65104 and keycode==55:
                    name = "grave"
                if name not in ignore_keys:
                    keycodes.append((nn(keyval), nn(name), nn(keycode), nn(group), nn(level)))
    log("get_gtk_keymap(%s)=%s (keymap=%s)", ignore_keys, keycodes, keymap)
    return keycodes
예제 #9
0
 def    __init__(self):
     # Default connection options
     self.config = make_defaults_struct(extras_defaults=LAUNCHER_DEFAULTS, extras_types=LAUNCHER_OPTION_TYPES, extras_validation=LAUNCHER_VALIDATION)
     #TODO: the fixup does not belong here?
     from xpra.scripts.main import fixup_video_all_or_none, fixup_encodings, fixup_compression, fixup_packetencoding
     fixup_video_all_or_none(self.config)
     fixup_encodings(self.config)
     fixup_compression(self.config)
     fixup_packetencoding(self.config)
     #what we save by default:
     self.config_keys = set(SAVED_FIELDS)
     if is_gtk3():
         self.config.client_toolkit = "gtk3"
     else:
         self.config.client_toolkit = "gtk2"
     def raise_exception(*args):
         raise Exception(*args)
     self.client = make_client(raise_exception, self.config)
     self.client.init(self.config)
     self.exit_code = None
예제 #10
0
    def __init__(self):
        # Default connection options
        self.config = make_defaults_struct()
        self.config.ssh_port = "22"
        #what we save by default:
        self.config_keys = set([
            "username", "password", "host", "port", "mode", "ssh_port",
            "encoding", "quality", "min-quality", "speed", "min-speed"
        ])
        if is_gtk3():
            self.config.client_toolkit = "gtk3"
        else:
            self.config.client_toolkit = "gtk2"

        def raise_exception(*args):
            raise Exception(*args)

        self.client = make_client(raise_exception, self.config)
        self.client.init(self.config)
        self.exit_code = None
예제 #11
0
 def check_support(self, force_enable=False):
     i = self.props
     gdk = import_gdk()
     title = "tmp-opengl-check"
     if is_gtk3():
         attributes = gdk.WindowAttr()
         attributes.width = 1
         attributes.height = 1
         attributes.title = title
         attributes.window_type = gdk.WindowType.TOPLEVEL
         attributes.wclass = gdk.WindowWindowClass.INPUT_OUTPUT
         attributes.event_mask = 0
         attributes_mask = gdk.WindowAttributesType.TITLE | gdk.WindowAttributesType.WMCLASS
         tmp = gdk.Window(None, attributes, attributes_mask)
     else:
         tmp = gdk.Window(None, 1, 1, gdk.WINDOW_TOPLEVEL, 0, gdk.INPUT_OUTPUT, title)
     log("check_support(%s) using temporary window=%s", force_enable, tmp)
     with self.get_paint_context(tmp):
         i.update(check_PyOpenGL_support(force_enable))
     tmp.destroy()
     return i
예제 #12
0
파일: keymap.py 프로젝트: rudresh2319/Xpra
def get_gtk_keymap(ignore_keys=[None, "VoidSymbol", "0xffffff"]):
    """
        Augment the keymap we get from gtk.gdk.keymap_get_default()
        by adding the keyval_name.
        We can also ignore some keys
    """
    from xpra.gtk_common.gtk_util import get_default_keymap, import_gdk, is_gtk3
    gdk = import_gdk()
    keymap = get_default_keymap()
    keycodes = []
    for i in range(0, 2**8):
        entries = keymap.get_entries_for_keycode(i)
        log("%s.get_entries_for_keycode(%s)=%s", keymap, i, entries)
        if not entries:
            continue
        if is_gtk3():
            found, keys, keyvals = entries
            if not found:
                continue
            for i in range(len(keys)):
                key = keys[i]
                keyval = keyvals[i]
                keycode = key.keycode
                name = gdk.keyval_name(keyval)
                name = KEY_TRANSLATIONS.get((name, keyval, keycode), name)
                if name not in ignore_keys:
                    keycodes.append((keyval or 0, name or "", keycode
                                     or 0, key.group or 0, key.level or 0))
        else:
            #gtk2:
            for keyval, keycode, group, level in entries:
                #assert keycode==i
                name = gdk.keyval_name(keyval)
                name = KEY_TRANSLATIONS.get((name, keyval, keycode), name)
                if name not in ignore_keys:
                    keycodes.append((keyval or 0, name or "", keycode
                                     or 0, group or 0, level or 0))
    log("get_gtk_keymap(%s)=%s (keymap=%s)", ignore_keys, keycodes, keymap)
    return keycodes
예제 #13
0
 def get_info(self, proto, *_args):
     info = X11ServerCore.get_info(self, proto)
     info.setdefault("features", {})["shadow"] = True
     info.setdefault(
         "server", {})["type"] = "Python/gtk%i/x11-shadow" % (2 + is_gtk3())
     return info