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
-
Unless the hardware keyboard inserts a character, or moves the cursor, there is not a good way to "trap" keyboard events. You could use special characters for this -- I don't have an external ios keyboard, but I understand option-c for example inserts ç, which you could look for in the delegate methods and take special action.
-
@Gerzer I had a look at your IOS Servr App, it looks like it could be a very useful App with many possibilities.
@JonB I'll look into it and consider the possibility of an implementation of it eventually. Can keyboard events not be nicely "trapped" in Pythonista or can they not be trapped in general other than by the OS?
-
mostly a pythonista thing, i think. not sure if it will be possible with the new
ctypes
module. -
@JonB I would be interested to see if it would work, however it is not essential and capturing the characters after they have been pressed is a usable work around for now.
-
@Cethric Thanks!
-
In FileManager.py is it possible to capture the <code>ui.NavigationView.pop_view</code> event? and if so how?
I want to use this to be able to transverse the folder structure of the Manager class visually in the FileViewer program.
Never mind solved my own problem, just stopped the transversal of the file structure and instead added a data item to the ListDataSource dict
-
Would it be possible to create syntax highlighting with in the ui.TextView class?
-
For some reason upon opening a file the ui.WebView loses focus and can no longer regain focus, is there something I am missing in my code or is this a bug?
A new update is avaliable here
Edit: The ui.Webview is a container for the ACE code syntax highlighter
-
try calling editor.focus().
is the ace editor working well for you? back when I was working on something similar, ace gave me tons of problems, for instance selecting text and copy/paste didn't work. the developer had. o interest in supporting iOS ( there were various branches with some iOS support, but some required changes in the main branch that jjelmer never wanted to pursue)
I ended up using CodeMirror, which while not quite as full featured, worked just fine.
-
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.