What I’m doing now is calling a view which is already made using view class (it’s like my original font-picker), so I would rather choose your first sample. I pass a label object when calling a popup view as an argument and it seems almost perfect except one thing.
In case of your first sample (which is without @ui.in_background,) when getting back from popup, the button looks stay grey even though I can still press the button. (so it just looks grey.) I thought putting “@ui.in_background” would solve it, but not really.
When putting “@ui.in_background” before def onBtn, after returning from popup the button now looks ok (I mean the color,) but the button never responds after it. Only after closing the main view, the button’s action occurs.
Yeah! your codes now put the texts back to the main view.
You can't put a wait_modal inside a button action, because the ui thread blocks until the button exits
Ok, so this was the problem.
and this is why the button still looks grey after closing the pop-up?
“@ui.in_background” didn’t work.
“using a "shield" view” > means using add_subview, right? Yes, I believe this would work for handing data.
dialog modules> I didn’t think about. I will check this.
Thanks for your many hints.
This maybe an easy question but I cannot figure out myself.
I want to show a pop-up view over my main view, selecting something on pop-up and send the selected thing back to the main view.
I made up a simple codes to show what I want to do.
By pressing a button, another small view is shown and putting some texts in a textfield and close it, I expect the texts will be put on the main view’s label. However it will not happen and only after closing the main view, I find in the console the texts are surely printed by print statement. Seems like control is not actually back to the program after closing the pop-up. How can I fix it?
import ui class Test(ui.View): def __init__(self, frame): self.frame = frame self.bg_color = 'white' btn = ui.Button(frame=(100,100,100,30), title='Open pop', action = self.onBtn) self.label = ui.Label(frame=(100,200,400,30), border_width=1) self.add_subview(btn) self.add_subview(self.label) def onBtn(self, sender): self.label.text = 'calling pop' pop = Popup() pop.present('sheet') self.wait_modal() text = pop.get_text() self.label.text = text pop.close() print('after get_text', text ) class Popup(ui.View): def __init__(self): self.frame = (100,100,400,600) self.bg_color = '#ededed' self.textbox = ui.TextField(frame=(100,100,200,30)) self.add_subview(self.textbox) self.right_button_items = [ui.ButtonItem(title='close', action=lambda x:self.close())] def get_text(self): return self.textbox.text if __name__ == '__main__': w, h = ui.get_screen_size() v = Test((0,0,w,h)) v.present('sheet')
Thank you. I could make a png external file.
Now, I have another problem. I thought png file would do, but I wanted to combine the image with a photo pictures which are usually in jpeg. When I try it with paste method of PIL, such as
where photo_img is in jpeg format and img_labels is in png format, this will result an error “images do not match.”
If you think of any good solution, let me know. Thank you.
Can I save ui.Image as an external file with the format of jpeg (or png). If I can transform ui.Image into PIL Image, that would do.
What I want to do is snapshot an image on ui.View and save that image as a jpeg file.
Here is my code and I can only make a ui.Image, but don’t know how to make a jpeg file from it.
with ui.ImageContext(100, 100) as ctx:
... v = ui.ImageView(width=100,height=100)
... label = ui.Label(text='testlabel')
... label_img= ctx.get_image()
I have picked the part of my codes to show the picker. And I also have installed some custom fonts in iOS and they are seen in setting.
from objc_util import *
v = ui.View()
vc = ObjCInstance(v)
fontpicker = ObjCClass('UIFontPickerViewController').new().autorelease()
fontview = fontpicker.view()
v.frame = (0,0,512,960)
done_button = ui.ButtonItem(title='OK')
sel = fontpicker.selectedFontDescriptor()
if sel != None:
done_button.action = tapped
v.right_button_items = [done_button]
v.font = None
font = UIFontPickerViewController()
if font != None:
label.text = font
label.font = (font, 18)
root = ui.View(bg_color='white')
button = ui.Button(
label = ui.Label(
Well, tab spaces were cut from the above codes when embedded to here. If you could try the above codes in your device, need to fix the tabs.