Forum Archive

file-picker.py input over Dict.

DavinE

Hello Guys,

i Have a Question about the file-picker.

my file-picker get an input over a dict like that:
{'Kunden Übersicht': ['01_Beschreibung', '02_Materiallisten', '03_Prüfungen', '04_KNX', '05_Bilder', '06_Notizen', '07_Datenbank']}

when i run the file-picker and i change e.g.:
{'Kunden Übersicht': ['01_Beschreibung', '02_Materiallisten', '03_Prüfungen', '04_KNX', '05_Bilder', '06_Notizen', '07_Datenbank'], '01_Beschreibung': ['TEST 1']}

how can i "reload" the file-picker ?
is that possible ?

cvp

@DavinE said:

how can i "reload" the file-picker ?

What's is your file-picker?

DavinE

@cvp, it‘s the file-Picker youd change.

So i call him:

```
root_node = FTPTreeNode(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()
````

And i only change That i can load an Dict into it..
structureFolder Is My Dict

cvp

@DavinE said:

how can i "reload" the file-picker ?

Where is your picker.view.present()?
And what do you mean with reload it? You can call it a second time

JonB

You can call reload_data on the table view object to reload the entire thing. Or, you need to call insert_rows on the individual rows to cause them to appear.

DavinE

@cvp said:

@DavinE said:

how can i "reload" the file-picker ?

Where is your picker.view.present()?

dock(picker.view).top_left(self.sectionAdaptCustomer)
This is my „present“

@cvp said

And what do you mean with reload it?

When i do some Changes on the names add new Stuff and some others....
I rebuilt my Dict with the new data...

@cvp said
You can call it a second time

Yes, but it‘s a owen Class and i don‘t have all Self. Variable in the file-Picker Class to Present

The best and easyest way is when i can reload the data... but i don‘t know how...
But maybe i call it a second Time...

DavinE

@JonB said:

You can call reload_data on the table view object to reload the entire thing. Or, you need to call insert_rows on the individual rows to cause them to appear.

For insert_rows theres no way ^^

What exacly do you mean with reload_data ?
tableview.reload()?

cvp

@DavinE said:

What exacly do you mean with reload_data ?

Yes, @JonB wanted to say (I think)

TableView.reload_data()
JonB

As an example, in the original omz file picker, see do_expand:

def do_expand(self, entry, row):
        '''Actual folder expansion (called on background thread if async_mode is enabled)'''
        entry.expand_children()
        self.set_busy(False)
        old_len = len(self.flat_entries)
        self.rebuild_flat_entries()
        num_inserted = len(self.flat_entries) - old_len
        inserted_rows = range(row + 1, row + num_inserted + 1)
        self.table_view.insert_rows(inserted_rows)

self.table_view has an insert_rows method, which you call giving it the index of the rows that got inserted into the dict. It will then animate inserting those rows. You could also call
self.table_view.reload_data()
Or possibly just
self.table_view.reload() (I think both work), which reloads the entire table.

(inserted_rows)

DavinE

@JonB said:

As an example, in the original omz file picker, see do_expand:

```
def do_expand(self, entry, row):
'''Actual folder expansion (called on background thread if async_mode is enabled)'''
entry.expand_children()
self.set_busy(False)
old_len = len(self.flat_entries)
self.rebuild_flat_entries()
num_inserted = len(self.flat_entries) - old_len
inserted_rows = range(row + 1, row + num_inserted + 1)
self.table_view.insert_rows(inserted_rows)

