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.
ios + pythonista3
Use the view of the ui library.
import ui
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.
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.
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.
-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, 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