Cursor Position.

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

    #1

    Cursor Position.

    Looking at the goto(xy) thread.
    Is there a way to get the X,Y position from a cursor click and then use the
    position to apply something like a water mark on an image at that position?
    Thanks,


  • Fredrik Lundh

    #2
    Re: Cursor Position.

    "Samantha" <samantha7395@h otmail.com> wrote:
    [color=blue]
    > Looking at the goto(xy) thread.
    > Is there a way to get the X,Y position from a cursor click and then use the
    > position to apply something like a water mark on an image at that position?[/color]

    All GUI toolkits can handle the "click here" part. Which one are you using ?

    to apply water marks, use PIL:

    http://www.pythonware.com/products/pil

    </F>



    Comment

    • Samantha

      #3
      Re: Cursor Position.

      I will be using Tkinter. All I need is a way to get the X,Y position from a
      mouse click. I am trying to have an image loaded to click on, but that seems
      to be a problem. So if I can just get the position from the screen of a
      graphics program, showing an image, it will work for me.
      S
      "Fredrik Lundh" <fredrik@python ware.com> wrote in message
      news:mailman.33 2.1131519776.18 701.python-list@python.org ...[color=blue]
      > "Samantha" <samantha7395@h otmail.com> wrote:
      >[color=green]
      >> Looking at the goto(xy) thread.
      >> Is there a way to get the X,Y position from a cursor click and then use
      >> the
      >> position to apply something like a water mark on an image at that
      >> position?[/color]
      >
      > All GUI toolkits can handle the "click here" part. Which one are you
      > using ?
      >
      > to apply water marks, use PIL:
      >
      > http://www.pythonware.com/products/pil
      >
      > </F>
      >
      >
      >[/color]


      Comment

      • Dennis Lee Bieber

        #4
        Re: Cursor Position.

        On Tue, 8 Nov 2005 22:07:00 -0800, "Samantha" <samantha7395@h otmail.com>
        declaimed the following in comp.lang.pytho n:
        [color=blue]
        > Looking at the goto(xy) thread.
        > Is there a way to get the X,Y position from a cursor click and then use the
        > position to apply something like a water mark on an image at that position?
        > Thanks,
        >[/color]
        The gotoXY subject is in reference to a TEXT-only console (a command
        line)...

        If you are manipulating images, you're in GUI environment. So far as
        I know, practically all GUI toolkits have some means of tracking mouse
        movements... Look for a mouse-button-down/up event.
        --[color=blue]
        > =============== =============== =============== =============== == <
        > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
        > wulfraed@dm.net | Bestiaria Support Staff <
        > =============== =============== =============== =============== == <
        > Home Page: <http://www.dm.net/~wulfraed/> <
        > Overflow Page: <http://wlfraed.home.ne tcom.com/> <[/color]

        Comment

        • Juho Schultz

          #5
          Re: Cursor Position.

          Samantha wrote:[color=blue]
          > I will be using Tkinter. All I need is a way to get the X,Y position from a
          > mouse click. I am trying to have an image loaded to click on, but that seems
          > to be a problem. So if I can just get the position from the screen of a
          > graphics program, showing an image, it will work for me.
          > S[/color]

          If you use TkInter, use also these:
          http://www.pythonware.com/library/tk...tion/index.htm


          For mouse click position, this might be helpful:
          http://www.pythonware.com/library/tk...d-bindings.htm

          Comment

          • Diez B. Roggisch

            #6
            Re: Cursor Position.

            Samantha wrote:[color=blue]
            > I will be using Tkinter. All I need is a way to get the X,Y position from a
            > mouse click. I am trying to have an image loaded to click on, but that seems
            > to be a problem. So if I can just get the position from the screen of a
            > graphics program, showing an image, it will work for me.[/color]

            Won't be easy - a toolkit (like tkinter) will only cpature your mous
            events that are directed towards it's own windows. You might be able to
            convince your program to collect mouse-events outside for a short period
            of time - like snapshot programs do - but that will reqiure pretty
            complicated, OS-dependant coding. Certainly way more complicated than
            loading an image using tkinter. Better tell us what's giving you a hard
            time there.

            Diez

            Comment

            • Samantha

              #7
              Re: Cursor Position.

              Diez,[color=blue]
              > Won't be easy - a toolkit (like tkinter) will only capture your mouse
              > events that are directed towards it's own windows.[/color]

              That is my exact problem. I want to have the mouse event captured from
              another application window. In this case an image window opened in Paint
              Shop Pro that by the way uses Python to make scripts. I would like to be
              able to click on the image and get the X,Y positions. I have been able to
              get the X,Y from Tkinter own window as you say. Once I have those positions
              I can use them in a Paint Shop Pro script.
              Thanks for your reply. Do you have any advise as to how I can do what I am
              trying or is it, in a practical matter, impossible.
              S

              "Diez B. Roggisch" <deets@nospam.w eb.de> wrote in message
              news:3tds08Fsb3 p1U1@uni-berlin.de...[color=blue]
              > Samantha wrote:[color=green]
              >> I will be using Tkinter. All I need is a way to get the X,Y position from
              >> a mouse click. I am trying to have an image loaded to click on, but that
              >> seems to be a problem. So if I can just get the position from the screen
              >> of a graphics program, showing an image, it will work for me.[/color]
              >
              > Won't be easy - a toolkit (like tkinter) will only cpature your mous
              > events that are directed towards it's own windows. You might be able to
              > convince your program to collect mouse-events outside for a short period
              > of time - like snapshot programs do - but that will reqiure pretty
              > complicated, OS-dependant coding. Certainly way more complicated than
              > loading an image using tkinter. Better tell us what's giving you a hard
              > time there.
              >
              > Diez[/color]


              Comment

              • Diez B. Roggisch

                #8
                Re: Cursor Position.

                > That is my exact problem. I want to have the mouse event captured from[color=blue]
                > another application window. In this case an image window opened in Paint
                > Shop Pro that by the way uses Python to make scripts. I would like to be
                > able to click on the image and get the X,Y positions. I have been able to
                > get the X,Y from Tkinter own window as you say. Once I have those positions
                > I can use them in a Paint Shop Pro script.
                > Thanks for your reply. Do you have any advise as to how I can do what I am
                > trying or is it, in a practical matter, impossible.[/color]

                As I said - it certainly is doable. But I fear not in tkinter "as is"
                (you can use tk still for your _own_ gui), and not without deeper
                knowledge of the windows event system. Then mark hammond's win32
                extensions are a starting point. And you should search for example code
                on MSDN or something like that (obviously _not_ in python), to get a
                starting point.

                Regards,

                Diez

                Comment

                • snoe

                  #9
                  Re: Cursor Position.

                  This script should be a good start:
                  from ctypes import *
                  import time

                  PUL = POINTER(c_ulong )
                  class KeyBdInput(Stru cture):
                  _fields_ = [("wVk", c_ushort),
                  ("wScan", c_ushort),
                  ("dwFlags", c_ulong),
                  ("time", c_ulong),
                  ("dwExtraInf o", PUL)]

                  class HardwareInput(S tructure):
                  _fields_ = [("uMsg", c_ulong),
                  ("wParamL", c_short),
                  ("wParamH", c_ushort)]

                  class MouseInput(Stru cture):
                  _fields_ = [("dx", c_long),
                  ("dy", c_long),
                  ("mouseData" , c_ulong),
                  ("dwFlags", c_ulong),
                  ("time",c_ulong ),
                  ("dwExtraInf o", PUL)]

                  class Input_I(Union):
                  _fields_ = [("ki", KeyBdInput),
                  ("mi", MouseInput),
                  ("hi", HardwareInput)]

                  class Input(Structure ):
                  _fields_ = [("type", c_ulong),
                  ("ii", Input_I)]

                  class POINT(Structure ):
                  _fields_ = [("x", c_ulong),
                  ("y", c_ulong)]

                  def Click(x,y):

                  orig = POINT()

                  windll.user32.G etCursorPos(byr ef(orig))

                  windll.user32.S etCursorPos(x,y )

                  FInputs = Input * 2
                  extra = c_ulong(0)

                  ii_ = Input_I()
                  ii_.mi = MouseInput( 0, 0, 0, 2, 0, pointer(extra) )

                  ii2_ = Input_I()
                  ii2_.mi = MouseInput( 0, 0, 0, 4, 0, pointer(extra) )

                  x = FInputs( ( 0, ii_ ), ( 0, ii2_ ) )

                  windll.user32.S endInput(2, pointer(x), sizeof(x[0]))

                  return orig.x, orig.y

                  Comment

                  • snoe

                    #10
                    Re: Cursor Position.

                    This script should be a good start:
                    from ctypes import *
                    import time

                    PUL = POINTER(c_ulong )
                    class KeyBdInput(Stru cture):
                    _fields_ = [("wVk", c_ushort),
                    ("wScan", c_ushort),
                    ("dwFlags", c_ulong),
                    ("time", c_ulong),
                    ("dwExtraInf o", PUL)]

                    class HardwareInput(S tructure):
                    _fields_ = [("uMsg", c_ulong),
                    ("wParamL", c_short),
                    ("wParamH", c_ushort)]

                    class MouseInput(Stru cture):
                    _fields_ = [("dx", c_long),
                    ("dy", c_long),
                    ("mouseData" , c_ulong),
                    ("dwFlags", c_ulong),
                    ("time",c_ulong ),
                    ("dwExtraInf o", PUL)]

                    class Input_I(Union):
                    _fields_ = [("ki", KeyBdInput),
                    ("mi", MouseInput),
                    ("hi", HardwareInput)]

                    class Input(Structure ):
                    _fields_ = [("type", c_ulong),
                    ("ii", Input_I)]

                    class POINT(Structure ):
                    _fields_ = [("x", c_ulong),
                    ("y", c_ulong)]

                    def Click(x,y):

                    orig = POINT()

                    windll.user32.G etCursorPos(byr ef(orig))

                    windll.user32.S etCursorPos(x,y )

                    FInputs = Input * 2
                    extra = c_ulong(0)

                    ii_ = Input_I()
                    ii_.mi = MouseInput( 0, 0, 0, 2, 0, pointer(extra) )

                    ii2_ = Input_I()
                    ii2_.mi = MouseInput( 0, 0, 0, 4, 0, pointer(extra) )

                    x = FInputs( ( 0, ii_ ), ( 0, ii2_ ) )

                    windll.user32.S endInput(2, pointer(x), sizeof(x[0]))

                    return orig.x, orig.y

                    Comment

                    Working...