Exemplo n.º 1
0
def _show_windows(handles, command, redraw_now=False):
    """Sets the specified window's show state.

    Parameters
    ----------
    handles: list of window handles
    command: one of following commands:
    SW_FORCEMINIMIZE:
        Minimizes a window, even if the thread that owns the window is not
        responding. This flag should only be used when minimizing windows
        from a different thread.
    SW_HIDE:
        Hides the window and activates another window.
    SW_MAXIMIZE:
        Maximizes the specified window.
    SW_MINIMIZE:
        Minimizes the specified window and activates the next top-level window
        in the Z order.
    SW_RESTORE:
        Activates and displays the window. If the window is minimized or
        maximized, the system restores it to its original size and position.
        An application should specify this flag when restoring a minimized
                    window.
    SW_SHOW:
        Activates the window and displays it in its current size and position.
    SW_SHOWDEFAULT:
        Sets the show state based on the SW_ value specified in the STARTUPINFO
        structure passed to the CreateProcess function by the program that
        started the application.
    SW_SHOWMAXIMIZED:
        Activates the window and displays it as a maximized window.
    SW_SHOWMINIMIZED:
        Activates the window and displays it as a minimized window.
    SW_SHOWMINNOACTIVE:
        Displays the window as a minimized window. This value is similar to
        SW_SHOWMINIMIZED, except the window is not activated.
    SW_SHOWNA:
        Displays the window in its current size and position. This value is
        similar to SW_SHOW, except the window is not activated.
    SW_SHOWNOACTIVATE:
        Displays a window in its most recent size and position. This value is
        similar to SW_SHOWNORMAL, except the window is not actived.
    SW_SHOWNORMAL:
        Activates and displays a window. If the window is minimized or
        maximized, the system restores it to its original size and position.
        An application should specify this flag when displaying the window for
        the first time.

    redraw_now :

    """
    # pylint: disable=no-member
    for handle in handles:
        if not handle == 0:
            BringWindowToTop(handle)
            ShowWindow(handle, command)
            if redraw_now:
                rect = GetWindowRect(handle)
                win32gui.RedrawWindow(handle, rect, None,
                                      win32con.RDW_UPDATENOW)
Exemplo n.º 2
0
def _show_figure(figure_numbers, command):
    """Sets the specified figure's show state.

    Parameters
    ----------
    figure_numbers: list of figure numbers
    command: one of following commands:
    SW_FORCEMINIMIZE:
        Minimizes a window, even if the thread that owns the window is not
        responding. This flag should only be used when minimizing windows
        from a different thread.
    SW_HIDE:
        Hides the window and activates another window.
    SW_MAXIMIZE:
        Maximizes the specified window.
    SW_MINIMIZE:
        Minimizes the specified window and activates the next top-level window
        in the Z order.
    SW_RESTORE:
        Activates and displays the window. If the window is minimized or
        maximized, the system restores it to its original size and position.
        An application should specify this flag when restoring a minimized
        window.
    SW_SHOW:
        Activates the window and displays it in its current size and position.
    SW_SHOWDEFAULT:
        Sets the show state based on the SW_ value specified in the STARTUPINFO
        structure passed to the CreateProcess function by the program that
        started the application.
    SW_SHOWMAXIMIZED:
        Activates the window and displays it as a maximized window.
    SW_SHOWMINIMIZED:
        Activates the window and displays it as a minimized window.
    SW_SHOWMINNOACTIVE:
        Displays the window as a minimized window. This value is similar to
        SW_SHOWMINIMIZED, except the window is not activated.
    SW_SHOWNA:
        Displays the window in its current size and position. This value is
        similar to SW_SHOW, except the window is not activated.
    SW_SHOWNOACTIVATE:
        Displays a window in its most recent size and position. This value is
        similar to SW_SHOWNORMAL, except the window is not actived.
    SW_SHOWNORMAL:
        Activates and displays a window. If the window is minimized or
        maximized, the system restores it to its original size and position.
        An application should specify this flag when displaying the window for
        the first time.

    """
    for number in _parse_figure_numbers(*figure_numbers):
        for format_ in FIGURE_TITLE_FORMATS:
            title = format_ + ' %d' % number
            handle = FindWindow(None, title)
            if not handle == 0:
                BringWindowToTop(handle)
                ShowWindow(handle, command)
