case1.画图工具简单练习

#_*_coding=utf-8_*_
import time
from pprint import pprint
import logging
from logging import handlers
#from pywinauto import actionlogger
from pywinauto import Application
# import argparse
# parser = argparse.ArgumentParser()
# parser.add_argument("--log", help = "enable logging", type=str, required = False)
# args = parser.parse_args() class Logger(object):
level_relations = {
'debug':logging.DEBUG,
'info':logging.INFO,
'warning':logging.WARNING,
'error':logging.ERROR,
'crit':logging.CRITICAL
}#日志级别关系映射 def __init__(self,logname,filename,level='info',when='D',backCount=3,fmt='%(asctime)s - %(name)s - %(levelname)s - %(message)s'):
self.logger = logging.getLogger(logname)
format_str = logging.Formatter(fmt)#设置日志格式
self.logger.setLevel(self.level_relations.get(level))#设置日志级别
sh = logging.StreamHandler()#往屏幕上输出
sh.setFormatter(format_str) #设置屏幕上显示的格式
th = handlers.TimedRotatingFileHandler(filename=filename,when=when,backupCount=backCount,encoding='utf-8')#往文件里写入#指定间隔时间自动生成文件的处理器
#实例化TimedRotatingFileHandler
#interval是时间间隔,backupCount是备份文件的个数,如果超过这个个数,就会自动删除,when是间隔的时间单位,单位有以下几种:
# S 秒
# M 分
# H 小时、
# D 天、
# W 每星期(interval==0时代表星期一)
# midnight 每天凌晨
th.setFormatter(format_str)#设置文件里写入的格式
self.logger.addHandler(sh) #把对象加到logger里
self.logger.addHandler(th) log=Logger(logname='pywinauto',filename='pywinauto.log',) app = Application(backend='uia').start(r'mspaint.exe')
#dlg = app.window(title='无标题-画图')
dlg = app.window(title_re='.* - 画图')
#dlg=app['无标题-画图']
#app['无标题-画图'].draw_outline()
dlg.draw_outline()
time.sleep(1)
dlg.print_control_identifiers()
dlg['“文件”选项卡'].click()
time.sleep(1)
dlg.child_window(title='打开', control_type='MenuItem', found_index=0).invoke()
time.sleep(1)
# handle Open dialog
file_name_edit = dlg['打开Dialog'].child_window(title="文件名(N):", control_type="Edit")
time.sleep(1)
file_name_edit.set_text(r'D:\pythonstudy\2018-4-16\1.png') # There are 2 Open buttons:
# dlg.Open.Open.click() will call drop down list of the file name combo box.
# The child_window statement is just copied from print_control_identifiers(). #dlg['打开Dialog'].打开Botton.click()
dlg['打开Dialog'].child_window(title="打开(O)", auto_id="", control_type="Button").click()
#new_dlg=app['1.png - 画图Dialog']
dlg.重新调整大小.click()
dlg.调整大小和扭曲.像素.select()
if dlg.调整大小和扭曲.保持纵横比.get_toggle_state() != 1:
dlg.调整大小和扭曲.保持纵横比.toggle()
dlg.调整大小和扭曲.child_window(title="水平(H):", control_type="Edit").set_text('')
dlg.调整大小和扭曲.确定.click()
# Select menu "File->Save as->PNG picture"
dlg['“文件”选项卡'].click()
dlg.child_window(title="另存为", found_index=1).invoke()
dlg['保存为'].child_window(title='文件名:',control_type="Edit").set_text('test.png')
dlg['保存为'].保存.click()
if dlg.确认另存为.exists():
dlg.确认另存为.是.click()
# Close application
dlg.close()

>>>>>>待续

