You can import any file type into pythonista, you have just to press the share button in your source app, then select pythonista and then import file.
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.
Posts made by zipit
-
RE: Import Scripts written on Mac/PC to Pythonista?
-
RE: snippets button
This is how it should look like/ where the button should be.
-
RE: Possible to change menubar/header color and font for ui.view?
It is a bit unclear to me what you are trying to do.
- An
ui.NavigationView
is just a (weirdly named) StackPanel - You cannot present an instance of a view twice. If you do present your
main_view
you cannot add it to thenav_view
and present it again. - You can however present as many views as you want alongside (views are always modal though).
edit: You can present an instance of a view multiple times as a popover (popovers behave it a bit weirdly). Also nothing should crash if you try to present a view twice. You should just get an exception informing you that the view is already being presented. So if your code is crashing for you, you should probably provide a more extensive code example.
Your code should look something like this:
import ui some_view = ui.View() nav_view = ui.NavigationView(some_view) nav_view.present('popover')
- An
-
RE: Colorama, see characters in color?
Hi, then, this not what can I do?...
Depends on your definition of this. You cannot set the background color but you can set the text color and font. Just follow the link provided by @ccc or use the Pythonista documentation and look up the
console
module. -
RE: Comment Line shortcut?
Hi,
the short and probably most useful answer is : 'No, you cannot.' The longer answer is : Pythonista does not allow custom virtual keyboard shortcuts at the moment. It is however possible to register shortcuts for physical keyboards programmatically - with some limitations/problems (for details see [1]). You can also head over to the recent Python 3.6 and A better keyboard threads where you will find partially a discussion on the very thing you want to do. @omz said he might consider it, but as always things are mostly tied to demand, so if you want to see some virtual keyboard customization you might want to express your whishes there (or more officially on github).
[1] https://forum.omz-software.com/topic/3156/editor-configurability/2
-
RE: What is command for console.write_link() on Python on PC?
console.write_link
is function of Pythonistas proprietaryconsole
module. You cannot reproduce that behaviour with a standard CPython (aka normal Python) installation since desktop shells usually do not support mouse interaction and therefore there is no such functionallity in CPython. However you can use a different Python platform on your desktop computer. IPython [1] is a very popular Python platform that has an interactive shell. IPython runs in the browser on a platform called Jupyter, so you could run IPython everywhere - on your iPad or iPhone for example. -
RE: Child nodes are not anchored within their parent node
Your CheckerBoard class is sitting at
position=parent.bounds.center()
, so I do not understand what you do mean with 'is not placed at the 0, 0 pixel', it seems to be working asintendedexpected. If you want the board to sit whithin screen bounds you have to choose your Board center somewhere in the lower left corner. -
RE: import numpy fails
Sound mysterious, I am using both using numpy and matlotlib quite regularly. The only things I can say are:
- The polar plot example runs fine for me in both Python enviroments.
What you told us about the exception is a bit confusing since neither numpy nor matplotlib have an init.py file afaik (they have both multiple __init__.py files though)edit: I just realized that you were probably only struggling with the forums markdown interface since your init.py is printed bold (you have to escape the first two underscores:\_\_init__.py
).- The polar plot example does not import anything from
numpy.random
and neither doesmatplotlib.pyplot
.
I cannot think of anything obvious, I think you will have to describe more precisely (actually copy and paste the full trace of the exception) what you are doing and what is going wrong.
-
RE: Running a program on Pythonista and Sublime Text.
Jeah, I did not state that very clearly. Was I meant was that since they forbid using deprecated methods the (kinda) opposite - future imports - are also not a good idea as mixing versions goes against the zen-priniciple concise and clear.
edit: And what is common is IMHO not an indicator of what is good. People also use cryptic bit shifts, overly complex list comprehensions, etc. all over the place and they are also not good.
But that is just my opinion. But you are right there are cases where you need future.
-
RE: Running a program on Pythonista and Sublime Text.
My approach would be to put from future import print_function
I do not want to be rude, but using
future
is IMHO bad advice ( especially for a beginner). IMHO it also goes against the Google Python style guide lines, which while not speaking out explicitly agianstfuture
do forbid the use of deprecated methods and unusal styles in multiple guide lines. -
RE: How do I (or how can I) add a separator line in the ui editor?
As far as I know Pythoniastandoes not expose a specific control (or View in Pyhthonistas terms) for that. There is also nothing like 4sided borders so that you could draw a (0,0,0,1) border. I did it recently by just adding an ui.View with thei height of 1 in the places I did need a border.
-
RE: Running a program on Pythonista and Sublime Text.
You are most likely running the script on your mac on Python 2.7 and on the iPad on Python 3.5 (Pythonistas default). With Python 3.0 the Python 2.x
print
keyword got demoted to a function and therefore does now require parentheses to be invoked. Long story short, you can either:- set Pythonista to Python 2.7 in the settings golbally
- or just for one instance by long pressing the play button
- or you could add something called a shebang line, forcing python into Python 2 mode from code, the first line of your script has to be
#!Python2
- or just change the code to
print (median (1,3,2))
, which in this case will also run just fine under Python 2.
-
RE: Reading Pythonistas/Apples plist file format?
Hi,
had some time to poke in
editor
around.editor.get_theme_dict()
does exactly what I want. It should be made officially public (as it is already not internal, but doesn't appear in the autocomplete for some reason). Some mentioning in the docs would also be nice. -
RE: Reading Pythonistas/Apples plist file format?
Thanks again, I'll see what I can figure out. About the quirks - This little setup shows what I consider quirky - not everything is being styled correctly.
import editor import ui import time class SomeUi(ui.View): def __init__(self): self.frame = (0, 0, 500, 470) self.table_view = ui.TableView(frame=(10, 10, 480, 400)) self.text_view = ui.TextField(frame=(10, 420, 480, 40)) self.add_subview(self.table_view) self.add_subview(self.text_view) editor.apply_ui_theme(self) def wait(dt=1.0): t = time.perf_counter() while time.perf_counter() - t < dt: pass op = SomeUi() op.present('sheet') wait(3) op.close() wait(1) editor.present_themed(op, style='sheet')
In a more complex setup I have also experieneced that when reading colors from an
ui
element styled with theeditor.apply_ui_theme()
before anyui.View.layout()
has ran can give you back a wrong color (-1, 1, 1, 1). -
RE: Reading Pythonistas/Apples plist file format?
thanks, that did work (Python really has a lib for everything):
import plistlib path = '/private/var/mobile/Containers/Shared/AppGroup/CB0CD8AB-6A20-4ECC-8312-B0822DFFD9A1/Library/Preferences/group.pythonista.plist' with open(path, 'rb') as f: data = plistlib.load(f) print(data)
The file however does not contain what I did hope for. Any chance you could shed some light on where the currently active theme is being stored? I know where the theme json files are stored, but I am sort of stumped on how to get the active theme.
Ps: I am aware of the theme related
editor
functions, but these have it quirks, which is why I am trying to do it by hand. -
Reading Pythonistas/Apples plist file format?
Hi,
does anyone know how Pyhtonistas
plist
files are being encoded? I always assumed that plists are just XML files in UTF-8 encoding. I however do fail reading pythonistas plist files, specifically :private/var/mobile/Containers/Shared/AppGroup/{Pythonistas app hash}/Library/Preferences/group.pythonista.plist
I do keep getting encoding exceptions:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd1 in position 8: invalid continuation byte
I did tryascii
,utf-8,
andutf-16
with no luck. -
RE: How do I convert a ui.Image into a scene.SpriteNode?
You have to cast the
ui.Image
into ascene.Texture
. Something like that:return scene.Texture(ctx.get_image())
-
RE: Creating a PYUI file that expands automatically on iPad?
I do not know much about the
ui
module but as far as I know the auto-resize feature of it has its limits.- each
ui.View
has aflex
field which allows some sort auf auto-resizing in relation to its parent. But it doesn't allow complex dependencies like for exampleXAML
does. - each
ui.View
also has alayout()
method which is called after its parent has been resized. Here you could intervene and adjust the layout of yourui
node when its parent (the main form) has been resized. - edit: technically you could also implement a general solution (an
ui.view
looking at its children and positioning and resizing them according to an algorithm) but that would require to implement stuff likemin_size
for everything. - if I remember correctly there are also some constants floating around in the
ui
module (check at the bottom of the doc) that tell you about the orientation and type of device your script is running on.
- each
-
RE: Python 3.6
As for the # character, where would you put that? I can't really make the keys on the extra row much smaller, and I don't really see a key there that I'd remove to replace it with #.
Actually I had not really thought about it. I had something like a modifier key in mind. I like the fact that the new keyboard lost a row but the hashtag character is IMHO quite essential for python. The word character keys do look quite empty regarding modifer keys, but I do not know if you can modify them.
I personally never did care much about snippets (I think I was a bit unclear there, I actually meant shortcuts to little python scripts interacting with the editor: autopep8, autodocstring, linting etc. - I am lazzy, I use them alot), but since you mentioned them: An alternative route for shortcuts could be to allow to execute a python script instead of a snippet. Basically a command palette that would appear in the auto-complete bar. It is always a little bit of a hassle to use editor scripts atm.
-
RE: Python 3.6
Is that the new virtual keyboard you were talking about? I am not sure how custom that virtual keyboard is, but I would like to vote for a more accessible hashtag character.
The gear icon means that we can access the tools-menue (currently accessible by the little wrench icon) from they keyboard? Or is that only there because this is some kind of default qwerty layout?
If not I also would like to vote for that. It would also be cool to be able to register shortcuts for stuff you frequently use.