• Sebastian

    @JonB this is exactly what I'm looking for, thank you! Since I learned mathematics with Norwegian terms, I didn't really know what to search for in English 😂

    posted in General Discussion read more
  • Sebastian

    Hey guys, just a quick question.

    I'm using SymPy to factorize polynomials, but I stumbled upon a certain polynomial that it wouldn't factorize.
    I have P(x) = x**3 - 3*x, which should be factorized to x*(x-sqrt(3))*(x+sqrt(3)).
    Using sympy.factor('x**3-3*x'), I get x*(x**2 - 3).

    Any ideas why SymPy can't factorize this polynomial?

    posted in General Discussion read more
  • Sebastian

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

    posted in Pythonista read more
  • Sebastian

    The "Convert indentation" action on 1.5 is named "Convert Tabs" on 2.0 (on iPhone at least).

    posted in Pythonista read more
  • Sebastian

    Does this work?

    import sound
    
    sound.set_honors_silent_switch(False)
    sound.set_volume(1)
    sound.play_effect('piano:D3')
    

    posted in Pythonista read more
  • Sebastian

    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 read more
  • Sebastian

    @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 read more
  • Sebastian

    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 read more
  • Sebastian

    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 read more
  • Sebastian

    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 read more

Internal error.

Oops! Looks like something went wrong!