pywinauto进阶练习的更多相关文章

  1. nodejs进阶(6)—连接MySQL数据库

    1. 建库连库 连接MySQL数据库需要安装支持 npm install mysql 我们需要提前安装按mysql sever端 建一个数据库mydb1 mysql> CREATE DATABA ...

  2. nodejs进阶(4)—读取图片到页面

    我们先实现从指定路径读取图片然后输出到页面的功能. 先准备一张图片imgs/dog.jpg. file.js里面继续添加readImg方法,在这里注意读写的时候都需要声明'binary'.(file. ...

  3. JavaScript进阶之路(一)初学者的开始

    一:写在前面的问题和话 一个javascript初学者的进阶之路! 背景:3年后端(ASP.NET)工作经验,javascript水平一般般,前端水平一般般.学习资料:犀牛书. 如有误导,或者错误的地 ...

  4. nodejs进阶(3)—路由处理

    1. url.parse(url)解析 该方法将一个URL字符串转换成对象并返回. url.parse(urlStr, [parseQueryString], [slashesDenoteHost]) ...

  5. nodejs进阶(5)—接收请求参数

    1. get请求参数接收 我们简单举一个需要接收参数的例子 如果有个查找功能,查找关键词需要从url里接收,http://localhost:8000/search?keyword=地球.通过前面的进 ...

  6. nodejs进阶(1)—输出hello world

    下面将带领大家一步步学习nodejs,知道怎么使用nodejs搭建服务器,响应get/post请求,连接数据库等. 搭建服务器页面输出hello world var  http  =  require ...

  7. [C#] 进阶 - LINQ 标准查询操作概述

    LINQ 标准查询操作概述 序 “标准查询运算符”是组成语言集成查询 (LINQ) 模式的方法.大多数这些方法都在序列上运行,其中的序列是一个对象,其类型实现了IEnumerable<T> ...

  8. Java 进阶 hello world! - 中级程序员之路

    Java 进阶 hello world! - 中级程序员之路 Java是一种跨平台的语言,号称:"一次编写,到处运行",在世界编程语言排行榜中稳居第二名(TIOBE index). ...

  9. C#进阶系列——WebApi 接口返回值不困惑:返回值类型详解

    前言:已经有一个月没写点什么了,感觉心里空落落的.今天再来篇干货,想要学习Webapi的园友们速速动起来,跟着博主一起来学习吧.之前分享过一篇 C#进阶系列——WebApi接口传参不再困惑:传参详解  ...

随机推荐

  1. chrome js 获取css

    var myDiv = document.getElementById("chooseRect"); var computedStyle = document.defaultVie ...

  2. 韩国 DBA 博客

    http://mysqldba.tistory.com/ http://cafe.naver.com/mysqlpg http://cafe.naver.com/realmysql http://wi ...

  3. IndexError:string index out of range

    IndexError:string index out of range 出现在下标越界的情况,如 item[1],可能为空的时候下标就会越界

  4. HDU 5063 Operation the Sequence(暴力)

    HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...

  5. Linux命令(六)——软件包管理(安装应用程序)

    与windows安装各种应用程序相似,在linux下也可以安装各种需要的应用程序,通常称为软件包.目前,在linux系统下常见的软件包格式主要有:RPM包.TAR包.bz2包.gz包.deb包.sh结 ...

  6. [ACM] HDU 5086 Revenge of Segment Tree(全部连续区间的和)

    Revenge of Segment Tree Problem Description In computer science, a segment tree is a tree data struc ...

  7. ijkplayer视频播放

      http://android-doc.com/androiddocs/2017/1018/5416.html https://www.2cto.com/kf/201801/714366.html ...

  8. bzoj4956: [Wf2017]Secret Chamber at Mount Rushmore

    F......loyd? 这范围也是..... 然而大了也不会.... #include<cstdio> #include<iostream> #include<cstr ...

  9. Linux系统查看当前时间的命令

    转自:https://www.cnblogs.com/redfire/p/7702213.html 一.查看和修改Linux的时区1. 查看当前时区命令 : "date -R"2. ...

  10. RabbitMQ消息队列服务

    MQ 全称为 Message Queue, 消息队列( MQ ) 是一种应用程序对应用程序的通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们. 一个软件它 ...