ncurses' Dark Devilry

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeremy Moles

    #1

    ncurses' Dark Devilry

    I'm working on a project using ncurses w/ Python. As an aside, I
    implemented addchstr in the cursesmodule.c file in Python SVN, if anyone
    wants me to try and get that made permanent.

    AT ANY RATE...

    I was wondering--and this is more a general curses question rather than
    a Python one, but I know there are some old-timers here who have made
    curses obey before--is there a way to "repaint" a portion of screen
    without stealing the "cursor?" That is:

    I have a focus "wheel" of sorts that allows the user to do input on
    various wigets and windows and whatnot. However, if I want to quickly
    call addstr somewhere else in the application I have to:

    1. Store the YX coords of the cursor currently
    2. Use the cursor in the "current" action
    3. Restore the old cursor location

    I know there are ways around this as I have seen curses apps that, for
    example, have a clock that updates every second without stealing
    "focus."

    I tried implementing/using addchstr (mentioned above) to no success.

    Any ideas? Is this just the plain wrong place to ask this? :)

  • Tony Nelson

    #2
    Re: ncurses' Dark Devilry

    In article <mailman.1336.1 133289146.18701 .python-list@python.org >,
    Jeremy Moles <jeremy@emperor linux.com> wrote:
    [color=blue]
    > I'm working on a project using ncurses w/ Python. As an aside, I
    > implemented addchstr in the cursesmodule.c file in Python SVN, if anyone
    > wants me to try and get that made permanent.
    >
    > AT ANY RATE...
    >
    > I was wondering--and this is more a general curses question rather than
    > a Python one, but I know there are some old-timers here who have made
    > curses obey before--is there a way to "repaint" a portion of screen
    > without stealing the "cursor?" That is:
    >
    > I have a focus "wheel" of sorts that allows the user to do input on
    > various wigets and windows and whatnot. However, if I want to quickly
    > call addstr somewhere else in the application I have to:
    >
    > 1. Store the YX coords of the cursor currently
    > 2. Use the cursor in the "current" action
    > 3. Restore the old cursor location
    >
    > I know there are ways around this as I have seen curses apps that, for
    > example, have a clock that updates every second without stealing
    > "focus."
    >
    > I tried implementing/using addchstr (mentioned above) to no success.
    >
    > Any ideas? Is this just the plain wrong place to ask this? :)[/color]

    I've only tried to read the Python Library Curses docs, but I thought
    that the Window object method addstr() would do what you want.
    _______________ _______________ _______________ _______________ ____________
    TonyN.:' *firstname*nlsn ews@georgea*las tname*.com
    ' <http://www.georgeanels on.com/>

    Comment

    • Jeremy Moles

      #3
      Re: ncurses' Dark Devilry

      On Tue, 2005-11-29 at 20:50 +0000, Tony Nelson wrote:[color=blue]
      > In article <mailman.1336.1 133289146.18701 .python-list@python.org >,
      > Jeremy Moles <jeremy@emperor linux.com> wrote:
      >[color=green]
      > > I'm working on a project using ncurses w/ Python. As an aside, I
      > > implemented addchstr in the cursesmodule.c file in Python SVN, if anyone
      > > wants me to try and get that made permanent.
      > >
      > > AT ANY RATE...
      > >
      > > I was wondering--and this is more a general curses question rather than
      > > a Python one, but I know there are some old-timers here who have made
      > > curses obey before--is there a way to "repaint" a portion of screen
      > > without stealing the "cursor?" That is:
      > >
      > > I have a focus "wheel" of sorts that allows the user to do input on
      > > various wigets and windows and whatnot. However, if I want to quickly
      > > call addstr somewhere else in the application I have to:
      > >
      > > 1. Store the YX coords of the cursor currently
      > > 2. Use the cursor in the "current" action
      > > 3. Restore the old cursor location
      > >
      > > I know there are ways around this as I have seen curses apps that, for
      > > example, have a clock that updates every second without stealing
      > > "focus."
      > >
      > > I tried implementing/using addchstr (mentioned above) to no success.
      > >
      > > Any ideas? Is this just the plain wrong place to ask this? :)[/color]
      >
      > I've only tried to read the Python Library Curses docs, but I thought
      > that the Window object method addstr() would do what you want.[/color]

      Perhaps I should have been more specific. :)

      addstr (or any of it's brothers, even those bound to a subwin instance)
      write values to an internal buffer/object that then gets flipped
      (refreshed()) onto the physical screen.

      However.

      All of the routines I can find in the ncurses library want to take
      control of the "cursor" object. That is: they either want to advance
      it's position (addstr) or not (addchstr), but they both certainly grab
      "control" of it; at least, visually.

      Basically what I'm looking for is a way to refresh a portion of a
      curses-controlled "window" without affecting the current location of the
      cursor or having to manually move it and move it back.

      Comment

      • Christopher Subich

        #4
        Re: ncurses' Dark Devilry

        Jeremy Moles wrote:[color=blue][color=green]
        >>In article <mailman.1336.1 133289146.18701 .python-list@python.org >,
        >> Jeremy Moles <jeremy@emperor linux.com> wrote:[color=darkred]
        >>>I have a focus "wheel" of sorts that allows the user to do input on
        >>>various wigets and windows and whatnot. However, if I want to quickly
        >>>call addstr somewhere else in the application I have to:
        >>>
        >>> 1. Store the YX coords of the cursor currently
        >>> 2. Use the cursor in the "current" action
        >>> 3. Restore the old cursor location
        >>>[/color][/color][/color]
        [color=blue]
        >
        > All of the routines I can find in the ncurses library want to take
        > control of the "cursor" object. That is: they either want to advance
        > it's position (addstr) or not (addchstr), but they both certainly grab
        > "control" of it; at least, visually.
        >
        > Basically what I'm looking for is a way to refresh a portion of a
        > curses-controlled "window" without affecting the current location of the
        > cursor or having to manually move it and move it back.[/color]

        Why not wrap your 1-3 in a function of your own? More generally, build
        a 'cursor location stack', probably using a list. Add utility functions
        push_cur and pop_cur to push and pop the current location of the cursor
        from that stack (pop_cur actually resets the current cursor location for
        future printing). Then your "write over there" becomes:

        push_cur()
        move_cursor(loc ation)
        write(text)
        pop_cur()

        which can be pretty easily wrapped in a single function.

        Mind you, I don't use curses myself, but what would prevent this from
        working?

        Comment

        • Greg Ewing

          #5
          Re: ncurses' Dark Devilry

          Christopher Subich wrote:
          [color=blue]
          > Why not wrap your 1-3 in a function of your own?[/color]

          It sounds like the OP is concerned about the visual effect
          of the cursor moving on the screen while characters are
          written.

          I doubt whether curses provides any way of controlling
          that. Curses was designed for glass ttys, on most of
          which it is physically impossible to write characters
          without the cursor moving. The best you can do is move
          it back to where you want it afterwards.

          --
          Greg Ewing, Computer Science Dept,
          University of Canterbury,
          Christchurch, New Zealand

          Comment

          • Grant Edwards

            #6
            Re: ncurses' Dark Devilry

            On 2005-11-29, Greg Ewing <greg@cosc.cant erbury.ac.nz> wrote:[color=blue]
            > Christopher Subich wrote:
            >[color=green]
            >> Why not wrap your 1-3 in a function of your own?[/color]
            >
            > It sounds like the OP is concerned about the visual effect of
            > the cursor moving on the screen while characters are written.
            >
            > I doubt whether curses provides any way of controlling that.
            > Curses was designed for glass ttys, on most of which it is
            > physically impossible to write characters without the cursor
            > moving. The best you can do is move it back to where you want
            > it afterwards.[/color]

            While you do have to move the cursor to the location where you
            want to write, some terminals allow you to make the cursor
            invisible. This can reduce the visual distraction when you
            need to update something on the screen that isn't where the
            cursor belongs (from the user's point of view).

            --
            Grant Edwards grante Yow! Like I always
            at say -- nothing can beat
            visi.com the BRATWURST here in
            DUSSELDORF!!

            Comment

            • Mike Meyer

              #7
              Re: ncurses' Dark Devilry

              Jeremy Moles <jeremy@emperor linux.com> writes:[color=blue]
              > Basically what I'm looking for is a way to refresh a portion of a
              > curses-controlled "window" without affecting the current location of the
              > cursor or having to manually move it and move it back.[/color]

              Have you looked into using curses window feature?

              <mike
              --
              Mike Meyer <mwm@mired.or g> http://www.mired.org/home/mwm/
              Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

              Comment

              Working...