How to modify the screen resolution on Kivy-iOS - python

I'm working on an app using the python/Kivy-iOS toolchain. For some reason, when I build to the iPhone5, the app doesn't run fullscreen (there's letterboxing at the top and bottom, see attached screenshot). This seems to be the default behavior for Kivy on iOS.
Any idea how to set the resolution manually or make it detect resolution properly?

iPhone5 requires a launch image with following properties for it to enable full 4" screen size for your app
file name - "Default-568h#2x.png"
dimensions - 640x1136
Place in your app-kivyapp/ directory or add them via xcode's settings interface and you are good to go.

Related

Resize "size of text, apps and other items" using Selenium Python

I am currently using Selenium lib in Python to work on automation project. When the project was built up, it used specific "Scale and Layout" in windows 10 as provided in the image below
However, not all laptops will have this setting preset before they run this python script. While i could change the Resolution of the screen using following code
driver.set_window_size(1360,768)
however, i could not find a method, despite lot of google search, to set the size of "text, apps and other items" option to 100%.
The reason i need this specific setting as otherwise some of the elements go non-interactable as the screen UI change.
Please note that resetting zoom to 100% did not work.
PS: I am using Chrome Webdriver

When converting kivy file (.py) to apk, widgets are not automatically adjusting to device's window size

I am trying to develop an andriod app using Kivy. I have used floatLayout to place the widgets. The output, when I run it on my linux is:
Output in linux
Then after converting it to apk, the widgets are getting compresed and texts flow out of widget and looking shabby :
output on android
my code :
code
code
how can I make the widgets get adjusted automatically to the size of device(in my case Andriod). So that the texts doesnt flow outside the buttons and looks systamatic as it is in linux.
First of all, you have to check your kivy app in correct resolutions.So run in cmd : python main.py --size=1440x2960 (phone device screensize opt.You can scale input sizes for your computer screen. Divide by 2/3/4/5..) So you can reedit your code after check in correct resolution.
Also you need to use metrics for your font sizes.Example: font_size: '20sp' . Use sp metrics for scale your fonts for all devices automaticly. Check here for Kivy Metrics Docu.

How to take screenshot of background app in python 2.7 for mac

I have been trying to make a program that notifies me when a number changes on an app. I have been using ImageGrab and then pytesseract which works but I can only figure out how to take the screenshot when I can visually see the number. It would be very nice if there was a way to take an image of the app if it was minimized (not visible on the screen) so I could work on other things as it ran. I also need the picture of a certain part of that app I need to do a bounding box within the app of where the picture is taken.
This is what I am currently using which takes a certain part of the whole screen:
img = ImageGrab.grab(bbox=(1400,875,1445,905))
I think there might be a way to do it with Quartz but I could not find out how to do a region of a background app.
It is possible to take screenshots of windows that are running in the background with the screencapture api in MacOS. You can see the documentation by typing man screencapture in the terminal.
For your use case it would look something like this:
screencapture -l <windowId> -R <x,y,w,h>
As you mentioned, you can use Quartz to find the desired windowId:
from Quartz import CGWindowListCopyWindowInfo, kCGNullWindowID, kCGWindowListOptionAll
windowName = 'Desktop' # change this to the window you are looking for
def findWindowId():
windowList = CGWindowListCopyWindowInfo(
kCGWindowListOptionAll, kCGNullWindowID)
for window in windowList:
if(windowName.lower() in window.get('kCGWindowName', '').lower()):
return window['kCGWindowNumber']
return None
You can find a fully working example here
Note: From my testings, if you minimise(cmd + m) or hide(cmd + h) a window, taking a screenshot of it will only capture the moment before it was hidden. You would need to keep the window opened for it to work--but it is ok to keep it behind other windows. Tested on MacOS v10.15.7.

Set tkinter icon on Mac OS

I am trying to change the icon that appears on my tk application for Mac OS. The last time I checked this code worked for windows. The goal is for this solution to work across all platforms.
root = tk.Tk()
app = Application(master=root)
app.master.iconbitmap("my_icon.ico")
app.mainloop()
The code is adding the default icon for a .pdf file which is not what I intended. The path to the my_icon.ico is correct. Why won't this work for Mac OS? Is there an ultimate solution that will work cross-platform?
According to the tk tcl documentation you may want to try wm iconphoto. It appears it may support OSX and it also mentions to set the file to around a 512x512 for smooth rendering in MAC.
I do not have MAC so I cannot test this but give this a shot and let me know if it helped.
Update:
As #l'L'l pointed out you may want to try root.iconphoto(True, img). I am unable to test it myself due to not having Mac.
import tkinter as tk
root = tk.Tk()
img = tk.Image("photo", file="icon.gif")
# root.iconphoto(True, img) # you may also want to try this.
root.tk.call('wm','iconphoto', root._w, img)
root.mainloop()
Here is the relevant text from the documentation here:
wm iconphoto window ?-default? image1 ?image2 ...? Sets the titlebar
icon for window based on the named photo images. If -default is
specified, this is applied to all future created toplevels as well.
The data in the images is taken as a snapshot at the time of
invocation. If the images are later changed, this is not reflected to
the titlebar icons. Multiple images are accepted to allow different
images sizes (e.g., 16x16 and 32x32) to be provided. The window
manager may scale provided icons to an appropriate size. On Windows,
the images are packed into a Windows icon structure. This will
override an ico specified to wm iconbitmap, and vice versa.
On X, the images are arranged into the _NET_WM_ICON X property, which
most modern window managers support. A wm iconbitmap may exist
simultaneously. It is recommended to use not more than 2 icons,
placing the larger icon first.
On Macintosh, the first image called is loaded into an OSX-native icon
format, and becomes the application icon in dialogs, the Dock, and
other contexts. At the script level the command will accept only the
first image passed in the parameters as support for multiple
sizes/resolutions on macOS is outside Tk's scope. Developers should
use the largest icon they can support (preferably 512 pixels) to
ensure smooth rendering on the Mac.
I did test this on windows to make sure it at least works there. I used a blue square image to test.
If the above documentations is accurate it should also work on MAC.
If you are using Mac OS you have to use a .icns image instead a .ico image.
you can use:
from tkinter import Tk
from platform import system
platformD = system()
if platformD == 'Darwin':
logo_image = 'images/logo.icns'
elif platformD == 'Windows':
logo_image = 'images/logo.ico'
else:
logo_image = 'images/logo.xbm'
root = Tk()
root.title("My App")
root.iconbitmap(logo_image)
root.resizable(0, 0)
root.mainloop()
Important Note: This method is long and a lot of work for the task at hand. However, it does come with some unrelated benefits. Note that there might be a better way, but this will work.
Anyway, moving on....
You can use py2app.
Py2app will turn your program into a .app, meaning it runs as an application (because it is). When using tkinter this is usually what you want in the end because GUIs are usually turned into apps for ease of use. You can read the py2app documentation here, or read a non-official but easier to understand (in my opinion) tutorial here. I will also sum up how to do the process.
First install py2app:
Enter this into the command prompt:
sudo pip install -U py2app
If successful, you should get py2app.
If not, one problem might be you don’t have pip. You can download it with another command:
sudo easy_install pip
Step one:
Create a file called setup.py in the same dictionary
as the program.
Step two:
Put this into the file.
from setuptools import setup
#APP would be the name of the file your code is in.
APP = ['example.py']
DATA_FILES = []
#The Magic is in OPTIONS.
OPTIONS = {
'argv_emulation': False,
'iconfile': 'app.icns', #change app.icns to the image file name!!!
}
setup(
app=APP,
name='Your app’s name', #change to anything
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Step 3:
Then open the bash terminal in the dictionary the file is in and type this command:
python setup.py py2app -A
The -A makes the app respond to updates in the code, but makes the app unsharable. When you are done developing, rerun the command, this time without the -A, like so:
python setup.py py2app
Note: You may need to use the command python3 setup.py py2... instead of python setup.py py2... for a python 3 py2app.
Step 4:
Navigate to the dictionary your code is in/dist. In that folder will be your app. (The dist folder should have been created in step three when you ran the command)
For windows users: py2app is not what should be used, instead use py2exe.
I found a solution that worked for me, changing the application icon rather than the window icon using the pyobjc module.
import tkinter as tk
import sys
root = tk.Tk()
if sys.platform.startswith('darwin'):
try:
from Cocoa import NSApplication, NSImage
except ImportError:
print('Unable to import pyobjc modules')
else:
ns_application = NSApplication.sharedApplication()
logo_ns_image = NSImage.alloc().initByReferencingFile_('/path/to/icon.icns')
ns_application.setApplicationIconImage_(logo_ns_image)
else:
pass # handle other platforms
root.mainloop()
tkinter.iconbitmap creates a proxy icon on mac which is a shortcut to that file. If you right click a file and select get info, the window that popes up has an icon. It is the icon of the file. You can drag the icon, and that will move the file. That is a proxy icon. If you set the iconbitmap, with an .app file the proxy icon will be that app. Since files dragged from the applications folder create shortcuts, if the .app you set iconbitmap to be, it will make a short cut if you drag the icon of the title bar. This is helpful because you don't want the user to be able to just drag your icon file out of it's directory, so it doesn't work next time your tkinter program loads that .app file. Before you convert your tkinter program to an app add root.iconbitmap("/Applications/<appname>.app").
Then move your app to the applications folder. When you open your app your tkinter window will have the icon of your app.If you drag the icon into a different folder it will create a short cut to your app.

How can I set an icon for a quickly application?

How can I set an applications image (icon) in my canonical-quickly project? Even if I set the icon path in Glade, the UI designer, my icon doesn't show up.
In the aplications bar of my desktop I only see a gear.
I used the following relative path in Glade:
../media/projectname.svg
It's been a while but anyway...
You should put it here:
YOUR_QUICKLY_PROJECT_FOLDER/data/media/YOU_PROJECT_NAME.svg
(.png/.jpg might work also, I am not sure)
And you don't need to set it anywhere in the programme.

Categories

Resources