Ejemplo n.º 1
0
def getCurrentMonitor ():
    '''Helper fetching the current monitor of focus'''
    from enso.platform.linux import utils
    display = utils.get_display ()
    input_focus = display.get_input_focus ()
    if input_focus != None and input_focus.focus:
        window = input_focus.focus
        geom = window.get_geometry()
        width = geom.width
        if (width == display.screen().width_in_pixels):
            '''Either a full screen window or desktop.
            We will use mouse coordinates for this'''
            _, x, y, _ = gtk.gdk.display_get_default().get_pointer() 
        else:
            '''A floating window.  We will see which monitor
            the majority of the window is on'''
            root = window.query_tree().root
            trans = root.translate_coords(window, 0, 0)
            x = trans.x + (width / 2)
            y = trans.y        
    else:
        x, y = 0, 0
        print "no focus"
    
    return gtk.gdk.screen_get_default ().get_monitor_at_point(x, y)
def get():
    '''Fetch text from X PRIMARY selection'''
    global selection_text, nautilus_file_selection

    selection_text = None
    clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_PRIMARY)
    clipboard.request_text(get_clipboard_text_cb)
    # Iterate until we actually received something, or we timed out waiting
    start = clock()
    while not selection_text and (clock() - start) < GET_TIMEOUT:
        gtk.main_iteration(False)
    if not selection_text:
        selection_text = ""
    files = []
    # Get file list from Nautilus window (if available)
    focus = get_focused_window(get_display())
    wmclass = focus.get_wm_class()
    if wmclass is None:  # or wmname is None:
        focus = focus.query_tree().parent
        wmclass = focus.get_wm_class()
    #wmname = focus.get_wm_name()
    # print wmclass, wmname
    # TODO: Implement file selection from other Linux file managers
    if nautilus_file_selection and nautilus_file_selection.paths and wmclass[
            0] == 'nautilus':
        files = nautilus_file_selection.paths
    selection = {
        "text": selection_text,
        "files": files,
    }
    return selection
def fake_ctrl_l(display=None):
    '''Fake a "Ctrl+L" keyboard event'''
    if not display:
        display = get_display()
    window = get_focused_window(display)
    state = PASTE_STATE
    k = "^L"
    ctrl = False
    if k.startswith("^"):
        k = k[1:]
        ctrl = True
    keycode = get_keycode(key=k, display=display)
    key = make_key(keycode, state, window, display)
    ctrl_keycode = get_keycode(key="Control_L", display=display)
    ctrl_key = make_key(ctrl_keycode, state, window, display)
    if ctrl:
        Xlib.ext.xtest.fake_input(
            display, Xlib.X.KeyPress, ctrl_keycode
        )  # IGNORE:E1101 @UndefinedVariable Keep PyLint and PyDev happy
    Xlib.ext.xtest.fake_input(
        display, Xlib.X.KeyPress,
        keycode)  # IGNORE:E1101 @UndefinedVariable Keep PyLint and PyDev happy
    Xlib.ext.xtest.fake_input(
        display, Xlib.X.KeyRelease,
        keycode)  # IGNORE:E1101 @UndefinedVariable Keep PyLint and PyDev happy
    if ctrl:
        Xlib.ext.xtest.fake_input(
            display, Xlib.X.KeyRelease, ctrl_keycode
        )  # IGNORE:E1101 @UndefinedVariable Keep PyLint and PyDev happy
    display.sync()
Ejemplo n.º 4
0
def getCurrentMonitor():
    '''Helper fetching the current monitor of focus'''
    from enso.platform.linux import utils
    display = utils.get_display()
    input_focus = display.get_input_focus()
    if input_focus != None and input_focus.focus:
        window = input_focus.focus
        geom = window.get_geometry()
        width = geom.width
        if (width == display.screen().width_in_pixels):
            '''Either a full screen window or desktop.
            We will use mouse coordinates for this'''
            _, x, y, _ = gtk.gdk.display_get_default().get_pointer()
        else:
            '''A floating window.  We will see which monitor
            the majority of the window is on'''
            root = window.query_tree().root
            trans = root.translate_coords(window, 0, 0)
            x = trans.x + (width / 2)
            y = trans.y
    else:
        x, y = 0, 0
        print "no focus"

    return gtk.gdk.screen_get_default().get_monitor_at_point(x, y)
 def _on_selection_change(self, selection, window_id):
     # File selection changed (user clicked on file/directory or selected
     # a group of files/directories.
     # Update internal variable
     try:
         focus = get_focused_window(get_display())
         assert type(
             focus
         ) != int, "focus is not of Window type, it's int and has value of %d" % focus
         if focus.get_wm_class() is None:  # or wmname is None:
             focus = focus.query_tree().parent
         # Capture the file selection from focused window only.
         # Nautilus sends paths of files focused in all opened windows
         # every time the file selection changes in any of them.
         if window_id == focus.id:
             self.paths = filter(
                 None, [File(uri).get_path() for uri in selection])
     except Exception as e:
         logging.error(e)