Pythonista is the 4th search result for python
in the Norwegian AppStore!
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 Sebastian
-
RE: Pythonista is the #1 search result for "python" in the App Store! (US and Germany)
-
RE: Convert Indentation action missing in Pythonista 2.0?
The "Convert indentation" action on 1.5 is named "Convert Tabs" on 2.0 (on iPhone at least).
-
RE: No sound when I run a script at all
Does this work?
import sound sound.set_honors_silent_switch(False) sound.set_volume(1) sound.play_effect('piano:D3')
-
RE: Asset picker in a Scene?
Oh cool! I guess this can be used for a lot of different things. I use it in a level editor for a platformer game I'm developing. 😋
-
RE: Asset picker in a Scene?
@shaun-h Go ahead and use it! I just posted it here in case any of you guys needed it 😄 I use it for my own project as well!
Now I'm curious! What kind of project are you working on? If you don't mind me asking 😋 -
RE: Asset picker in a Scene?
I forgot to post a reply on this thread. Here's my take on an AssetPicker using the UI module. Hope someone can test it to make sure it works on other people's devices.
PS: I know the code looks horrible 😝# coding: utf-8 import os import json import ui import scene import Image def get_asset_folder(): return os.path.dirname(scene.get_image_path('emj:Airplane'))[:-10] def get_collection_info(asset_type=''): folder = get_asset_folder() with open(folder+os.listdir(folder)[0], 'r') as f: return [asset for asset in json.load(f)['collections'] if asset['type'] == asset_type] class AssetPicker (ui.View): def __init__(self, source, name='', dark_cells=False, object_type='none', parent=None): w, h = ui.get_screen_size() self.frame = (0, 0, w, h) self.name = name self.source = source self.dark_cells = dark_cells self.parent = parent self.object_type = object_type self.picked_asset = None self.load_button_items() self.create_table_view() def is_main(self): return all([1 if isinstance(i, dict) else 0 for i in self.source]) def load_button_items(self): if self.is_main(): self.left_button_items = [ui.ButtonItem('Cancel', action=lambda s: self.navigation_view.close())] else: self.right_button_items = [ui.ButtonItem('Done', action=lambda s: self.navigation_view.close())] def create_table_view(self): table_view = ui.TableView() table_view.name = 'tableview' table_view.flex = 'WH' table_view.width = self.width table_view.height = self.height table_view.delegate = self table_view.data_source = self self.add_subview(table_view) def tableview_number_of_rows(self, tableview, section): return len(self.source) def tableview_cell_for_row(self, tableview, section, row): cell = ui.TableViewCell('subtitle') cell.accessory_type = 'disclosure_indicator' if self.is_main(): text = self.source[row]['title'] cell.text_label.text = text if 'copyright' in self.source[row]: cell.detail_text_label.text = self.source[row]['copyright'] else: cell.text_label.text = self.source[row] tableview.row_height = 48 cell.image_view.image = ui.Image.named(self.source[row]) if self.dark_cells: cell.image_view.background_color = 'black' return cell def tableview_did_select(self, tableview, section, row): if not self.is_main(): if self.parent: pass # do something with asset # example: Image.open(self.source[row]).show() self.navigation_view.close() return path = os.path.join(get_asset_folder(), self.source[row]['path']) if not os.path.isdir(path): with open(path, 'r') as f: source = eval(f.read()) else: source = sorted(list(set([path.split('/')[-1]+':'+(i.split('@')[0] if '@' in i else i.split('.')[0]) for i in os.listdir(path)]))) dark_cells = 1 if 'darkBackground' in self.source[row] else 0 self.navigation_view.push_view(AssetPicker(source, name=self.source[row]['title'], dark_cells=dark_cells, object_type=self.object_type, parent=self.parent)) def present(parent=None, object_type='none', *args, **kwargs): source = get_collection_info(asset_type='image') main_view = AssetPicker(source, name='Assets', object_type=object_type, parent=parent) nav_view = ui.NavigationView(main_view) nav_view.present(*args, **kwargs) if __name__ == '__main__': present(hide_title_bar=True)
-
RE: "scene.gravity" and orientation
That's what I've been doing right now. Thanks for the answers guys!
Using the following code, I managed to see which orientation is being used.# coding: utf-8 import scene import motion class MyScene (scene.Scene): def setup(self): self.label_node = scene.LabelNode('', ('Arial', 12), position=self.size*0.5, parent=self) motion.start_updates() self.orientation = '?' def update(self): x, y, z = motion.get_gravity() if abs(x) > abs(y): if x > 0: self.label_node.text = 'LANDSCAPE, RIGHT' else: self.label_node.text = 'LANDSCAPE, LEFT' else: if y < 0: self.label_node.text = 'PORTRAIT' def did_change_size(self): self.label_node.position = self.size*0.5 def stop(self): motion.stop_updates() scene.run(MyScene())
-
RE: "scene.gravity" and orientation
I'm having the same issues with the motion module as well...
I'm relying on the accelerometer to move around in my game, and I need to get the
motion.get_gravity
relative to the device orientation. -
"scene.gravity" and orientation
I'm still kinda wondering about the
scene.gravity
. I mentioned something about it here. How can I get thescene.gracity
to follow my device's orientation? -
Platformer Art
Anyone else noticed that the
plf:Enemy_Fly_move
and theplf:Enemy_Fly_dead
have switched places? 😆 -
RE: ui.TableViewCell.detail_text_label
@Phuket2 Thanks!
ui.TableViewCell('subtitle')
did the trick! 😊👌 -
ui.TableViewCell.detail_text_label
How does the
ui.TableViewCell.detail_text_label
work? It is alwaysNone
when I try to make changes to it. -
RE: Autocomplete
I think I use jedi allready, but I meant autocomplete for the pythonista specific modules.
-
RE: Platformer in previous beta
I thought that was the case. I just started making my own level editor. That's why I asked about the asset picker, on another thread.
-
RE: Asset picker in a Scene?
In that case, I guess I'll write my own. Is there a way of getting all the assets' names in a list or something?
-
Asset picker in a Scene?
Is it possible to use the asset picker within a
scene.Scene
(the thing that opens from the editor when you tap the '+' button)? Or do I need to create my own as aui.View
?Edit:
Autocompletion errors. -
Autocomplete
I often find myself having trouble reading the code on my iPhone, as the script gets bigger, and I sometimes have to transfer it to my computer where it's easier to read. But when doing that, I really miss Pythonista's autocomplete feature on the Pythonista modules. So I was wondering if it was possible to get the same autocomplete on other editors, like for instance Sublime Text.
-
RE: Platformer in previous beta
@JonB Cool, will try that when I get home! Thanks!
-
Platformer in previous beta
I think I remember there was a platformer game example in one of the previous examples, and since I started to make a platformer game myself with the new version of the scene module I was wondering; how was the levels created?
-
RE: Bug list for beta release 160037
I don't know if this is a bug or not, or if it's just me, but the
scene.gravity
function doesn't change with the orientation. The easiest way to test this is by running the new Game Tutorial Part 3, and changing fromPORTRAIT
toLANDSCAPE
.