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.
Ui button action parameters
-
@resserone13 I was busy to understand your loop/path in page_info. What is its goal?
-
@resserone13 said:
take the user to the websites
How do you want to "take the user to a website"?
Open Safari or have a web view in your ui?Easiest way is to have, instead of a textview, a button and it's action to open the url
-
@cvp page_info() is like any_scene() class I used when I made the app with scene. I modeled page_info() after any_scene(). Page_info() is a generic function to display the page. Kinda like your myview().
I’ve also created make_btn() and make_title() for making buttons and creating titles.
-
@resserone13 I would like them to be directed to the website in Safari.
-
@resserone13 written just before your answer about safari, this code opens a web view in your app.
If you open safari, you will leave your app. Sure of this?class my_View(ui.View): def __init__(self,l_txt,tv_txt): self.background_color=bg_color self.frame = (0,0,700,700) title = ui.Label() title.font= text_font, 25 title.text = l_txt title.alignment= ui.ALIGN_CENTER title.frame=screen_size.w * 0.1, screen_size.h * 0.02, screen_size.w * 0.75, screen_size.h * 0.05 if tv_txt.startswith('http'): tv = ui.Button() tv.title = tv_txt def open_url(sender): wv = ui.WebView() wv.load_url(sender.title) wv.frame = sender.superview.frame wv.present('sheet') wv.wait_modal() tv.action = open_url else: tv = ui.TextView() tv.editable=False tv.scroll_enabled=True tv.auto_content_inset=True tv.number_of_lines= 0 tv.line_break_mode = ui.LB_CHAR_WRAP tv.text = tv_txt tv.background_color=bg_color tv.alignment= ui.ALIGN_CENTER tv.font= text_font, 22 tv.frame= screen_size.w * 0.07, screen_size.h * 0.08, screen_size.w * 0.87, screen_size.h * 0.85 self.add_subview(title) self.add_subview(tv)
-
@resserone13 i'm no more available during one hour...sorry
-
-
@resserone13 said:
I also have Trouble importing text from another file. I tried to set it up like the brick breaker levels and colors example but it’s not working.
Where is your code for this?
-
-
@resserone13 I understand but it is not in your GitHub, for testing your code 😀
-
@resserone13 did you try my code to open a web view?
-
@resserone13 said:
line = ui.Path.rounded_rect(x, y, screen_size.w * 0.8, 0, 50)
Your rectangle has a width of 0, thus not displayed...
-
@resserone13 and path can be drawn in the draw method of the ui.View, but, it seems, only if you sub-class it.
class View_with_Path(ui.View): def draw(self): for x, y in (screen_size.w/2, screen_size.h * 0.8), (screen_size.w/2, screen_size.h * 0.4), (screen_size.w/2, screen_size.h * 0.1): path = ui.Path.rounded_rect(x, y, screen_size.w * 0.8, 10, 50) path.line_width=3 ui.set_color('yellow') # only to see where the path is drawn path.fill() def page_info(text, image, dwell_time, desc): v = View_with_Path() #v = ui.View() v.frame = (0,0,screen_size.w,screen_size.h) v.background_color=bg_color title= make_title(text) #for x, y in (screen_size.w/2, screen_size.h * 0.8), (screen_size.w/2, screen_size.h * 0.4), (screen_size.w/2, screen_size.h * 0.1): #path = ui.Path.rounded_rect(x, y, screen_size.w * 0.8, 0, 50) #line.line_width=3 #ui.set_color('yellow') #path.fill() #display.add_subview(line) . . .
-
@cvp said:
@resserone13 did you try my code to open a web view?
Yes I got the web view working. Thanks. -
@resserone13 said:
Yes I got the web view working
If you prefer to open really Safari:
if tv_txt.startswith('http'): tv = ui.Button() tv.title = tv_txt def open_url(sender): import webbrowser webbrowser.open('safari-'+sender.title)
-
@resserone13, things are moving so fast here that I am probably hopelessly late, but I can think of two options if you want to have clickable links in the middle of a body of text.
First is to use a webview, which works but has the downside that it wants to open the link in place. You can get around this by using a delegate to capture the attempt and open the link in Safari instead.
Second is to use objc and attributed text with a textview or label. This is not difficult but can be made even easier with an addition to the RichLabel that is part of the ui3 package, let me know if that seems relevant to you.
-
@mikael I just have my iPhone 11 with Pythonista. I don’t know if I have ui3. I’ve had trouble using stash to import and pip install modules. The web view is working OK for me. I just need to add some navigational buttons at the top. But it does look nice. I will probably have questions on objc In the near future. Once I figure out UI I will dive into objective c.
-
@cvp. Thanks for all your input and advice. I am reviewing everything and re-writing the script. Hopefully everything will be functions. I am going to try classes as well but I might have mainly functions. I’m going to work on it and I will keep you updated. Thanks for all your help it’s really allowing me to get a lot done and learn a lot. Hopefully when I keep showing you these updates you’ll see that I’m learning from what you’re showing me.
-
@resserone13 said:
I just need to add some navigational buttons at the top.
import ui class MyWebView(ui.View): def __init__(self, url): self.width, self.height = ui.get_window_size() self.wv = ui.WebView(frame=self.bounds) self.wv.load_url(url) self.add_subview(self.wv) bi_back = ui.ButtonItem(image=ui.Image.named('iob:ios7_arrow_back_32')) bi_forward = ui.ButtonItem(image=ui.Image.named('iob:ios7_arrow_forward_32')) bi_back.action = self.go_back bi_forward.action = self.go_forward self.right_button_items = [bi_forward, bi_back] self.present('fullscreen') def go_back(self, sender): self.wv.go_back() def go_forward(self, sender): self.wv.go_forward() wv = MyWebView('https://omz-software.com/pythonista/docs/')
-
I have a for loop that loops over btn names and creates a button for each name. How do I make it loop over a list of btns and a list of actions so that the each button gets a name and an action?
I’m using enumerate to help space the btns out. I tired switching to zip but then I loose the i variable for the enumerate function?def add_btn(self, btn_names, actions_list): for i, name, a in enumerate((btn_names)): btn= ui.Button() btn.background_color=btn_clr btn.title=name btn.font=(btn_fnt, btn_txt_sz) btn.tint_color=txt_clr btn.border_width=2 btn.border_color=txt_clr btn.frame=(width * 0.15, height * (0.12 + i * 0.1), width * 0.7, height * 0.05) btn.corner_radius= btn_corner_radius btn.action='?????' self.add_subview(btn)