In general the _appex
model is not really meant to be used as it is the backend for the appex
wrapper module. Try using:
import appex
print(appex.get_text())
print(appex.get_urls()) # or appex.get_url()
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.
In general the _appex
model is not really meant to be used as it is the backend for the appex
wrapper module. Try using:
import appex
print(appex.get_text())
print(appex.get_urls()) # or appex.get_url()
From memory my OpenGLES library had very rudimentary header parsing (If its not on the github repo its probably on my iPad) if you wanted to have a look at it and use components of it. From memory it was very messy, it did what it needed to do but it wasn't very nice.
@wolf71 objc_util
dynamically creates its own copy of the AudioComponentDescription
hence your ArgumentError
This can be resolved either by using the objc_util
version (can remberer exactly how to do that) or you specify that you want to use your copy. Eg
from objc_util import *
import ctypes
AVAudioUnit=ObjCClass('AVAudioUnit')
AVAudioUnitComponent=ObjCClass('AVAudioUnitComponent')
AVAudioUnitComponentManager=ObjCClass('AVAudioUnitComponentManager')
#
# componentType,componentSubType,componentManufacturer is OSType
#
# ref: developer.apple.com/reference/audiotoolbox/audiocomponentdescription
#
class AudioComponentDescription(ctypes.Structure):
_fields_=[('componentType',ctypes.c_char_p),('componentSubType',ctypes.c_char_p),('componentManufacturer',ctypes.c_char_p),('componentFlags',ctypes.c_uint32),('componentFlagsMask',ctypes.c_uint32)]
anyEffect = AudioComponentDescription('aufx','dcmp','appl',0,0)
availableEffects = AVAudioUnitComponentManager.sharedAudioUnitComponentManager().componentsMatchingDescription_(anyEffect, argtypes=[AudioComponentDescription])
@starrshaw the sound is being played twice but the call to stop it playing is only made once.
import sound, time
y = "room_One.mp3"
x = sound.play_effect(y)
sound.play_effect(y) # <- This call can be removed
time.sleep(5)
sound.stop_effect(x)
Without seeing the data or the complete stack trace I can only guess what the issue is. But two possibilities come to mind:
line
is a white space character so there is nothing to split which results in 2).splitUP
has a value of ['xy']
instead of ['x', 'y']
splitUP
Without breaking it first. IE print(splitUP)
and see what that gives.I assume that you have your data already in a list
form and that you have some understanding of how pythonista UI's work, if not let me know and I will try and explain it as best I can.
The following is a brief outline of what needs to be done:
import ui
data = [x for x in range(0, 50)]
datasource = ui.ListDataSource(data)
tv = ui.TableView()
tv.data_source = datasource
tv.delegate = datasource
def selectitem(*args):
view = ui.View(title='{}'.format(args[1]))
label = ui.Label()
label.text = "{}, {}, {}".format(*args)
label.size_to_fit()
view.add_subview(label)
view.background_color = 'white'
nav.push_view(view)
datasource.tableview_did_select = selectitem
nav = ui.NavigationView(tv)
nav.present()
Hope this helps.
If you are really concerned about memory there is a lot more in your code that can be cleaned up, mainly unnecessary variables, etc. But if you need help with that then we can go over it after.
As to the rockets not deleting correctly, I get an error before it can even delete due to non-existent indecies in the list (due to the list being modified from in the loop that is not really friendly with your code). To resolve that I completely changed your for
-loop to the following:
for i, missile in enumerate(self.missiles):
print(i, missile.position)
if missile.position.y > self.size_of_screen.y - 100:
missile.remove_from_parent()
self.missiles.remove(missile)
Also Node.remove_from_parent()
needs to be called for the object to be removed from the render list.
@mrcoxall: does the last image display once the loop is finished? I just tested it (using different images) and it seemed that the only issue was that the loop was blocking the UI thread, so it couldn't update and render the new information. To fix this just add @ui.in_background
above def start_button_touch_up_inside(sender)
and it should work fine.
Yes .tmp.html
can simply be changed to any value you want. The following code does this automatically for you:
def createTables(text=None, name=None):
if text is None:
text = editor.get_text()
if name is None:
name = '{}.html'.format(os.path.basename(editor.get_path()))
path = os.path.join(os.path.expanduser('~/Documents'), name)
with open(path, 'wb') as f:
f.write(TEMPLATE.format('\n'.join([
TEMPLATE_ROW.format(x) for x in text.split('\n') if x != ''
])))
webbrowser.open("file://{}".format(path))
However I would recommend against this on the basis that, if the .html
was not appended to the name (or even just changing the name in any way shape or form) then it will replace the contents of the file you are working on. While this might be decent when rendered out it is not as easy to read as markdown is as plaintext
. Hence I have used .tmp.html
as only one file can be open at a time and this reduces 'clutter' from your documents folder (instead of dozens of xyz.md.html
duplicate files there is just one .tmp.html
). .tmp.html
can be deleted whenever you want and will not damage you script file. (Also adding the prefix of .
means the file will be hidden (reducing visual clutter)). Sorry if this has gone to far off on a wild tangent. Hope it answers your question as well...
@procryon: float(second_word)
is never stored hence, screen.setBrightness_(second_word)
will fail as a str
object is being passed as an argument instead of a float
or int
object.
Hence: float_value = float(second_word)
and changing screen_word
to float_value
in screen.setBrightness_
should resolve your issue.
I agree that ctypes
/objc_util
errors can sometimes be a little hard to read, however the error type (TypeError
, ValueError
, etc) can be a hint towards what the issue might be. In this instance passing a str
argument where a float
or int
is expected.
Sorry didn't realise I forgot to add that. At the top of the python file add import os
that should fix it.
This is just a really basic concept for it, but add this to a workflow calling this script and see if it does what you want.
import editor
import os
import webbrowser
TEMPLATE = '''<html>
<head>
</head>
<body>
<table>
{}
</table>
</body>
</html>
'''
TEMPLATE_ROW = '''<tr>
<td> {} </td>
<td>
<div style='width: 300px; height: 300px; border: 1px solid black;'>
</div>
</td>
</tr>
'''
def createTables(text=None):
if text is None:
text = editor.get_text()
path = os.path.join(os.path.expanduser('~/Documents'), '.tmp.html')
with open(path, 'wb') as f:
f.write(TEMPLATE.format('\n'.join([
TEMPLATE_ROW.format(x) for x in text.split('\n') if x != ''
])))
webbrowser.open("file://{}".format(path))
createTables()
@uj_jonas instead of making main
a ui.ScrollView
in your code make wv_container
a ui.ScrollView
.
I'm just putting ideas out here, but split the paragraphs with str.split('\n')
and then use a tableview with a custom cell to display the text and a storyboard
view. Then tell the scrollview to break on pages.
@RMurtsoo I am going to try an explain why this hasn't worked for you with out actually giving you a direct answer, not because I am trying to be rude/annoying but it is in my honest belief that we don't learn very well when just given an answer. So if this does come across as rude or demeaning I appologise.
So to pull your code apart
view = ui.View() # this is correct however you might want to consider setting a frame size. `view = ui.View(frame=(0,0,width,height))` as the default is less than 200/200 from memory
view.present('portrait') # from documentation `ui.View.present(style='default', animated=True, popover_location=None, hide_title_bar=False, title_bar_color=None, title_color=None, orientations=None)` therefore if you want to force a orientation you need to provide values for `orientations` not `style` http://omz-software.com/pythonista/docs/ios/ui.html#ui.View.present
def button(): # `ui.Button` actions require a sender argument, ie `def button(sender):...` where `sender` can be named anything
ui.Imageview('Image').height = 120 # this creates a new `ui.ImageView` and doesn't actually reference any view from you `view` variable in the global stack. This is why you `ui.ImageView` height is not changing. Consider reading the documentation and examples to see how this is done
img = ui.ImageView() # this is correct however you might want to set a new frame size here as the default is 0/0. Which cause also be an attributing reason to why you aren't seeing anything. `ui.ImageView(frame=(0,0,200,200)` or you can set it later with `img.width`, `img.height`, `img.x` and `img.y`
img.name = 'Veer'
img.heigt = 150 # I'm going to assume that this is just a typo
view.add_subview(img)
button = ui.Button() # by naming the variable of this object to `button` you have overrided the method by the same name, thus you will get a `Exception` when tapping the button. Consider renaming either the method name to something else or renaming this variable to something else.
button.action = button
view.add_subview(button)
I would highly recommend reading the documentation for Pythonista, and for Python. Out of curiosity which version of Pythonista are you using?
@cook shared_application.setStatusBarHidden_
is a function not a variable. Try shared_application.setStatusBarHidden_(True)
.
The same goes for prefersStatusBarHidden_
As to whether or not it will work, I don't know, I would need to do further research.
I still have spare spaces on my account, I haven't used it much recently. So if you want to host from there, send me the details and I can set it up if you want.
Good catch, I can't say I have done a speed test on iOS to see the differences between the two, but in general yes byref(error)
is faster than pointer(error)
To add on to what @omz said I also saw a crash with the error variable as well.
Here is my fix:
path = ObjCInstance(NSHomeDirectory())
file_manager = NSFileManager.defaultManager()
error = c_void_p()
a = file_manager.attributesOfFileSystemForPath_error_(path, pointer(error))
print(ObjCInstance(error))
print(a)
The only major change that I made was to use ctypes.pointer
instead of ctypes.POINTER
as the upper case version is for defining argtypes and restypes or values in structures where as the lower case version is used for creating pointer objects