file-picker.py input over Dict.
@cvp said:
@DavinE said:
maybe this works
That supposed that you changed your TableView.data_source.items....
I sincerely don't understand where you use a dict instead of a path.
This is the OMZ file-picker present:
def file_picker_dialog(title=None, root_dir=None, multiple=False,
select_dirs=False, file_pattern=None, only=False, show_size=True, from_dialog=None, icloud=False, callback=None):
if root_dir is None:
root_dir = os.path.expanduser('~/')
if title is None:
title = os.path.split(root_dir)[1]
if icloud:
root_node = FileTreeNode('/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/', show_size, select_dirs, file_pattern,only) # bug? does not use root_dir
else:
root_node = FileTreeNode(root_dir, show_size, select_dirs, file_pattern,only) # bug? does not use root_dir
root_node.title = title or ''
picker = TreeDialogController(root_node, allow_multi=multiple)
picker.from_dialog = from_dialog
picker.callback = callback
picker.view.present('sheet')
rood_node
has here the Path in it.
This is my present:
root_node = TreeNode(structureFolder)
picker = TreeDialogController(
root_node,
self.content_area,
self.main_content,
self.DEVICE,
structureFolder,
self.customerSettingPath,
self.sectionAdaptCustomer,
self.regUserLabel
)
dock(picker.view).top_left(self.sectionAdaptCustomer)
at(picker.view).top = at(self.regUserLabel).bottom
at(picker.view).bottom = at(self.sectionAdaptCustomer['createCustomerFolderSetting__ACTION_ButtonSitePositionLabel']).top
at(picker.view).right = (at(self.content_area).right - (At.gap * 2))
at(picker.view).left = at(self.content_area).left
picker.view.wait_modal()
root_node = TreeNode(structureFolder)
structureFolder
here is my dict not a path...
I Think the easyest way to reload is close the picker and Open it again
How can I manage controls over two views
Or without needing pop class
@ui.in_background
def onBtn(self, sender):
self.label.text = 'calling pop'
f = dialogs.form_dialog('',fields=[{'title':'text','type':'text'}])
if f:
self.label.text = f['text']
Tableview_select
@mikael, this is about as stripped out as I can make it
def tableview_add(self):
trxRec = {}
result = {}
# trxRec = {'account': self.selected_account}
result = bucks_dialog(trxRec) # this works
def tableview_update(self):
result = {}
trxRec = {}
# trxRec = self.selected_item
result = bucks_dialog(trxRec) # this blows out - self.container_view changes to None
def tableview_did_select(self, tv, section, row):
self.tableview_update()
def transaction_action(sender): # sender is ui.button
sender.tint_color = 'blue'
ds.tableview_add()
Bucks_dialog is a custom form_dialogs from dialogs
Error is:
Pythonista3/Documents/Projects/bucks/bucks_form.py", line 217, in trans_type_action
self.container_view.name = segment_names[ind]
AttributeError: 'NoneType' object has no attribute 'name'
self.container_view is none (form_dialog)
A touch event on a tableview?
@zinc if you use form_dialog instead of list_dialog, each field is editable
'Enter'-keypress/softpress to call action in custom form input
Again thank you for the teaching points @cvp :)
I tried your code, and as you suggested, the rerun did give an error:
Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/60EBD24F-667F-4F6E-B595-9100C20FC784/Pythonista3/Documents/dialogs_2.py", line 16, in <module>
f = dialogs.form_dialog(title='dialog title', done_button_title='ok',fields=fields, sections=None)
File "/var/containers/Bundle/Application/CD376C3C-8193-4F37-B990-A9B960D30F2D/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/dialogs.py", line 456, in form_dialog
c = _FormDialogController(title, sections, done_button_title=done_button_title)
File "/private/var/mobile/Containers/Shared/AppGroup/60EBD24F-667F-4F6E-B595-9100C20FC784/Pythonista3/Documents/dialogs_2.py", line 10, in my__init__
original__init__(self, *args, **kwargs)
File "/private/var/mobile/Containers/Shared/AppGroup/60EBD24F-667F-4F6E-B595-9100C20FC784/Pythonista3/Documents/dialogs_2.py", line 10, in my__init__
original__init__(self, *args, **kwargs)
File "/private/var/mobile/Containers/Shared/AppGroup/60EBD24F-667F-4F6E-B595-9100C20FC784/Pythonista3/Documents/dialogs_2.py", line 10, in my__init__
original__init__(self, *args, **kwargs)
[Previous line repeated 494 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object
Am I missing something here or isn't it the purpose of the del sys.modules['dialogs']
-statement to avoid this issue?
'Enter'-keypress/softpress to call action in custom form input
Just for the fun...
I never thought about it before but there is a way to change the frame of the dialog (and define the return as the done button) without redefining the form_dialog.
You just have to monkey patch the init method of the _FormDialogController class.
The only problem is that, during a rerun, you have to delete the import of dialogs, otherwise a problem of recurrence occurs.
Try this, if you want 😀
import ui
from console import set_color
try:
del sys.modules['dialogs']
except:
pass
import dialogs
original__init__ = dialogs._FormDialogController.__init__
def my__init__(self, *args, **kwargs):
original__init__(self, *args, **kwargs)
self.container_view.frame = (0, 0, 400, 130)
self.textfield_did_end_editing = self.done_action
dialogs._FormDialogController.__init__ = my__init__
fields = [{'title':'Fahrenheit:','type':'text','value':''}]
f = dialogs.form_dialog(title='dialog title', done_button_title='ok',fields=fields, sections=None)
if f:
try:
float(f['Fahrenheit:'])
set_color(0,0,1) # not 1,1,1 because background is also white
print(round((int(f['Fahrenheit:'])-32)*5/9,2), end='')
set_color()
print('ËšC')
except Exception as e:
print(e)
set_color(1,0,0)
print('! ', end='')
set_color()
else:
set_color(1,0,0)
print('! ', end='')
set_color()
print('Cancelled')
I would like to add that I am proud of myself for having found this, because, sincerely, I am far from mastering Python 😢
Examples for dialogs.form_dialog() ?
@madivad All my last added fields types are processed in my_tableview_cell_for_row, thus they only work with the standard form_dialog.
dialogs._FormDialogController.tableview_cell_for_row = my_tableview_cell_for_row
diag = dialogs.form_dialog(title = 'Form Dialog', sections=form_list_of_sections)
Examples for dialogs.form_dialog() ?
I’d forgotten about your repos!
I ended up working it out, for me it’s the custom dialog where the control is misaligned, with the inbuilt control it aligns correctly
Edit: just confirmed, I downloaded that git, comment out line 89 (and join 90 back to the end of 89) and then edit the 'diag' at the end of the doc from:
diag = dialogs.form_dialog(title = 'Form Dialog', sections=form_list_of_sections)
To
diag = my_form_dialog(title = 'Form Dialog', sections=form_list_of_sections)
And run that on a smaller screen
Examples for dialogs.form_dialog() ?
@madivad weird. I only use my iPad and form_dialog is a sheet of (0,0,500,500) in standard dialogs module. Normally, the code sets the width of the segmentedcontrol equal to the TetxField width, unless you did change something.
Rough stick
Is like this to share default:
import glob
import dialogs
path='/private/var/mobile/Containers/Shared/AppGroup/29427C70-DDD5-4356-A6C7-0FBAD22F6230/Pythonista3/Documents/'
files=[f for f in glob.glob(path+'**/*.py',recursive=True)]
files_name=[]
form_list_of_sections=[]
for f in files:
import os
with open(f,'r') as file:
fn=os.path.basename(file.name)
file.close()
files_name.append(dict(type = 'check', title = fn,
key = 'to_share', value = False)
)
form_list_of_sections.append(('pick for share pp',files_name, 'the files will appear in other app by share default '))
diag = dialogs.form_dialog(title = 'Form Dialog', sections=form_list_of_sections)```