Exemplo n.º 3
0
def stack(*figure_numbers, **kwds):
    """Stack figure windows.

    Parameters
    ----------
    figure_numbers : list of integers or string
        specifying which figures to stack (default 'all').
    kwds : dict with the following keys
        figs_per_stack :
            number of figures per stack (default depends on screenheight)

    Description
    -----------
       STACK stacks all open figure windows on top of eachother
       with maximum overlap. STACK(FIGS) can be used to specify which
       figures that should be stacked. Figures are not sorted when specified.

     Example:
     --------
     >>> import pylab as p
     >>> import wafo.fig as fig
     >>> for ix in range(7):
     ...     f = p.figure(ix)
     >>> fig.stack()                # stack all open figures
     >>> fig.stack(range(1,4), 5, 7)  # stack figure 1,2,3,5 and 7
     >>> fig.close()

     See also
     --------
      fig.cycle, fig.keep, fig.maximize, fig.restore,
             fig.pile, fig.tile

    """
    wnds = find_figure_handles(*figure_numbers)
    numfigs = len(wnds)
    if numfigs > 0:
        screenpos = get_screen_position_and_size(wnds)
        y_step = 25
        x_step = border = 5

        figs_per_stack = kwds.get(
            'figs_per_stack',
            int(numpy.fix(0.7 * (screenpos[3] - border) / y_step)))

        for iy in range(numfigs):
            pos = get_window_position_and_size(wnds[iy])
            # print('[x, y, w, h] = ', pos)
            ix = iy % figs_per_stack
            ypos = int(screenpos[1] + ix * y_step + border)
            xpos = int(screenpos[0] + ix * x_step + border)
            MoveWindow(wnds[iy], xpos, ypos, pos[2], pos[3], 1)
            BringWindowToTop(wnds[iy])
Exemplo n.º 4
0
def set_size(*figure_numbers, **kwds):
    """Set size for figure windows.

    Parameters
    ----------
    figure_numbers : list of integers or string
        specifying which figures to pile (default 'all').
    kwds : dict with the following keys
        width  :
        height :

    Description
    -------------
    Set size sets the size of all open figure windows. SET_SIZE(FIGS)
    can be used to specify which figures that should be resized.
    Figures are not sorted when specified.

     Example:
     --------
     >>> import pylab as p
     >>> import fig
     >>> for ix in range(7):
     ...     f = p.figure(ix)
     >>> fig.set_size(7, width=150, height=100)
     >>> fig.set_size(range(1,4), 5,width=250, height=170)
     >>> fig.close()

     See also
     --------
     fig.cycle, fig.keep, fig.maximize, fig.restore,
             fig.stack, fig.tile

    """
    handles = find_figure_handles(*figure_numbers)
    numfigs = len(handles)
    if numfigs > 0:
        screen_width, screen_height = _get_screen_size(handles)
        width = kwds.get('width', int(screen_width / 2.5))
        height = kwds.get('height', int(screen_height / 2))
        new_pos = kwds.get('position', None)
        pos = new_pos
        for handle in handles:
            if not new_pos:
                pos = get_window_position_and_size(handle)
            MoveWindow(handle, pos[0], pos[1], width, height, 1)
            BringWindowToTop(handle)
