You have to cast the ui.Image
into a scene.Texture
. Something like that:
return scene.Texture(ctx.get_image())
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.
You have to cast the ui.Image
into a scene.Texture
. Something like that:
return scene.Texture(ctx.get_image())
You could also just use os.path.dirname(__file__)
- assuming your interpreted file lies in your Book Notes folder. This would have the advantage of not having to hard code any folder name.
Works fine for me. Your exception suggests that in your enviroment the functiondelete_calendar()
in the namespace reminders
has been overwritten with a string of the same name. You should investigate that with the inspector when your exception is raised.
Or more likely ... you have missed a parenthesis while copying the snippet which often completely confuses the interpreter.
It is a bit unclear to me what you are trying to do.
ui.NavigationView
is just a (weirdly named) StackPanelmain_view
you cannot add it to the nav_view
and present it again.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')
Ploting and calculus can be done with numpy
and matplotlib
. Both are available in pythonista by default.
import numpy
from matplotlib import pyplot
#100 linear samples between -10 and 10
x = numpy.linspace(-10, 10, 100)
#draw a red line through f(x) = x
pyplot.plot(x, x, 'r-')
#draw a blue dotted line through f(x) = sin(x)
pyplot.plot(x, numpy.sin(x), 'b--')
#show the plot
pyplot.show()
In order to save space in device (iPhone), can I delete freely from Pythonista some pure python external libraries that I never use [...]
Hm, pythonista is taking about 450 MB with some installed extra libraries for me. Sympy 1.0 is is about 4 MB big. I do not want to be rude, but I somehow fail to see how this going to make any impact on a device that measures its storage space in GB.
Okay, thanks. I gave the thread a more meaningful title. I cannot provide a full example as my code relies on other stuff, but here is a snippet how I did solve the problem now (a bit clunky). Maybe it will help someone in the future. I wrote two comments so that the code does make some sense.
def draw_line(self):
'''
'''
if self.line is not None:
self.line.remove_from_parent()
minx, miny = None, None
path = ui.Path()
path.line_width = 2
# self is a pythonista node. self.anchors are some phythonista node
# objects that are children of self. We want to draw a line through all
# these anchors within the coord system of self.
for i, anchor in enumerate(self.anchors):
p = anchor.position
# get/update the lower left corner minimum
minx, miny = (p.x if minx is None else min(minx, p.x),
p.y if miny is None else min(miny, p.y))
if i == 0: path.move_to(p.x, -p.y)
else: path.line_to(p.x, -p.y)
# the offset(position) of our node has to be the lower left corner
# point plus the center vector of our path
self.line = ShapeNode(path,
stroke_color='green',
fill_color='transparent',
position = (minx + path.bounds.w * .5,
miny + path.bounds.h * .5),
parent=self)
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.
This is how it should look like/ where the button should be.
It is a bit unclear to me what you are trying to do.
ui.NavigationView
is just a (weirdly named) StackPanelmain_view
you cannot add it to the nav_view
and present it again.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')
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.
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
console.write_link
is function of Pythonistas proprietary console
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.
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 as intended expected. If you want the board to sit whithin screen bounds you have to choose your Board center somewhere in the lower left corner.
Sound mysterious, I am using both using numpy and matlotlib quite regularly. The only things I can say are:
\_\_init__.py
).numpy.random
and neither does matplotlib.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.
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.
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 agianst future
do forbid the use of deprecated methods and unusal styles in multiple guide lines.