```

self.table_view has an insert_rows method, which you call giving it the index of the rows that got inserted into the dict. It will then animate inserting those rows. You could also call
self.table_view.reload_data()
Or possibly just
self.table_view.reload() (I think both work), which reloads the entire table.

(inserted_rows)

i Tryed self.table_view.reload() already this did not worked...
but i can try self.table_view.reload_data() maybe this works i will reply

cvp

@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.

DavinE

@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

cvp

@DavinE said:

I Think the easyest way to reload is close the picker and Open it again

Sure, but you want to reload while it is presented..aren't you?

And we don't see how you use your structfolder dict in TreeNode and TreeDialogController

DavinE

@cvp said:

@DavinE said:

I Think the easyest way to reload is close the picker and Open it again

Sure, but you want to reload while it is presented..aren't you?

Yes, That is right

@cvp said:

And we don't see how you use your structfolder dict in TreeNode and TreeDialogController

I do nothing other like the original file-picker.py but i can Post it:

Class TreeNode:

#FUNKTION Class TreeNode
class TreeNode(TreeNode):
    #FUNKTION __init__
    def __init__(
        self,
        customer_folder,
        path=None,
        level=0,
        can_delete=None,
        can_move=None,
        can_rename=None,
        can_add=None,
        is_folder=None
    ):
        TreeNode.__init__(self)
        self.CUSTOMER_FOLDER = customer_folder
        self.path = path
        self.level = level
        self.can_delete = can_delete
        self.can_move = can_move
        self.can_rename = can_rename
        self.can_add = can_add
        self.is_folder = is_folder

        if path:
            self.title = os.path.split(path)[1]
        else:
            self.title = 'Kundenordner anpassen'
        self.leaf = path and len(os.path.splitext(path)[1]) > 0
        self.icon_name = 'FileOther' if self.leaf else 'Folder'

        # Setzt gewisse Eingenschaften was mit dem Objekt gemacht werden darf und was nicht!
        if self.level is 1:
            self.can_delete = False
            self.can_move = False
            self.can_rename = False
            self.can_add = True
            self.is_folder = True
        else:
            self.can_delete = True
            self.can_move = True
            self.can_rename = True
            self.can_add = False if self.leaf else True
            self.is_folder = False if self.leaf else True

        if not self.path is None and self.path != list(self.CUSTOMER_FOLDER)[0]:
            MariaDB()
            try:
                cursor_SQL.execute(
                    """
                    SELECT
                        ID,
                        structure_set_path
                    FROM folder_structure
                    WHERE structure_name = %s
                    """,
                    [
                        self.path,
                    ],
                )
                for datanorm_ID, datanorm_structure_set_path in cursor_SQL.fetchall():
                    self.ID = datanorm_ID
                    self.set_path = datanorm_structure_set_path

            except mysql.connector.Error as e:
                #CHANGES Hier muss noch der Fehler ausgegeben werden!!!
                print(f'SELECT `version`, `build`, `update_needed` FROM `version` WHERE `file`= app:\n{e}')
                sound.play_effect(play_sound('play_effect', 'mysql', 'error'))
                console.alert('mysql.connector', 'Der Abruf des Versionstandes konnte nicht ausgeführt werden.\nFehlerausgabe im Terminal', hide_cancel_button=False)
            finally:
                cursor_SQL.close()
                connection_SQL.close()

    #FUNKTION expand_children
    def expand_children(self):
        print(f'self.path -- {self.path}')
        print(f'self.level -- {self.level}')

        if self.path is None:
            names = [list(self.CUSTOMER_FOLDER)[0]]
        else:
            if self.path in self.CUSTOMER_FOLDER:
                names = self.CUSTOMER_FOLDER[self.path]
            else:
                names = ''

        print(names)

        self.children = [FTPTreeNode(self.CUSTOMER_FOLDER, name, self.level+1) for name in names]
        print(type(self.children))
        print(self.children)
        self.expanded = True 

TreeDialogController:


class TreeDialogController(object):
    #FUNKTION __init__
    def __init__(
        self,
        root_node,
        content_area,
        main_content,
        device,
        customer_folder,
        customerSettingPath,
        sectionAdaptCustomer,
        regUserLabel,
    ):
        self.content_area = content_area
        self.main_content = main_content
        self.DEVICE = device
        self.CUSTOMER_FOLDER = customer_folder
        self.customerSettingPath = customerSettingPath
        self.sectionAdaptCustomer = sectionAdaptCustomer
        self.regUserLabel = regUserLabel

        self.table_view = ui.TableView()
        self.table_view.content_inset = (0, 0, 50, 0)
        self.table_view.data_source = self
        self.table_view.delegate = self
        self.table_view.flex = 'WH'
        self.table_view.allows_selection_during_editing = True
        self.table_view.tint_color = 'grey'
        self.view = ui.View()
        self.view.name = root_node.title
        self.root_node = root_node
        self.entries = []
        self.flat_entries = []
        self.expand_root()

cvp

@DavinE said:

I do nothing other like the original file-picker.py

I don't recognize the File_Picker...
TreeNode class entirely different.
I think you should try, as you thought, close the previous and recall it.

cvp

@DavinE said:

class TreeNode(TreeNode):

It is not coherent with root_node = TreeNode(structfolder )

DavinE

@cvp said:

@DavinE said:

I do nothing other like the original file-picker.py

I don't recognize the File_Picker...
TreeNode class entirely different.
I think you should try, as you thought, close the previous and recall it.

Thanks That you helped me always out!

I Need to call these so it woreked like i will

self.root_node = TreeNode(structureFolder)

self.root_node.expand_children()
self.entries = self.root_node.children
self.flat_entries = self.entries
self.table_view.reload() 
cvp

@DavinE said:

I Need to call these so it woreked like i will

👍

DavinE

@cvp said:

@DavinE said:

I Need to call these so it woreked like i will

👍

Simpler:

self.root_node = TreeNode(structureFolder)
self.expand_root() 

Really thanks @cvp 😎