Exemplo n.º 5
0
def pile(*figure_numbers, **kwds):
    """Pile figure windows.

    Parameters
    ----------
    figure_numbers : list of integers or string
        specifying which figures to pile (default 'all').
    kwds : dict with the following keys
        position :
        width  :
        height :

    Description
    -------------
       PILE piles all open figure windows on top of eachother
       with complete overlap. PILE(FIGS) can be used to specify which
       figures that should be piled. Figures are not sorted when specified.

     Example:
     --------
     >>> import pylab as p
     >>> import wafo.fig as fig
     >>> for ix in range(7):
     ...     f = p.figure(ix)
     >>> fig.pile()                # pile all open figures
     >>> fig.pile(range(1,4), 5, 7)  # pile figure 1,2,3,5 and 7
     >>> fig.close()

     See also
     --------
     fig.cycle, fig.keep, fig.maximize, fig.restore,
             fig.stack, fig.tile

    """
    wnds = find_figure_handles(*figure_numbers)
    numfigs = len(wnds)
    if numfigs > 0:
        screen_width, screen_height = _get_screen_size(wnds)
        pos = kwds.get(
            'position', (int(screen_width / 5), int(screen_height / 4)))
        width = kwds.get('width', int(screen_width / 2.5))
        height = kwds.get('height', int(screen_height / 2))

        for wnd in wnds:
            MoveWindow(wnd, pos[0], pos[1], width, height, 1)
            BringWindowToTop(wnd)
Exemplo n.º 6
0
def tile(*figure_numbers, **kwds):
    """Tile figure windows.

    Parameters
    ----------
    figure_numbers : list of integers or string
        specifying which figures to tile (default 'all').
    kwds : dict with key pairs
        specifying how many pairs of figures that are tiled at a time

    Description
    -----------
       TILE places all open figure windows around on the screen with no
       overlap. TILE(FIGS) can be used to specify which figures that
       should be tiled. Figures are not sorted when specified.

     Example:
     --------
     >>> import pylab as p
     >>> import wafo.fig as fig
     >>> for ix in range(7):
     ...     f = p.figure(ix)
     >>> fig.tile()             # tile all open figures
     >>> fig.tile( range(1,4), 5, 7)    # tile figure 1,2,3,5 and 7
     >>> fig.tile(range(1,11), pairs=2) # tile figure 1 to 10 two at a time
     >>> fig.tile(range(1,11), pairs=3) # tile figure 1 to 10 three at a time
     >>> fig.close()

     See also
     --------
     fig.cycle, fig.keep, fig.maximize, fig.minimize
     fig.restore, fig.pile, fig.stack

    """
    wnds = find_figure_handles(*figure_numbers)

    nfigs = len(wnds)
    # Number of windows.

    if nfigs > 0:
        nfigspertile = kwds.get('pairs', nfigs)

        ceil = numpy.ceil
        sqrt = numpy.sqrt
        maximum = numpy.maximum

        nlayers = int(ceil(nfigs / nfigspertile))

        # Number of figures horisontally.
        nh = maximum(int(ceil(sqrt(nfigspertile))), 2)
        # Number of figures vertically.
        nv = maximum(int(ceil(nfigspertile / nh)), 2)

        screenpos = get_screen_position_and_size(wnds)
        screen_width, screen_heigth = screenpos[2:4]

        hspc = 10            # Horisontal space.
        topspc = 20            # Space above top figure.
        medspc = 10            # Space between figures.
        botspc = 20            # Space below bottom figure.

        figwid = (screen_width - (nh + 1) * hspc) / nh
        fighgt = (screen_heigth - (topspc + botspc) - (nv - 1) * medspc) / nv

        figwid = int(numpy.round(figwid))
        fighgt = int(numpy.round(fighgt))

        idx = 0
        for unused_ix in range(nlayers):
            for row in range(nv):
                figtop = int(screenpos[1] + topspc + row * (fighgt + medspc))
                for col in range(nh):
                    if (row) * nh + col < nfigspertile:
                        if idx < nfigs:
                            figlft = int(
                                screenpos[0] + (col + 1) * hspc + col * figwid)
                            fighnd = wnds[idx]
                            MoveWindow(fighnd, figlft, figtop, figwid, fighgt,
                                       1)
                            # Set position.
                            BringWindowToTop(fighnd)
                        idx += 1