How can I find the subclasses of the app using pywinauto - python-3.x

Hi,everyone
Nowadays I have been working on automating the Flygram app using python package such as pywinauto, pyautogui, however, I got stuck in the problem.
When the script runs and finds the Flygram app, there are two instances of Flygram. The worse thing is that there are no subclasses of Flygram. Even I used pyinspect, it didn't find the subclasses.
Please help me someone who knows how to handle this kind of problem.
Thanks.
from pywinauto.application import Application
import pywinauto.mouse as mouse
import pywinauto.keyboard as keyboard
import time
app = Application(backend='uia').start(r"C:\Flygram_PC\Flygram.exe", timeout=10)
time.sleep(3)
app = Application(backend='uia').connect(path=r"C:\Flygram_PC\Flygram.exe")

Related

How do I run other python separate inside of kivy program

Coming from Arduino to python I am use to everything running in a loop more or less.
I am trying to understand how python interacts with kivy.
I understand that in order to make a segment of code run over and over I need a while statement for example. However if I use code that loops before it gets to the kivy code it will never get to the kivy code. But if I make a loop after the kivy code it will not run till I close the program.
I have google around and I see examples of simple projects of python/kivy projects that all the code pertains to the UI glue logic to make it actually do something. But I have not seen anything show python code running independent of the kivy project.
In other words if I made a project in Arduino I would have a main loop and I could call out to functions and then return from them. However I don't understand what is the best way to do this with kivy/python.
The sample code I have posted below is not a loop however I would expect it to run everything in one go. But It will run the first print statements and then when I close the app the last print statement will run.
I understand that loops are not recommended with object oriented programing, this is just a simple example as reference of what I'm use to.
For those that will say I don't understand what your asking and what are you trying to do or ask?
I am trying to ask where do I put python code that dose not pertain immediately to the kivy code but needs to run in loops or whatever while kivy is running. So that I can make things happen on the python side while not blocking kivy.
Dose this require multiple python programs? And leave the kivy program by itself almost like a .kv file.
Or dose it require everything to be put in classes?
Thanks for any clarification, best practices or examples.
from kivy.app import App
from kivy.uix.button import Button
print("test")
class FirstKivy(App):
def build(self):
return Button(text="Test text")
print("test2")
FirstKivy().run()
print("test3")
You would need to add Threading to your code
from kivy.app import App
from kivy.uix.button import Button
import threading
print("test")
class FirstKivy(App):
def build(self):
return Button(text="Test text")
print("test2")
def run():
FirstKivy().run()
def print_stuff():
print("test3")
kivy_thread = threading.Thread(target=run)
print_thread = threading.Thread(target=print_stuff)
kivy_thread.start()
print_thread.start()

How to configure tkinter buttons to seem more modern

