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.
Proof of concept HTML Editor
-
I used JavaScript long ago when it was practically useless and have not kept up with its rapid progression over the past few years. Would
Atom
be an option for embedding into a ui.WebView or is it to heavyweight for that? Does the choice ofCoffeescript
make it a non-starter? -
edit: focus didn't work. but I noticed if you open the settings dialog, click in the textfield, then dismiss it, the keyboard stays. that suggests you could have a hidden textarea, then after you send text to the editor, you would use
begin_editing
on the textfield to show the keyboard, then callget_editor().focus()
in JavaScript to give focus to the editor. this probably needs to have slight delays to allow animations to happen.as an aside, you should consider ways for the threads to terminate, for instance by checking
on_screen
... I got into an endless "couldn't save, trying again in 0.2 second" loop somehow. you might also consider not polling for save, but rather trigger on events in JavaScript, the push back to pythonista. see my recent post on debugging for how you'd accomplish that. -
@JonB ACE does show some errors and can be troublesome on occasions, I will look into CodeMirror as another option if I cannot get this to work.
Thank you for pointing out the threading issue, I currently only do a check when the ui.View is closed to update a variable in the thread to close it. I will look into it as I have not got that issue.
I'm sorry but I don't know what post you a redirecting me to about pushing events in javascript back to Pythonista.@ccc I believe Atom would be a little to heavyweight for what I am doing but thank you for the suggestion anyway.
I don't quite understand what you mean by using coffeescript -
see https://omz-forums.appspot.com/pythonista/post/5338101740208128
basically you implement a custom delegate for your webview that lets you pass commands initiated from JavaScript to be executed in Python. in that case, it was logging (but note this gives you access to the window errors and any console.log calls, which can be very useful). but you may find other uses. -
@JonB thank you, this really looks like it could be useful
-
@JonB I am currently in the process of changing the html editor to use CodeMirror as it actually looks like a beter option over ACE. Once I can get git working on my iPad again I will update the repo but so far the focus issue is gone and the use of a webview deligate is considerably better than a thread continuously polling the view. Thanks again
-
Is there a way of dynamically setting the background colour and the text colour of a ui.TableViewCell?
Also is there a faster method to apply the colour settings to the presented view than what is currently being used? -
tableview stuff gets set in the delegate. i believe you can call table reload (or refresh?) to apply the new theme to the existing cells. there are ways to access cell properties through callbacks, but otherwise iirc there is not an easy way to find tableviewcells from the top down.
i dont quite follow what you are doing themewise.... but are you parsing css to set the theme? is that slow, or just the recursive walking of the view tree? if the css parse is the bottleneck, just grab the colors direct from javascript.
one thing that might make things seem faster, would be to call the recursive style set as part of an animation, with a short animation duration (0.1 sec say). that way, the colors will appear to all change at once instead of trickling in.
alternatively, playing with either calling that in the background, or not, might make the ui more responsive.
-
Ok I will look into creating a custom delegate then.
The collection of themes is loaded into a variable (
themes_data
) so i only need to load the css files once, so even if it was slow initially repeated calls after the initial set up only make calls to the preloaded variable. I believe it is the recursive walk of the view tree that is the issue.
Currently the colour changes are performed in the background.
I will look into loading the colours as part of an animation.Thanks
-
the other approach, which may be faster, would be to build a list structure of all themesble objects, one time. then, you dont need to recurse through views, which might be slow due to repeated subviews calls, and the recursive nature, which involves many slow function calls. so, build a list one time (or, if you have a lot of dynamic components, youll have to keep track of them as they are added /deleted)
this would let you use list comprehension or maps to set the attributes, looping one time over the list which you have already prefiltered (eliminating all those other checks for name, etc). since list comprension /maps are optimized in c, it might yield better performance.