예제 #1
0
    def parse_border(self, border_str, extra_args):
        enabled = not border_str.endswith(":off")
        parts = [x.strip() for x in border_str.replace(":off", "").split(",")]
        color_str = parts[0]

        def border_help():
            log.info(" border format: color[,size][:off]")
            log.info("  eg: red,10")
            log.info("  eg: ,5")
            log.info("  eg: auto,5")
            log.info("  eg: blue")

        if color_str.lower() in ("none", "no", "off", "0"):
            return
        if color_str.lower() == "help":
            border_help()
            return
        color_str = color_str.replace(":off", "")
        if color_str == "auto" or color_str == "":
            try:
                try:
                    from hashlib import md5
                except ImportError:
                    from md5 import md5
                m = md5()
                for x in extra_args:
                    m.update(str(x))
                color_str = "#%s" % m.hexdigest()[:6]
                log("border color derived from %s: %s", extra_args, color_str)
            except:
                log.info("failed to derive border color from %s",
                         extra_args,
                         exc_info=True)
                #fail: default to red
                color_str = "red"
        try:
            color = color_parse(color_str)
        except Exception as e:
            log.warn("invalid border color specified: '%s' (%s)", color_str, e)
            border_help()
            color = color_parse("red")
        alpha = 0.6
        size = 4
        if len(parts) == 2:
            size_str = parts[1]
            try:
                size = int(size_str)
            except Exception as e:
                log.warn("invalid size specified: %s (%s)", size_str, e)
            if size <= 0:
                log("border size is %s, disabling it", size)
                return
            if size >= 45:
                log.warn("border size is too high: %s, clipping it", size)
                size = 45
        self.border = WindowBorder(enabled, color.red / 65536.0,
                                   color.green / 65536.0, color.blue / 65536.0,
                                   alpha, size)
        log("parse_border(%s)=%s", border_str, self.border)
예제 #2
0
 def notify_factory():
     color = random.choice(color_combos)
     nid, title, message, actions = messages.pop(0)
     icon = None #random.choice(images)
     notifier.bg_color = color_parse(color[0])
     notifier.fg_color = color_parse(color[1])
     notifier.show_timeout = random.choice((True, False))
     notifier.new_popup(nid, title, message, actions, icon)
     return len(messages)
예제 #3
0
 def notify_factory():
     color = random.choice(color_combos)
     title, message = random.choice(messages)
     icon = None  #random.choice(images)
     notifier.bg_color = color_parse(color[0])
     notifier.fg_color = color_parse(color[1])
     notifier.show_timeout = random.choice((True, False))
     notifier.new_popup(0, title, message, (), icon)
     return True
