How to implement Scroll View in pythonista 1

Introduction

Like when you're scrolling through a map Display a part of a large image on the screen and scroll it. This can be implemented by using the scroll view of the ui library.

environment

ios + pythonista3

Library used

Use the view of the ui library.

import ui

pythonista ui documentation

The pythonista documentation is carefully written as it is, so even beginners can to some extent I understand. I managed to understand whether English was kind or not, even if I was fully borrowed from the power of automatic translation.

I will implement it for the time being

scrollview_image.py


#! python3
# 
#20210118 ver001 scroll view is implemented by viewing a large image and displaying it.
# 

import ui #Library to display scrllview and imageview


class epaint(ui.View):
	def __init__(self):
		w,h = ui.get_screen_size()#ui library methods. Get the screen size and substitute it for w and h.
		
		#Create a view of the original large but image to sroll. Nothing is displayed at this stage.
		self.bv = ui.ImageView()#The object bv is ui.I declared it as ImageView and created it.
		self.bv.frame = (0, 0, 3264,2448)#Declare the frame size of ImageView. The image inside is stretched to this size.
		#By the way, it is possible to omit the frame line. If not, a View is created with the original image size.
		self.bv.image = ui.Image.named('test:Peppers')#Call and display the test image(pythonista3 inclusion)
		self.bv.bg_color = 'red'#Set the background color. It is possible without it.

		#Create a ScrollView. The scroll view is understood as the frame displayed on the screen.
		self.sv = ui.ScrollView()#The object called sv is ui.Declared that it is ScrollView.
		self.sv.width = w*0.8#Set the display frame to the width of 80% of the screen.
		self.sv.height = h*0.75#Set the frame to 75% of the height of the screen.
		self.sv.content_size = (3500,2500)#Set the size of the frame to put the original image of ScrollView.
		#Make it the same size or larger than the size of the View to be inserted. It is placed in the upper left. Unlike ImageView, it is not stretched.
		self.sv.scroll_enabld = False #Scrolling is True enabled and False disabled. Default True
		
		self.sv.add_subview(self.bv)#By putting bv in sv, the source of ScrollView assigned the image to contents.
		self.add_subview(self.sv)#View to be displayed by putting sv in self is declared as sv.


v = epaint() #Assign a class to a variable. Instantiation.
v.present('fullscreen')#Display ui in full screen.


Explanation

Both scroll view and image view are a kind of View object of ui library. The view object is an image like a layer of retouching software. (There is also a proper order.)

This is a difficult place, but the original image of ScrollView can be any View. Buttons can also be placed outside the image. You can place as many as you like. After deciding the size of the frame of the original image in the contents of ScrollView and creating ScrollView If you assign View, it will be placed in contents. If you do not specify the placement coordinates, it will be at the upper left of the origin. (The method of specifying coordinates will be improved soon)

In the coordinate system of the ui library, the upper left is (0,0) and the x direction increases to the right, In the y direction, the bottom is the increasing direction. It's a little different from the normal coordinate system, so it may be confusing at first.

Finally, View is displayed with add because it is not displayed just by declaring it.

important point

-The coordinate system of the ui object starts at the upper left and increases toward the lower right. -View has an order. Touch event conflicts. This is because there are other views that use touch events besides ScrollView. Only the View that uses the top touch event will receive the touch event. Specifically, both view and ScrollView to get the handwritten path at the same time Not available. -View has an order. There is also a method to change the order. Use this You can also switch screens. -In addition to the image, you can also put buttons in the contents of the original image. When you press a button, scroll the button that does not fit on the screen and press it You can make a ui.

Finally

Finally, in my article "Read a photo and handwritten sketch. With zoom function. I made it." I will disassemble the function and introduce it. I'm making this tool and there is no article about ScrollView on pythonista I really had a hard time, so I introduced it first. It seems that the content was the same as swift, so to understand the image I think that article will also be helpful.

[iPhone] Scroll large images with UIScrollView

Recommended Posts

How to implement Scroll View in pythonista 1
How to implement nested serializer in drf-flex-fields
How to view images in Django's Admin
How to implement Rails helper-like functionality in Django
How to implement shared memory in Python (mmap.mmap)
How to implement a gradient picker in Houdini
How to use bootstrap in Django generic class view
How to upload files in Django generic class view
How to develop in Python
How to temporarily implement a progress bar in a scripting language
How to implement Python EXE for Windows in Docker container
How to handle session in SQLAlchemy
How to use classes in Theano
How to write soberly in pandas
How to collect images in Python
How to update Spyder in Anaconda
How to use SQLite in Python
How to convert 0.5 to 1056964608 in one shot
How to reflect CSS in Django
How to kill processes in bulk
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
How to use PubChem in Python
How to run TensorFlow 1.0 code in 2.0
How to handle Japanese in Python
How to log in to Docker + NGINX
How to call PyTorch in Julia
[For beginners] How to implement O'reilly sample code in Google Colab
How to implement Java code in the background of RedHat (LinuxONE)
How to smartly define objects that are commonly used in View
How to use calculated columns in CASTable
I tried to implement PLSA in Python
[Introduction to Python] How to use class in Python?
How to suppress display error in matplotlib
I tried to implement permutation in Python
How to dynamically define variables in Python
How to do R chartr () in Python
How to convert csv to tsv in CLI
How to delete expired sessions in Django
How to use Google Test in C
How to end Python's infinite scroll scraping
I tried to implement PLSA in Python 2
How to work with BigQuery in Python
How to execute commands in jupyter notebook
How to do'git fetch --tags' in GitPython
How to get a stacktrace in python
How to display multiplication table in python
How to extract polygon area in Python
How to reassign index in pandas dataframe
How to check opencv version in python
I tried to implement ADALINE in Python
How to enable SSL (TLS) in Apache
How to specify non-check target in Flake8
I tried to implement PPO in Python
How to handle consecutive values in MySQL
How to switch python versions in cloud9
How to adjust image contrast in Python
How to use __slots__ in Python class
How to dynamically zero pad in Python
How to do Server-Sent Events in Django