Make interface using design tool and edit it by script (add some ui elements). Is it possible?
I had made interface using design tool in Pythonista. And I need to edit "scrollview1" from script and add list of buttons. How can I do it?
May be it is imposible? If I make interface in design tool then I can only edit action script?
@cg-mag, I did a simple example without trying to place etc that may help you.
Most of the code is just making up a view. But just done to illustrate it. From what I understand about your question is you really need to look at the function
In the example.
# coding: utf-8 import ui # your action function for your button # sender is the ui element. In this case the button. def add_buttons_to_scrollview(sender): # get a reference to the view. v = sender.superview # get a reference to the scrollview, using array # notation, using the name of the object. sv = v['scroll'] # make a button in code and add it to the scrollviews, subviews btn = ui.Button(title = 'test button') sv.add_subview(btn) if __name__ == '__main__': f = (0,0,540,576) v = ui.View(frame = f) #ignore this, is like your pyui file, just in code scrollview = ui.ScrollView(name = 'scroll') scrollview.background_color = 'white' scrollview.frame = v.frame scrollview.height -= 40 scrollview.y = 40 v.add_subview(scrollview) btn = ui.Button(title= 'Press') btn.border_width = .5 btn.x =btn.y = 5 btn.width = 100 btn.background_color = 'white' v.add_subview(btn) #end ignore # in the ui designer, enter the function to be # called by your btn action # done in code here, but you can enter the function # name in the ui designer. btn.action = add_buttons_to_scrollview v.present('sheet')
Maybe post a snippet of what you tried that didnt work.
It sounds like you really want a TableView, so that you don't need to instantiate all buttons at once.
Thank you! I'll try
add_subview will work for scrollviews, but note to make it scrollable you need to set the content_size property. I think typically one would create a container View that is larger than the screen, and add that View as a subview of scrollview, rather than adding lots of subviews to the scrollview, though i think it can be done either way.
For a dictionary, you might take a look at TableView, which will give you better performance when you have many words.
I'll think about tableView. Thanks. But it will be later..
I touch the button, but nothing was heppend(.
# coding: utf-8 import ui def action_butt(sender): v=sender.superview myScrollView=v['scrollview1'] butt = ui.Button(title='test') myScrollView.add_subview(butt) v=ui.load_view('Untitled 5') v.present()
I need to understend the principle of work with views..
@cg-mag, it looks ok to me what you did. But look in ui designer and make sure you have the correct names. And also that you action field in the btn is just
@Phuket2, Yes I have correct names.
It is a simple scene. Where can i mistake?((
@cg-mag , what is the 'No Name' control on the picture? Is your scrollview1 at the front? I mean object layering? You have a menu to move to the front and back. Also is your scrollview apart if a subview in the form?
From your pics it looks correct to me. But, you are right, you really need to understand views. Might be time to take a step back and read about them in the included documentation.
It's the most fundamental thing you need to understand.
Let's say you scrollview is a subview of customview on the form called mycustomview. Then when you reference it you would need to do something like
v = sender.superview
scrollview = v['mycustomview']['scrollview1']
Sorry, I am trying to help, for me it's not clear what your problem is
No Name - it is not control. It is standart title... Scroll view I move to back. There obly 2 objects - scroll view and buuuton. All in the center with standart sizes.
Action from button have executed and I can change with this action for example content_size, but I can not add button!
I can change in scrollView anything, but can`t add new ui element
Maybe start a new project. Only put the scrollview and the button on the form. Maybe something will show up clearly
You are also right, it's a very easy example. So just start from scratch to be sure
I start new script and do this. I have the same
Ok, maybe I didn't see in the code version. Change the content size in the ui designer. Make the width and height the size of your screen.
Thank you a lot! Problem was in that - button was created but in left upper conner - very high. I move scroll view down and now all works right!!
Now I have new questions) - can i add 2 ui.label in each raw in table view?
@cg-mag , yes you can create ui.Labels in your ui.TableViews. But it has default ui.Labels built in already. You can do so much with ui.TableView, but it's worth the time reading first, it will save you a lot of time. It looks more difficult than it is.
Hard for me to reply fast at the moment. Floods every where and electric on and off. 3G is really bad. Maybe many people using it.
@cg-mag, no problems. I have been working on a menu creating program for my friend. I haven't done much, but from the screenshot below you can see you can do a lot with the TableView.