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.
Outliner with drag/drop reordering - part 2
-
@cvp I wonder if updates are not being made on the main thread...
https://stackoverflow.com/questions/2318445/uitableview-crashes-if-data-source-is-updated-during-scrollingYou can try beginUpdates() before updating your data (adding or deleting rows) then end updates() after reloading on the tableview ObjCInstance)
-
@JonB thanks for your continuous help. I remember that I already did something like that, without success.
I would try to incorporate this advice but it not so easy, and obviously no way to correctly test it because the problem is not reproducible on demand.Don't forget that the way I update the TableView is only by modifying directly the items, wiThouT calling delete or add functions. There are a lot of script lines where I update items because there are a lot of ways to do it. And often, the call reload_data is not in the same function. Very annoying to update in your adviced way.
I have tried this beginUpdates before deleting item(s) and enUpdates() after reload_dara, and I get this ObjectiveC error (I remember now I already got it and stopped to use this code)
Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (56) must be equal to the number of rows contained in that section before the update (60), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). Table view: <SUITableView_PY3: 0x14233d000; baseClass = UITableView; frame =(0 74; 818 1106); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x286c94480>; layer = <CALayer: 0x283c27a00>; contentOffset: {0, 373.5}; contentSize: {818, 2492}; adjustedContentInset: {0, 0, 20, 0}; dataSource: <SUITableView_PY3: 0x14233d000; baseClass = UITableView; frame = (0 74; 818 1106); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x286c94480>; layer = <CALayer: 0x283c27a00>; contentOffset: {0, 373.5}; contentSize: {818, 2492}; adjustedContentInset: {0, 0, 20, 0}; dataSource: <SUITableView_PY3: 0x14233d000>>>
Perhaps due that to delete a row and its children, I rebuild the data_source.items before reload the TableView, without using any call to an eventUal delete function. And, that works always for me, I never have this crash posted by @ihf.
I think next time I write such a program (if ever) I will use a basic scroll view and draw all the necessary objects myself ...
-
@ihf V01.24 and outline.versions with
Version V01.24 - correction of bug "sometimes after view dates, back and hit Expand All and the top line of icons is (mostly) gone"
-
@ihf not sure you had seen the post where there was a new version of Mac script, before new version of outline.py
-
@cvp I was just now testing it. I changed the line that had your path in it to: default_path = os.path.expanduser('~/Desktop/Pythonista/Backup/Outline')
I couldn't get it to work at first. Not sure what the problem was but I ended up with Firefox being frozen and I restarted it and now the script seems to work fine.In my case, it opens Safari but then the outline html file is opened (by default) in Firefox. It never actually uses Safari. Now are you ready for potential enhancements? The ultimate "enhancement" would be a complete rewrite so that the full outline runs as a webapp (no Pythonista)...LOL. A bit simpler, add sort on date to the html page. -
@ihf said
The ultimate "enhancement" would be a complete rewrite so that the full outline runs as a webapp (no Pythonista)
Did you become crazy? 😂
-
@ihf on Mac OS, I do
os.system("open /Applications/Safari.app file:///"+os.getcwd()+"/"+fname)
Then, I don't see how you could open Firefox.
On iOS, I do
webbrowser.open('safari-http://localhost:' + port)
-
-
@cvp The script opens Safari but then when it actually opens the .html file my config must be defaulting to opening a tab in Firefox. Yes, rewriting to run in the web was not meant to be a serious proposal although it would have many virtues and to my knowledge does not exist. I will continue to enjoy your creation with the hope that Pythonista keeps running without support from @omz.
-
-
@cvp je comprends que
-
@ihf For instance, I've spent some hours today to try to solve the problem of "the display gets messed up in that lines are overlapping." when sorting dates. But without success.
-
@ihf Version mac_outline_viewer.py V00.05 with
V0.05 - support sort on dates
Even if I 'm sincerely not proud of my quick and dirty script/html/JavaScript and maybe it could be very slow with long outlines, I don't know.
Feed-back hoped
-
@cvp It works great!
-
@ihf As you know, a TableView does not remember all TableViewCells but rebuilds them when they are visible. If scrolling makes them disappear, their memory is freed and if they reappear, they are built and displayed. It is therefore a saving of memory but a waste of time if the scrolling causes cells to appear and disappear often. But it seems that most of our problems would come from the possible desynchronization between the management of the table of items and their display.
I more and more want to try to replace the TableView with a simple ScrollView where I would manage the position of the rows myself. The cells would be subviews of the scrollview and would only be rebuilt if their content changes.
this solution, for which I cannot yet estimate the development time, would only be valid if your outlines did not contain too many lines (but how many = too many?). Could you tell me approximately how many lines are in your outlines?
And, would you agree to test a different version? -
@cvp To answer your last question first, of course, I would be happy to test any future version. As far as how large my outlines are, Were you referring to how many lines in the outline or in a particular item?
-
-
@cvp Another option is that you can store TableViewCells rather than returning new ones. That way the objc references never change .
Rather than starting cell_for_row with
cell=ui.TableViewCell()
like normal, you could manage your cells on your own, and build them all in advance, and then in cell_for_row, you simply return the pre-built value:cell=self.cells[section][row]
Since you probably won't have outlines with thousands of rows, that's probably safe memory-wise.
I also wonder if it wouldn't be possible to use one of the omz text view classes (say extending the markdown formatter. ). That would require a lot of swizzling, or at least making implementing subclasses of objc classes that we don't have good documentation on (and just have to rely on swizzlelog to figure out the interfaces) ... so probably is not heading in the right direction...
-
@JonB that would not solve the problem we had for which you adviced to use begin /end update.
The internal code will still decide to call cell_for_row and perhaps still be désynchronised.and yet, I followed the omz doc, namely modify my items and call reload for any modification or deletion
Édit: for info, I already stored cell in my own array self.cells, for usage when I'm sure that the row is still on screen, when the TextView in the row is edited
-
@cvp My Outline lengths are (up to now) <100 items. I can imagine them being somewhat longer but certainly <<1000.