예제 #4
0
    def __init__(self, options, title="Xpra Session Browser"):
        gtk.Window.__init__(self)
        self.exit_code = 0
        self.set_title(title)
        self.set_border_width(20)
        self.set_resizable(True)
        self.set_decorated(True)
        icon = self.get_pixbuf("xpra")
        if icon:
            self.set_icon(icon)
        add_close_accel(self, self.quit)
        self.connect("delete_event", self.quit)

        self.child_reaper = getChildReaper()

        self.vbox = gtk.VBox(False, 20)
        self.add(self.vbox)

        title_label = gtk.Label(title)
        title_label.modify_font(pango.FontDescription("sans 14"))
        self.vbox.add(title_label)

        self.warning = gtk.Label(" ")
        red = color_parse("red")
        self.warning.modify_fg(STATE_NORMAL, red)
        self.vbox.add(self.warning)

        hbox = gtk.HBox(False, 10)
        al = gtk.Alignment(xalign=1, yalign=0.5)
        al.add(gtk.Label("Password:"******""
        #log.info("options=%s (%s)", options, type(options))
        self.local_info_cache = {}
        self.dotxpra = DotXpra(options.socket_dir, options.socket_dirs,
                               username)
        self.poll_local_sessions()
        glib.timeout_add(5 * 1000, self.poll_local_sessions)
        self.populate_table()

        import signal
        signal.signal(signal.SIGINT, self.app_signal)
        signal.signal(signal.SIGTERM, self.app_signal)
        self.show_all()
예제 #5
0
 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)
예제 #6
0
 def al(label, font="sans 14", xalign=0):
     l = Gtk.Label(label=label)
     l.modify_font(Pango.FontDescription(font))
     if label.startswith("WARNING"):
         red = color_parse("red")
         l.modify_fg(Gtk.StateType.NORMAL, red)
     al = Gtk.Alignment(xalign=xalign, yalign=0.5, xscale=0.0, yscale=0)
     al.add(l)
     al.show_all()
     return al
예제 #7
0
def get_fcolor(encoding):
    color_name = os.environ.get("XPRA_BOX_COLOR_%s" % encoding.upper(), _DEFAULT_BOX_COLORS.get(encoding))
    try:
        c = color_parse(color_name)
    except:
        c = color_parse("black")
    #try and hope this works:
    try:
        return c.red/65536.0, c.green/65536.0, c.blue/65536.0, 0.3
    except:
        pass
    try:
        #it seems that in some GDK versions, we get a return value
        #made of (boolean, GDK.Color), we only want the color..
        c = c[1]
    except:
        log.warn("failed to parse color %s", color_name)
        return 0, 0, 0
    return c.red/65536.0, c.green/65536.0, c.blue/65536.0, 0.3
예제 #8
0
gi.require_version("Gdk", "3.0")
from gi.repository import GLib, Gtk, Gdk, GdkPixbuf

from xpra.os_util import OSX
from xpra.util import u
from xpra.gtk_common.gtk_util import (
    add_close_accel, color_parse,
    get_icon_pixbuf,
    )
from xpra.notifications.notifier_base import NotifierBase, log

DEFAULT_FG_COLOUR = None
DEFAULT_BG_COLOUR = None
if OSX:
    #black on white fits better with osx
    DEFAULT_FG_COLOUR = color_parse("black")
    DEFAULT_BG_COLOUR = color_parse("#f2f2f2")
DEFAULT_WIDTH = 340
DEFAULT_HEIGHT = 100


class GTK_Notifier(NotifierBase):

    def __init__(self, closed_cb=None, action_cb=None, size_x=DEFAULT_WIDTH, size_y=DEFAULT_HEIGHT, timeout=5):
        super().__init__(closed_cb, action_cb)
        self.handles_actions = True
        """
        Create a new notification stack.  The recommended way to create Popup instances.
          Parameters:
            `size_x` : The desired width of the notifications.
            `size_y` : The desired minimum height of the notifications. If the text is
예제 #9
0
                        "mode"              : str,
                        "autoconnect"       : bool,
                        "ssh_port"          : int,
                        }
LAUNCHER_DEFAULTS = {
                        "host"              : "",
                        "port"              : -1,
                        "username"          : get_username(),
                        "password"          : "",
                        "mode"              : "tcp",    #tcp,ssh,..
                        "autoconnect"       : False,
                        "ssh_port"          : 22,
                    }


black   = color_parse("black")
red     = color_parse("red")
white   = color_parse("white")


def get_active_item_index(optionmenu):
    menu = optionmenu.get_menu()
    for i, x in enumerate(menu.get_children()):
        if hasattr(x, "get_active") and x.get_active():
            return i
    return -1

def set_history_from_active(optionmenu):
    #Used for OptionMenu combo:
    #sets the first active menu entry as the "history" value (the selected item)
    i = get_active_item_index(optionmenu)
예제 #10
0
파일: sessions_gui.py 프로젝트: chewi/xpra
    def __init__(self, options, title="Xpra Session Browser"):
        super().__init__()
        self.exit_code = 0
        self.set_title(title)
        self.set_border_width(20)
        self.set_resizable(True)
        self.set_default_size(800, 220)
        self.set_decorated(True)
        self.set_size_request(800, 220)
        self.set_position(Gtk.WindowPosition.CENTER)
        self.set_wmclass("xpra-sessions-gui", "Xpra-Sessions-GUI")
        add_close_accel(self, self.quit)
        self.connect("delete_event", self.quit)
        icon = get_icon_pixbuf("browse.png")
        if icon:
            self.set_icon(icon)

        hb = Gtk.HeaderBar()
        hb.set_show_close_button(True)
        hb.props.title = "Xpra"
        button = Gtk.Button()
        icon = Gio.ThemedIcon(name="help-about")
        image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
        button.add(image)
        button.set_tooltip_text("About")
        button.connect("clicked", self.show_about)
        hb.add(button)
        hb.show_all()
        self.set_titlebar(hb)

        self.clients = {}
        self.clients_disconnecting = set()
        self.child_reaper = getChildReaper()

        self.vbox = Gtk.VBox(False, 20)
        self.add(self.vbox)

        title_label = Gtk.Label(title)
        title_label.modify_font(Pango.FontDescription("sans 14"))
        title_label.show()
        self.vbox.add(title_label)

        self.warning = Gtk.Label(" ")
        red = color_parse("red")
        self.warning.modify_fg(Gtk.StateType.NORMAL, red)
        self.warning.show()
        self.vbox.add(self.warning)

        self.password_box = Gtk.HBox(False, 10)
        self.password_label = Gtk.Label("Password:"******""
        #log.info("options=%s (%s)", options, type(options))
        self.local_info_cache = {}
        self.dotxpra = DotXpra(options.socket_dir, options.socket_dirs, username)
        self.poll_local_sessions()
        self.populate()
        GLib.timeout_add(5*1000, self.update)
        self.vbox.show()
        self.show()