• superrune

    Hi!

    I have done a pixel art app with Pythonista. Everything is working as it should, and the painting experience is great through Python. But I wish the app had palm rejection when I used my Apple Pencil. Does anyone know if that is possible with Pythonista?

    posted in Pythonista read more
  • superrune

    Relieved it was such a simple fix. Thanks!!

    posted in Pythonista read more
  • superrune

    Hi!

    It seems like the command ui.present(style = 'full_screen') no longer gives a full screen view but rather a windowed view in the updated Pythonista. Anyone else seen this? Is this a bug or new behaviour?

    posted in Pythonista read more
  • superrune

    Thanks @cvp! This is great!

    posted in Pythonista read more
  • superrune

    Cool, saw your answer now!! I keep replying to fast :)

    posted in Pythonista read more
  • superrune

    Cool, now most of the script seems to work as it should. Thanks again!

    I changed the text assignment to this, and now it appears where I intended:

            # Sends the selected image to the pixel Editor
            self.superview['File Label'].text = selectedFile 
    

    filePreview should exist though, should it not? I created it as an imageview a couple lines up, so is should be within the scope of the file window. Looks more like the function isnt called at all when I press the different table lines.

    Here is how it looks right now:

    import ui
    from glob import glob
    from os.path import basename
    
    class fileWindow(ui.View):
        def __init__(self):
            self.frame=(100, 150, 300, 300)
            self.name = 'File window'
            self.border_width = 2
            print ('Loader superview at init:', self.superview)
            
            imagefiles = [basename(x) for x in glob('*.*')]
    
            
            filelistData = ui.ListDataSource(imagefiles)
            filelistData.delete_enabled=False
            
            filelist = ui.TableView(frame=(10, 10 ,150, 280), data_source=filelistData, name='filelist')
            filelist.row_height = 24
            filelist.action = self.fileSelected # This does not work...
            self.add_subview(filelist)
            
            filePreview = ui.ImageView(frame=(170,10,120,100))
            filePreview.background_color = 'black'
            self.add_subview(filePreview)
            
            loadButton = ui.Button(name='Load', frame=(170,120,64,32), title='Load')
            loadButton.background_color = 'white'
            loadButton.action = self.loadAction
            self.add_subview(loadButton)
            
            ui.delay(self.x,0.01)
            
        def x(self):
            print ('Loader superview type = ', type(self.superview))
            
        def loadAction(self,sender):
            selectedFile = self['filelist'].data_source.items[self['filelist'].selected_row[1]]
            print ('Selected ' + selectedFile + ' from sender: ' + sender.name)
            # Sends the selected image to the pixel Editor
            self.superview['File Label'].text = selectedFile
            
        def fileSelected(self,sender):
            # This does not work..
            print('Gonk!!')
            filePreview.background_color = 'red'
            
    class pixelEditor(ui.View): 
        def __init__(self, width=640, height=480):
            self.bg_color = 'grey'
                
            fileButton = ui.Button(name='File', frame=(10,80,64,32), title='File:')
            fileButton.background_color = 'white'
            fileButton.action = self.openFileWindow
            self.add_subview(fileButton)
            
            fileLabel = ui.Label(frame=(100, 80, 300, 32), font=('HelveticaNeue-Light', 32), text='___')
            fileLabel.name = 'File Label'
            self.add_subview(fileLabel)
            
            print(self.superview)
            
        def openFileWindow(self, sender):
            fv = fileWindow()
            self.add_subview(fv)
            #fv.present()
            print('File window opened.')
        
    
    v = pixelEditor()
    v.present('fullscreen')
    

    posted in Pythonista read more
  • superrune

    @cvp said:

    print ('Loader superview type = ', type(self.superview))

    Thanks,

    I still have to do a fv.present() inside the openFileWindow function, right? The window will not show up otherwise...

    print ('Loader superview type = ', type(self.superview)) now returns a NoneType, though.

    I still want to put the selected file name into fileLabel.text - how would you go about doing that?

    posted in Pythonista read more
  • superrune

    Thanks, that also worked. I had the sub-window opening OK a couple steps back as well. But the next problem still remains, though, even in this version.

    I do a print ('Loader superview:', self.superview) when I init the fileWindow, to see that there is a parent view I can put the selected file into, but that still returns None. Is there a way to get the new view properly assigned as a child of the first pixelEditor view?

    edit: I see you have made a new function that prints the superview, but it returns fileWindow. So the windows parent is itself? Why is the superview not pixelEditor?

    Thanks for taking the time to help me out!!

    posted in Pythonista read more
  • superrune

    When I do that, I get the error message 'pixelEditor' object has no attribute 'openFileWindow'

    Moving the definition before the action assignment doesnt change anything either.

    posted in Pythonista read more
  • superrune

    I tried changing self to sender in the function that opens the window, but still the parent view is returned as None.

    posted in Pythonista read more
  • superrune

    I’m slowly moving closer to something that works! So I moved the open view function out of the class, and now opening the window works! So now I need to get these two windows to talk to each other. Inside the init of the file window I am printing the superview to make sure it’s actually a child, but superview returns none. So why isn’t the parent/child relationship set up, even though I am creating this as a sub view?

    #!python3
    import ui
    from glob import glob
    from os.path import basename
    
    class fileWindow(ui.View):
        def __init__(self):
            self.frame=(100, 150, 300, 300)
            self.name = 'File window'
            self.border_width = 2
            print ('Loader superview:', self.superview)
            
            imagefiles = [basename(x) for x in glob('*.*')]
            
            def loadAction(sender):
                selectedFile = imagefiles[filelist.selected_row[1]]
                print ('Selected ' + selectedFile + ' from sender: ' + sender.name)
                # Sends the selected image to the pixel Editor
                self.superview.text = selectedFile
            
            def fileSelected(sender):
                # This does not work..
                filePreview.background_color = 'red'
            
            filelistData = ui.ListDataSource(imagefiles)
            filelistData.delete_enabled=False
            
            filelist = ui.TableView(frame=(10, 10 ,150, 280), data_source=filelistData, name='filelist')
            filelist.row_height = 24
            filelist.action = fileSelected # This does not work...
            self.add_subview(filelist)
            
            filePreview = ui.ImageView(frame=(170,10,120,100))
            filePreview.background_color = 'black'
            self.add_subview(filePreview)
            
            loadButton = ui.Button(name='Load', frame=(170,120,64,32), title='Load')
            loadButton.background_color = 'white'
            loadButton.action = loadAction
            self.add_subview(loadButton)
            
    def openFileWindow(sender):
            fv = fileWindow()
            sender.add_subview(fv)
            fv.present()
            #fv = fileWindow()
            #v.present()
            print('File window opened.')
    
    class pixelEditor(ui.View): 
        def __init__(self, width=640, height=480):
            self.bg_color = 'grey'
                
            fileButton = ui.Button(name='File', frame=(10,80,64,32), title='File Window')
            fileButton.background_color = 'white'
            fileButton.action = openFileWindow
            self.add_subview(fileButton)
            
            fileLabel = ui.Label(frame=(100, 80, 300, 32), font=('HelveticaNeue-Light', 32), text='___')
            fileLabel.name = 'File Label'
            self.add_subview(fileLabel)
            
            print(self.superview)
        
        
    v = pixelEditor()
    v.present('fullscreen')
    

    posted in Pythonista read more
  • superrune

    Thanks @mikael, for explaining this to me. That makes total sense. When I do that though, I get this error:
    TypeError: openFileWindow() takes 0 positional arguments but 1 was given
    Answers on stackoverflow mention that the error occurs when you forgot to add ‘self’ to the functions inside the class, but that doesn’t seem to make any change.

    posted in Pythonista read more
  • superrune

    Thanks for answering! I’ve tried to restructure the script so that the file windows is a separate class, but it doesn’t behave quite as I expected. But views opens instantaneously, and the buttons don’t seem to work. Any pointers?

    #!python3
    import ui
    from glob import glob
    from os.path import basename
    
    class fileWindow(ui.View):
        def __init__(self, frame=(100, 150, 300, 300)):
            self.name = 'File window'
            self.border_width = 2
            
            imagefiles = [basename(x) for x in glob('*.*')]
            
            def loadAction(sender):
                selectedFile = imagefiles[filelist.selected_row[1]]
                print ('Selected ' + selectedFile + ' from sender: ' + sender.name)
                # Sends the selected image to the pixel Editor
                self.subviews[1].text = selectedFile
            
            def fileSelected(sender):
                # This does not work..
                filePreview.background_color = 'red'
            
            filelistData = ui.ListDataSource(imagefiles)
            filelistData.delete_enabled=False
            
            filelist = ui.TableView(frame=(10, 10 ,150, 280), data_source=filelistData, name='filelist')
            filelist.row_height = 24
            filelist.action = fileSelected # This does not work...
            self.add_subview(filelist)
            
            filePreview = ui.ImageView(frame=(170,10,120,100))
            filePreview.background_color = 'black'
            self.add_subview(filePreview)
            
            loadButton = ui.Button(name='Load', frame=(170,120,64,32), title='Load')
            loadButton.background_color = 'white'
            loadButton.action = loadAction
            self.add_subview(loadButton)
            
    
    class pixelEditor(ui.View): 
        def __init__(self, width=640, height=480):
            self.bg_color = 'grey'
    
            def openFileWindow():
                fv = fileWindow()
                fv.present()
                print('File window opened.')
                
            fileButton = ui.Button(name='File', frame=(10,80,64,32), title='File Window')
            fileButton.background_color = 'white'
            fileButton.action = openFileWindow()
            self.add_subview(fileButton)
            
            fileLabel = ui.Label(frame=(100, 80, 300, 32), font=('HelveticaNeue-Light', 32), text='___')
            fileLabel.name = 'File Label'
            self.add_subview(fileLabel)
            
            print(self.superview)
        
        
    v = pixelEditor()
    v.present('fullscreen')     
        ```

    posted in Pythonista read more
  • superrune

    Hi!

    I am trying to get better in Python/Pythonista by doing a pixel paint app. I have some problems understanding communication between views, nested and otherwise, and I was hoping you might have some suggestion to how I can make my code more elegant.

    My paint app is built up from views, there is an editor view at the "root" holding the image and tool buttons. What I want to do, is to open a file selector view on top of this, that does stuff with the editor view "below". For that I need the file view to access variables and functions that belong to the root editor.

    Right now, I have nested everything. The editor functions are inside the editor class, and the file view is a function of the editor class. Also, the file view functions are nested inside the file view function itself. But this feels real messy to me, and I'd rather have the file window as a separate class that is outside of the editor. But I'm not sure how to let the communicate back to the editor!

    I have made a super-simplified example of how my app works. Can anybody take a quick look and give me some hints?

    #!python3
    import ui
    from glob import glob
    from os.path import basename
    
    class pixelEditor(ui.View):
        
        def fileWindow(self, sender):
            fileWindow = ui.View(frame=(100, 150, 300, 300), name='File window', border_width=2)
            imagefiles = [basename(x) for x in glob('*.*')]
            
            def loadAction(sender):
                # Dummy for the function that loads the image into the editor
                selectedFile = imagefiles[filelist.selected_row[1]]
                print ('Selected ' + selectedFile + ' from sender: ' + sender.name)
                # Sends the selected image to the pixel Editor
                self.subviews[1].text = selectedFile
            
            def fileSelected(sender):
                filePreview.background_color = 'red'
            
            filelistData = ui.ListDataSource(imagefiles)
            filelistData.delete_enabled=False
            
            filelist = ui.TableView(frame=(10, 10 ,150, 280), data_source=filelistData, name='filelist')
            filelist.row_height = 24
            filelist.action = fileSelected # Does not work...
            fileWindow.add_subview(filelist)
            
            filePreview = ui.ImageView(frame=(170,10,120,100))
            filePreview.background_color = 'black'
            fileWindow.add_subview(filePreview)
            
            loadButton = ui.Button(name='Load', frame=(170,120,64,32), title='Load')
            loadButton.background_color = 'white'
            loadButton.action = loadAction
            fileWindow.add_subview(loadButton)
            
            self.add_subview(fileWindow)
            print('File window opened.')
            
            
        def __init__(self, width=640, height=480):
            self.bg_color = 'grey'
        
            fileButton = ui.Button(name='File', frame=(10,80,64,32), title='File Window')
            fileButton.background_color = 'white'
            fileButton.action = self.fileWindow
            self.add_subview(fileButton)
            
            fileLabel = ui.Label(frame=(100, 80, 300, 32), font=('HelveticaNeue-Light', 32), text='___')
            fileLabel.name = 'File Label'
            self.add_subview(fileLabel)
            
            print(self.superview)
        
        
    v = pixelEditor()
    v.present('fullscreen')
    

    posted in Pythonista read more
  • superrune

    Using console.open_in(filename) worked great. Took some attempts before I realized I had to write the file locally/inside Pythonista first :)

    Is there an equally simple way to programmatically load a file from a selection of sources, like Dropbox, iCloud etc?

    posted in Pythonista read more
  • superrune

    Thanks for all the answers! I will try out the different ones and see which one works best. Cheers!

    posted in Pythonista read more
  • superrune

    Hi! Pardon me if this has been asked, I could not find it in the search.

    I have made a drawing app that is working quite well. One thing I have not solved is the loading and saving of images, and instead of loading and saving from Camera Roll, I thought it would be better to save them to iCloud or Dropbox. Can Pythonista open a file requester to let the user save to the new Files system in iOS 11?

    posted in Pythonista read more
  • superrune

    Hi,

    I'm learning both Python an Pythonista, so I'm not sure if this is a bug. I`m editing a pyui file that I downloaded on github, but when I'm editing a subview (or a subviews subview!), it very often resets to how it was before editing when I return to a parent level. It's extremely frustrating, especially after spending some doing fine edits. On some views, I had to edit the UI files as JSON in order to complete the edit. By the way, it would be great to have a button to quickly switch back and forth between text and graphical UI editing.

    Thanks!

    posted in Pythonista read more
  • superrune

    Fantastic! Thanks for going through the code, this is super-helpful. Thanks again!

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!