Okay so I'm a teacher using tkinter to create gui's with my students. My mac users are fine with the look but in windows their programs leave something to be desired. I don't have access to PIP (my sys admin WONT open it up for the kids to use terminal) so I'm limited in my libraries.
Im (slowly) building up some configurations that i think would help them get the idea behind how to configure (I explain its like adding CSS to HTML - doens't (usually) change the function, it just looks better) any tips or examples i can pass on to them would be super helpful. Here is an example of a slider i turned into a tactile on/off switch.
import tkinter as tk
main = tk.Tk()
def on_off_slider_action(slider_val):
if int(slider_val): #using as "truthy"
on_off_slider.configure(troughcolor="#00FF00")
else:
on_off_slider.configure(troughcolor="#FF0000")
on_off_slider = tk.Scale(main, from_=0,
to=1,orient=tk.HORIZONTAL,length=50,showvalue=0,
command=on_off_slider_action,width=30)
on_off_slider.configure(bd=0)
on_off_slider.configure(relief=tk.FLAT)
on_off_slider.configure(sliderrelief=tk.FLAT)
on_off_slider.configure(bg="#999999", activebackground="#888888" )
on_off_slider.grid(row=0,column=0)
main.mainloop()
example switch off
example switch on

How to copy-paste data from an OS-running application with Python?

I need to write an application that basically focuses on a given Windows window title and copy-pastes data in a notepad. I've managed to achieve it with pygetwindow and pyautogui, but it's buggy:
import pygetwindow as gw
import pyautogui
# extract all titles and filter to specific one
all_titles = gw.getAllTitles()
titles = [title for title in all_titles if 'title' in title]
window = gw.getWindowsWithTitle(titles[0])[0].activate()
pyautogui.hotkey('ctrl', 'a')
pyautogui.hotkey('ctrl', 'c')
Using Spyder, I ocasionally get the following error when activating:
PyGetWindowException: Error code from Windows: 126 - The specified module could not be found.
Additionally, I would be interested in doing this process without affecting the user working on the machine. Activate basically makes the window pop to front. Moreover, it would be better to not be OS dependant, but I haven't found anything yet.
I've tried pywinauto but the SetFocus() method doesn't work (it's buggy, documented).
Is there any other method which would make the whole process invisible and easier?
Not sure if this will help
I am using pywinauto to set_focus
import pywinauto
import pygetwindow as gw
def focus_to_window(window_title=None):
window = gw.getWindowsWithTitle(window_title)[0]
if not window.isActive:
pywinauto.application.Application().connect(handle=window._hWnd).top_window().set_focus()

Weird way of importing Python turtle works but I don't know why

I hope you will understand my question.
I noticed that I get the same results when I import turtle module in following two ways.
from turtle import Turtle
t=Turtle()
t.screen.bgcolor("black")
and also
import turtle
turtle.bgcolor("black")
I am confused about this, “from turtle import Turtle”.
According to what I know, it means “to import Turtle.py from turtle (folder / package)”. I may be wrong, you can help me out to understand better.
But I can’t find any Turtle.py module. It is only turtle.py I saw.
What's weird about it is that it works.
Can anyone tell me why?
I am using Python version 3.6
Python's turtle.py is unusual in that it presents both a function-based interface and an object-oriented interface. Depending on how you import it, you can work with one, or the other, or both.
Here, we are using the object-oriented interface to invoke the screen method bgcolor():
from turtle import Turtle
t = Turtle()
t.screen.bgcolor("black")
I usually write this as:
from turtle import Turtle, Screen
screen = Screen()
screen.bgcolor("black")
t = Turtle()
as having direct access to the Screen object simplifies things. Using this style import, you cannot access the function-based interface.
When we do this simpler import, we have access to both the function-based interface and the object-oriented interface. Here, we're using the function bgcolor() to set the background color:
import turtle
turtle.bgcolor("black")
Using either the function-based or object-oriented interface to turtle.py is fine, but you can get yourself seriously confused when mixing the two.

Adjusting python auto-complete behavior

I have been using Aptana with pydev and IDLE to learn python2.7. And it has done a fair job of helping me to learn, except for when I came across this microblog tutorial. In it there is a line from flask.ext.sqlalchemy import SQLAlchemy which leads to a db = SQLAlchemy( line, in Aptana there is no help, no doc string, no examples of what could go in there. Even worse, all of this:
class User(db.Model):
id = db.Column(db.Integer, primary_key = True)
nickname = db.Column(db.String(64), index = True, unique = True)
email = db.Column(db.String(120), index = True, unique = True)
role = db.Column(db.SmallInteger, default = ROLE_USER)
Is in red, no idea how to pull it apart to learn its syntax. However, when I do:
from flask.ext.sqlalchemy import SQLAlchemy
from flask import Flask
app = Flask(__name__)
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer,primary_key = True)
In IDLE, I am getting auto-completion, doc strings, I can see what else can go in there, I can learn.
I thought the answer would exist with a new IDE like environment, I got it in my head that VIM might be helpful. I am on windows, so GIT, MinGW, TortoiseHG, _vimrc, vimfiles, {autoload,bundle}, pathogen.vim, jedi-vim, building vim from source (for some reason the ones I kept finding didn't have python enabled) were not easy task, considering first time exposure and all at once. So I have a vim that can edit python code, and from flask.ext.sqlalchemy import SQLAlchemy in vim has the same result as in Aptana, no help.
Can someone explain to me why IDLE is able to help but Aptana/Pydev and Vim cannot? Can someone show me how they can help?
This is what is in flask.ext.__init__().py
# -*- coding: utf-8 -*-
"""
flask.ext
~~~~~~~~~
Redirect imports for extensions. This module basically makes it possible
for us to transition from flaskext.foo to flask_foo without having to
force all extensions to upgrade at the same time.
When a user does ``from flask.ext.foo import bar`` it will attempt to
import ``from flask_foo import bar`` first and when that fails it will
try to import ``from flaskext.foo import bar``.
We're switching from namespace packages because it was just too painful for
everybody involved.
:copyright: (c) 2011 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
def setup():
from ..exthook import ExtensionImporter
importer = ExtensionImporter(['flask_%s', 'flaskext.%s'], __name__)
importer.install()
setup()
del setup
So in my case from flask.ext.sqlalchemy import SQLAlchemy translates to "look in site-packages for the flask_sqlalchemy.py and in that file find SQLAlchemy" which is, in this case, a big class. How can I make Aptana and vim see this, like IDLE does?
This link solved it, but I used C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib;C:\Python27\Lib\site-packages as my Variable value and I deleted and restored my interpreter in pydev, seems to have worked.

Resources