omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. Sebastian

    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.


    • Profile
    • Following 2
    • Followers 1
    • Topics 31
    • Posts 161
    • Best 6
    • Controversial 0
    • Groups 0

    Sebastian

    @Sebastian

    6
    Reputation
    2620
    Profile views
    161
    Posts
    1
    Followers
    2
    Following
    Joined Last Online

    Sebastian Unfollow Follow

    Best posts made by Sebastian

    • RE: Center text in table

      Example of centered text in ui.TableView:

      import ui
      
      class Data (ui.ListDataSource):
      	def __init__(self, items=None):
      		ui.ListDataSource.__init__(self, items)
      		
      	def tableview_cell_for_row(self, tableview, section, row):
      		cell = ui.TableViewCell()
      		cell.text_label.text = str(self.items[row])
      		cell.text_label.alignment = ui.ALIGN_CENTER
      		return cell
          
      		
      v = ui.TableView()
      v.frame = (0, 0, 512, 512)
      v.data_source = Data('abcde')
      v.delegate = v.data_source
      v.present('sheet')
      
      posted in Pythonista
      Sebastian
      Sebastian
    • RE: Pythonista is the #1 search result for "python" in the App Store! (US and Germany)

      Pythonista is the 4th search result for python in the Norwegian AppStore!

      posted in Pythonista
      Sebastian
      Sebastian
    • RE: ui.TableViewCell.detail_text_label

      @Phuket2 Thanks! ui.TableViewCell('subtitle') did the trick! 😊👌

      posted in Pythonista
      Sebastian
      Sebastian
    • ui.TableViewCell.detail_text_label

      How does the ui.TableViewCell.detail_text_label work? It is always None when I try to make changes to it.

      posted in Pythonista
      Sebastian
      Sebastian
    • 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.

      posted in Pythonista
      Sebastian
      Sebastian
    • Transformation matrix?

      I'm having som problems with the new node system of the 1.6 beta. Is there an equivalent to the previous scene.translate function?

      posted in Pythonista
      Sebastian
      Sebastian

    Latest posts made by Sebastian

    • RE: Pythonista is the #1 search result for "python" in the App Store! (US and Germany)

      Pythonista is the 4th search result for python in the Norwegian AppStore!

      posted in Pythonista
      Sebastian
      Sebastian
    • 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).

      posted in Pythonista
      Sebastian
      Sebastian
    • 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')
      
      posted in Pythonista
      Sebastian
      Sebastian
    • 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. 😋

      posted in Pythonista
      Sebastian
      Sebastian
    • 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 😋

      posted in Pythonista
      Sebastian
      Sebastian
    • 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)
      
      posted in Pythonista
      Sebastian
      Sebastian
    • 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())
      
      posted in Pythonista
      Sebastian
      Sebastian
    • 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.

      posted in Pythonista
      Sebastian
      Sebastian
    • "scene.gravity" and orientation

      I'm still kinda wondering about the scene.gravity. I mentioned something about it here. How can I get the scene.gracity to follow my device's orientation?

      posted in Pythonista
      Sebastian
      Sebastian
    • Platformer Art

      Anyone else noticed that the plf:Enemy_Fly_move and the plf:Enemy_Fly_dead have switched places? 😆

      posted in Pythonista
      Sebastian
      Sebastian