Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Unable to get ScrollView working.
-
I am having trouble using ScrollView I can't get it to actually scroll. I have the content size larger than the ScrollView size. But it refuses to scroll.
I will post some code later.
-
See
ScrollView.py
in https://github.com/humberry/ui-tutorial -
I will try that out when I can. (It's like 1 AM here so yeah. Can't look at it now.)
-
@chibill, from memory I think it will be the content_size not being set. A few have had simlar problems.
-
Well the github example works but mine does not. And the only difference is I have multiple things I add as sub_veiws to the ScrollView object.
-
Even if I encapsulate the multiple parts in a View object then add it to sub_view it does not work.
-
@chibill , best way is to make a basic example of what you are trying to do and post it. I do that all the time. When I am making the basic example to post I get the light bulb moment and see the problem
-
I can upload a zip on the files. (There is like four files.)
-
@chibill the easiest way to share is to create a folder, put your files in it, then from the file menu, clck edit, select the folder, then click share, and select Gist.
-
I can't share that way it seems. It keeps telling me 'unable to create gist. Error 422'
-
@chibill , just copy and paste your code into the forum
Use the </> icon in the forum and paste your code in the text template that's displayed. Then your code will be formatted -
# coding: utf-8 import ui import ping import base64 from PIL import Image import StringIO import re w = ui.View() sv = ui.ScrollView() v = ui.View() #v.present('fullscreen') t = None def BuildServerList(Servers): global t lasty = 10 for Server in Servers: server = ui.load_view('MCServer.pyui') server['title'].text=Server['title'] server.name = Server['title'] server.background_color = (.1,.1,.1,1) try: temp = ping.do_ping(Server['ip'],Server['port']) server['ping'].text = str(temp[0])+' ms' server['Description'].text =re.sub(u'\u00A7.', '',temp[1].response['description']) server['Version'].text =str(temp[1].response['version']['name']) server['player'].text = str(temp[1].response['players']['online'])+' / '+str(temp[1].response['players']['max']) if temp[0] < 150: server['bars'].image = ui.Image.named('0.PNG') elif temp[0]<300: server['bars'].image = ui.Image.named('1.PNG') elif temp[0]<600: server['bars'].image = ui.Image.named('2.PNG') elif temp[0]<1000: server['bars'].image = ui.Image.named('3.PNG') else: server['bars'].image = ui.Image.named('4.PNG') except Exception as e: try: temp = ping.do_ping(Server['ip'],Server['port']) server['ping'].text = str(temp[0])+' ms' server['Description'].text =re.sub(u'\u00A7.', '',str(temp[1].response['description']['text'])) server['Version'].text =str(temp[1].response['version']['name']) server['player'].text = str(temp[1].response['players']['online'])+' / '+str(temp[1].response['players']['max']) if temp[0] < 150: server['bars'].image = ui.Image.named('0.PNG') elif temp[0]<300: server['bars'].image = ui.Image.named('1.PNG') elif temp[0]<600: server['bars'].image = ui.Image.named('2.PNG') elif temp[0]<1000: server['bars'].image = ui.Image.named('3.PNG') else: server['bars'].image = ui.Image.named('4.PNG') except: server['Description'].text = 'Ping Timeout' server['bars'].image = ui.Image.named('5.PNG') try: test = ui.Image.from_data(base64.decodestring(temp[1].response['favicon'].split(',')[1])) server['image'].image = test except: server['image'].image = ui.Image.named('unknown.png') server['bars'].image = ui.Image.named('0.PNG') server.x = 10 server.y = lasty+10 lasty = lasty+10 +server.height v.add_subview(server) v.background_color=(0,0,0,0) v.height = lasty v.width=730 sv.add_subview(v) sv.x,sv.y = 0,0 sv.content_size.height = lasty+10 sv.content_size.width = 730 serverList = [{'title':'ORE School','ip':'nickstar.openredstone.org','port':25565},{'title':'ORE SkyBlock','ip':'nickstar.openredstone.org','port':26969},{'title':'PandoraCraft','ip':'173.236.23.173','port':25565},{'title':'ORE School','ip':'nickstar.openredstone.org','port':25565},{'title':'ORE SkyBlock','ip':'nickstar.openredstone.org','port':26969},{'title':'PandoraCraft','ip':'173.236.23.173','port':25565}] BuildServerList(serverList) sv.width,sv.height = ui.get_screen_size() sv.border_color=(0,1,0,0) sv.border_width = 10 w.background_color=(1,1,1,0) w.add_subview(sv) w.present()
It's abit messy because of trying to make it work.
-
The file Ping is just to get the ping information of Mc Servers. And the MCServer.pyui is just view that I use as a template to not have to make a lot of code to build the list.
-
@chibill , ok. Still it's just difficult to work out with all the code. That's why I say if you just do a minimal version of your code to post. Easy for people to help and also I think 9 times out of 10 you get the answer yourself. The simple things are easily not spotted because you are thinking about your logic.
But I hope this helps. I am not writing anything into the scroll view, but you can see it scrolls vertically. 4 times the height of the view.bounds.height
import ui if __name__ == '__main__': f = (0, 0, 600, 800) v = ui.View(frame = f, bg_color = 'teal') sv = ui.ScrollView(frame = f, bg_color = 'white') sv.content_size = (v.bounds.width, v.bounds.height * 4) v.add_subview(sv) v.present('sheet')
-
@chibill , hmmm, I think I see now. You have to use a tuple to set content_size (w,h)
-
Yeah that was the whole problem. Which makes me feel sort of dumb.
-
@chibill , no need to,feel,dumb. I have done that for you me and the rest of planet here 😱 We keep asking we keep learning