'macro'에 해당되는 글 2건

  1. 2017.06.22 Python으로 마우스 제어하기
  2. 2011.01.12 간단한 반복 작업 매크로
Coding/Python 삽질기2017. 6. 22. 00:49

# pymove.py


import win32api

import win32con

import sys


mVersion = "V0.627_20170622"


def clickMouseLeft(x,y):

    win32api.SetCursorPos((x,y))

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)


def clickMouseRight(x,y):

    win32api.SetCursorPos((x,y))

    win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,x,y,0,0)

    win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,x,y,0,0)


def moveMouseXY(x,y):

    win32api.SetCursorPos((x,y))



def readDataFile(filename):

    ''' Example of data file

        L 1 2

        R 2 3

        M 3 4

    '''

    with open(filename, 'r') as fp:

        cmdlines = fp.readlines()

    return cmdlines



def parseCommand(cmdlines):

    cmdlist = []

    for c in cmdlines:

        cmd = c.strip().split(" ")

        cmdlist.append(cmd)

    return cmdlist


cmdTable = { 

   'L':clickMouseLeft,

   'R':clickMouseRight,

   'M':moveMouseXY

}


def process(cmdlist):

    for c in cmdlist:

        cmdTable[c[0]](int(c[1]), int(c[2]))


def main(filename):

    cmdlines = readDataFile(filename)

    cmdlist = parseCommand(cmdlines)

    process(cmdlist)


def printHelp():

    print "\n[Help]"

    print "Usage : pymove filename"


if __name__ == '__main__':

    if (len(sys.argv) < 2) or ('-h' in sys.argv[1:]):

        printHelp()

    else:

        main(sys.argv[1])

    print mVersion



'Coding > Python 삽질기' 카테고리의 다른 글

[Python] Thread example  (0) 2017.06.30
Python for Windows Extensions  (0) 2017.06.21
[Python] 진법 변환  (0) 2016.12.27
Posted by chobocho
Coding/Python 삽질기2011. 1. 12. 00:24
#-*- coding: cp949 -*-
# Name        : py_patten.py
# Author      : chobocho.com
# Version     :
# Copyright   :
# Description : simple number change 
#

from Tkinter import *
import tkMessageBox
 
save_file_name = "test.txt"
names = [ 'number1', 'number2' ]
table  = { names[0] : '100', names[1] : '200' } 

text_data = """Trees are  %(number1)s 
won,  %(number2)s won!""" 
 
class App:
    def __init__ (self, master):
    
        self.target_file_name = save_file_name
        
        frame = Frame(master)
        frame.pack()
        
        f3 = Frame(frame, width = 100, height = 40)
        f3.grid(row = 0, column = 0)
        
        self.label_1 = Label(f3, text= names[0])
        self.label_1.grid(row = 0, column = 0, sticky = W) 
        self.input_1 = Entry(f3)
        self.input_1.grid(row = 0, column = 1)

        self.label_2 = Label(f3, text= names[1])
        self.label_2.grid(row = 1, column = 0, sticky = W)
        self.input_2 = Entry(f3)
        self.input_2.grid(row = 1, column = 1)

        # 버튼을 그려주는 부분
        f4 = Frame(frame, width = 100, height = 40)
        f4.grid(row = 1, column = 0)
        

        self.info_button = Button(f4, text="Make", command = self.MakeFile)
        self.info_button.grid(row = 0, column = 0)
        self.info_button = Button(f4, text="Info", command = self.ShowInfo)
        self.info_button.grid(row = 0, column = 1)

    def ShowInfo(self):
        tkMessageBox.showinfo("Information","http://chobocho.com\nVersion 0.2")

    def MakeFile(self):
        self.value1 = self.input_1.get()
        self.value2 = self.input_2.get() 
        
        table[ names[0] ] = self.value1
        table[ names[1] ] = self.value2
        
        self.data = text_data % table

        target = file(self.target_file_name, 'w')
        target.write(self.data)
        target.close()

               
#----------------------------------------------------------
# main
if __name__ == "__main__":      
    root = Tk()
    app = App(root)
    root.mainloop()

'Coding > Python 삽질기' 카테고리의 다른 글

[Python] Undo / Redo 구현하기  (0) 2011.06.16
http://www.pythonchallenge.com...Level6  (0) 2010.12.13
http://www.pythonchallenge.com...Level5  (0) 2010.12.13
Posted by chobocho