• Drizzel

    I figured out the issue. Whenever I import an image from my camera roll, it’s ending is in caps (.PNG). Renaming it to .png causes the issue, so I’m just going to not do that :)

    posted in Pythonista read more
  • Drizzel

    @pulbrich no, it actually functions. The output is the same if I use “import ui” and when I don’t.

    @JonB your suggestion prints the following:

    yes
    <_ui.Image object at 0x108fe9e40>

    posted in Pythonista read more
  • Drizzel

    I‘m having a somewhat similar issue, I can’t even load an image that’s 511 kB in size. I haven’t used the scene module for some time now and my memory is a bit rusty, but the following code should run without an issue, right?
    Here it is:

    from scene import *
    import os
    
    A = Action
    class MyScene (Scene):
        def setup(self):
            img = 'rectangle_1.png'
            self.background_color = 'white'
            if img in os.listdir(): print('yes')    #prints 'yes' in console
            print(ui.Image.named('IMG_5903.JPG')) #prints None in console
            #a = Texture(img) #Image not found
            a = SpriteNode(img) #could not load texture
            self.add_child(a)
            pass
        
    if __name__ == '__main__':
        run(MyScene(), show_fps=False)
    
    

    posted in Pythonista read more
  • Drizzel

    @cvp Thanks a lot! Definitely didn’t expect thou to write a full script :) Although, after all, you basically coded the base for the music player I’m working on.
    I will definitely try it out tomorrow, I’m too tired right now😴

    I already love the “for @Drizzel eyes only 😀”

    posted in Pythonista read more
  • Drizzel

    @saraparker Yeah, I figured that out too. But if you check some other GPS-logging app like runtastic, they have the same issue

    posted in Pythonista read more
  • Drizzel

    @cvp My apologies for being unclear, I just renamed the modified delete function to song_delete. And I would much prefer to just have the tableViewCell show the delete button while the console alert is shown. And after I confirmed or cancelled the delete, it should slide back or be deleted.

    But as I said above, I might just get used to it and leave it as is :)

    import ui
    import console
    
    def delete(tv, section, row):
        #Called when the user confirms deletion of the given row.
        try:
            console.alert('delete' '', '', 'confirm', hide_cancel_button=False)
            data.pop(row)
            tv.data_source = ui.ListDataSource(data)
            tv.delete_rows([row])
        except KeyboardInterrupt: None
        table.data_source.tableview_delete = ui.in_background(delete) #otherwise the tableview_delete function turs back to the standard behaviour
    
    data = [0, 1, 2, 3, 4, 5, 6]
    
    table = ui.TableView()
    table.data_source = ui.ListDataSource(data)
    table.data_source.tableview_delete = ui.in_background(delete)
    
    table.present()
    
    
    

    posted in Pythonista read more
  • Drizzel

    @cvp yeah, I missed some lines, I added them in the code below.
    @JonB That fixes the frozen screen, thanks :)
    However, the visual behaviour is odd now, although I might just have to accept that

    import ui
    import console
        
    def song_delete(tv, section, row):
        # Called when the user confirms deletion of the given row.
        try:
            console.alert('delete' '', '', 'confirm', hide_cancel_button=False)
            data.pop(row)
            tv.data_source = ui.ListDataSource(data)
            tv.delete_rows([row])
        except KeyboardInterrupt: None
        table.data_source.tableview_delete = ui.in_background(song_delete)
        
    data = [0,1,2,3,4,5,6]
    
    table = ui.TableView()
    table.data_source = ui.ListDataSource(data)
    table.data_source.tableview_delete = ui.in_background(song_delete)
    
    table.present()
    
    

    posted in Pythonista read more
  • Drizzel

    Why can’t I put a console alert in a modified tableViewCell delete function? My screen always freezes when trying to delete a tableViewCell. Here’s a basic example:

    import ui
    import console
    
    def edited_delete(tv, section, row):
        # Called when the user confirms deletion of the given row.
        try:
            console.alert('delete' '', '', 'confirm', hide_cancel_button=False)
            tv.delete_rows([row])
        except KeyboardInterrupt: None
        
    data = [0,1,2,3,4,5,6]
    
    table = ui.TableView()
    table.data_source = ui.ListDataSource(data)
    table.data_source.tableview_delete = edited_delete
    
    table.present()```

    posted in Pythonista read more
  • Drizzel

    Thanks a lot, I tried it out and it improved the data. Another interesting thing is that somehow the data seems to be more consistent when moving

    posted in Pythonista read more
  • Drizzel

    I’m trying to make a small gps logger that tells me how far I ran in a given time, but it seems as if the gps data isn’t very consistent. This is a shortened version of my code:

    import location, time, math
    
    def distanceFromCoords(long1, lat1, long2, lat2): #calculate distance between two coordinates
        #convert latitude and longitude to spherical coordinates in radians
        degrees_to_radians = math.pi/180.0
        
        #phi = 90 - latitude
        phi1 = (90.0 - lat1)*degrees_to_radians
        phi2 = (90.0 - lat2)*degrees_to_radians
        
        # theta = longitude
        theta1 = long1*degrees_to_radians
        theta2 = long2*degrees_to_radians
        
        #calculate spherical distance from spherical coordinates.
        cos = (math.sin(phi1)*math.sin(phi2)*math.cos(theta1 - theta2) + math.cos(phi1)*math.cos(phi2))
        arc = math.acos(cos)
        
        # multiply arc by the radius of the earth (3960 miles or 6371 kilometers)
        return round(arc*6371*1000) #multiplied with 1000 to get meters
    
    location.start_updates() #start location updates
    
    if True:
        distance = 0 #total distance travelled
        startTime = time.time() #set starting time of timer
        
        #to calculate distances two coordinates are needed. coord1 is the coordinate I was at, and coord2 is the coordinate I am at now
        
        coord2 = (location.get_location()['longitude'],location.get_location()['latitude'])
        while True: 
            coord1 = coord2 #set coord1 to coord2 from previous loop repetition
            coord2 = (location.get_location()['longitude'],location.get_location()['latitude']) #get current coordinates
            distance += distanceFromCoords(coord1[0], coord1[1], coord2[0], coord2[1]) #add distance between coord1 and coord2 to the total distance travelled
    
            print('\n', round(time.time()-startTime), '\n', distance, '\n')
            
            time.sleep(1)
            
    location.stop_updates() #I know, this never gets executed :D
    

    If I don’t move my iPad and leave it for twenty seconds, the code tells me that I already moved about 50 meters! When doing a cooper run (you have 12 minutes time and need to run as far as possible) these 50 meters would already change my grade substantially (yeah, I’m still in school).

    Is there any better way to do this? After all most apps (runtastic, google maps ...) manage too.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!