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.
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? -
Do you mean take a .pyui file and "decompile" it into a .py module that produces the same effect? (Like the .designer.cs files that you get with .NET WinForms.)
I was playing around with that idea a bit, but didn't get too far with it, as it seems a lot of the object property names on the UI classes differ from what's serialized into the JSON .pyui files. Feel free to play around with this and improve on it, though.
-
No). I am beginner). I`ll have wanted to make dictionary app. I am using scrollList with list of buttons for each words. I am using sqlite3 for saving words. But I can't load words, because i don't no how edit scroll layout. I had try use add_subview, but it did not work.
-
You can add buttons from within the editor too, just clck on the scrollview, then select SubViews.
polymerchm created a tool that let you reorganize pyui heirarchys, though it doesnt sound like thats whatbyou need in this case.
https://github.com/polymerchm/pyuiEdit -
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 need to load from data base the list of words! Each word will be button.
-
@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
def add_buttons_to_scrollview(sender):
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
-
@cg-mag, now seeing you requirements, what @JonB says about a TableView makes most sense to me
@JonB said:
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(.
"action_butt" execute..# 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
action_butt
Nothing else -
@Phuket2, Yes I have correct names.
photos below.
http://cs621927.vk.me/v621927381/398fc/AilzRGS9vNA.jpg
http://cs621927.vk.me/v621927381/39905/ZCm19WhP38U.jpg
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 likev = 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?