omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    Containers for photos, with scroll, drag&drop between them

    Pythonista
    2
    47
    16767
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cvp
      cvp last edited by

      See also PhotosPickerView.py

      jmv38 2 Replies Last reply Reply Quote 0
      • jmv38
        jmv38 @cvp last edited by

        @cvp thanks for the 2nd example, it is inspiring.

        Actually i dont use grids i prefer to place and zoom and cut each photo manually.

        If you put your whole program in github i certainly wont demand support!

        I think I’ll post my work step by step in gists and this forum as I progress. Not sure how fast I’ll go though...

        Btw, I am french too (Grenoble) so no pb with the langage. I’ll continue anyway to write in english by respect for people in this forum.

        Thanks.

        cvp 1 Reply Last reply Reply Quote 0
        • jmv38
          jmv38 @cvp last edited by

          @cvp from the doc, it seems the tableView is vertical only. Is there a way to have is horizontal too? Initially i wanted my camera roll container to be vertical, but the photo group containers to be horizontal (and themselves inside a scrollable vertical container too).
          So i should pbly use a scrollview instead for my base photo container?

          1 Reply Last reply Reply Quote 0
          • jmv38
            jmv38 @cvp last edited by

            @cvp mmm PhotosPickerView.py seems a bit over my head, with all this objC functions...

            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @jmv38 last edited by

              @jmv38 said:

              f you put your whole program in github i certainly wont demand support!

              here

              jmv38 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @jmv38 last edited by

                @jmv38 said:

                seems a bit over my head, with all this objC functions...

                It is not so complex as it seems...

                1 Reply Last reply Reply Quote 0
                • jmv38
                  jmv38 @cvp last edited by

                  @cvp thanks for juxtapositionDePhotos.py
                  all the bricks i need are there
                  => this is really going to help me.
                  thanks.

                  cvp 1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @jmv38 last edited by

                    @jmv38 quick and dirty horizontal scroll view

                    import photos
                    import ui
                    
                    def main():
                    	assets = photos.get_assets()
                    	#assets = photos.pick_asset(assets=assets,multi=True)
                    	d = 100
                    	wsv = min(400,d * len(assets))
                    	sv = ui.ScrollView()
                    	sv.frame = (0,0,wsv,d)
                    	x = 0
                    	for i in range(0,len(assets)):
                    		b = ui.Button(name=str(i))
                    		#b = ui.ImageView(name=str(i))
                    		b.border_color = 'blue'
                    		b.border_width = 1
                    		ui_image = assets[i].get_ui_image().with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
                    		w,h = ui_image.size
                    		w = d * w/h
                    		b.frame = (x,0,w,d)
                    		b.image = ui_image
                    		def b_action(sender):
                    			sender.superview.name = 'tapped=' + sender.name
                    		b.action = b_action
                    		sv.add_subview(b)
                    		x = x + w
                    	sv.content_size = (x,d)
                    	sv.present('sheet')
                    
                    if __name__ == '__main__':
                    	main()
                    

                    jmv38 1 Reply Last reply Reply Quote 0
                    • jmv38
                      jmv38 @cvp last edited by

                      @cvp excellent! thanks.
                      It is nice to have the function in a really small piece of code.
                      I had to limit the number of photos because i have 1600 and that crashes my app. I’ll manage that.

                      Another thing: for the interractions between panels i learned (from coding in Codea) that it is much easier to wire things together via a register/trigger message system. Do you have something available?

                      cvp 2 Replies Last reply Reply Quote 0
                      • cvp
                        cvp @jmv38 last edited by

                        @jmv38 said:

                        it is much easier to wire things together via a register/trigger message system. Do you have something available?

                        No, never done like that. I always use normal way of ui. Good luck

                        1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @jmv38 last edited by

                          @jmv38 said:

                          limit the number of photos because i have 1600

                          Perhaps, use collections or get_moments

                          jmv38 1 Reply Last reply Reply Quote 0
                          • jmv38
                            jmv38 @cvp last edited by jmv38

                            @cvp here an example of a very simple event class i found on google and modified for my needs. I also added an example of usage.

                            class EventHook(object):
                            
                                def __init__(self):
                                    self.__handlers = []
                            
                                def __iadd__(self, handler):
                                    self.__handlers.append(handler)
                                    return self
                            
                                def __isub__(self, handler):
                                    self.__handlers.remove(handler)
                                    return self
                            
                                def __call__(self, *args, **keywargs):
                                    for handler in self.__handlers:
                                        handler(*args, **keywargs)
                            
                                def clearObjectHandlers(self, inObject):
                                    for theHandler in self.__handlers:
                                        if theHandler.im_self == inObject:
                                            self -= theHandler
                                            
                            if __name__ == '__main__':
                              class Watcher():
                                  def __init__(self):
                                      self.incoming = EventHook()
                                      self.leaving = EventHook()
                              
                              class Greeter():
                                def __init__(self,me):
                                  self.me = me
                                def sayHello(self, name):
                                  print('{}: hello Mister {}'.format(self.me,name))
                                def sayGoodbye(self, name):
                                  print('{}: goobye Mister {}'.format(self.me,name))
                                  
                              class Maid():
                                def __init__(self,me):
                                  self.me = me
                                def sayHello(self, name):
                                  print('{}: hello Mister {}'.format(self.me,name))
                                def sayGoodbye(self, name):
                                  if name != 'DSK':
                                    print('{}: goobye Mister {}'.format(self.me,name))
                                  else:
                                    print('{}: You f... s.. o. a b...!'.format(self.me))
                              
                              from console import clear
                              clear()
                              Isee = Watcher()
                              deskMan = Greeter('desk man Georges')
                              maid = Maid('maid Sandra')
                              
                              # make the connections:
                              Isee.incoming += lambda name: print('\nM. {} is comming...'.format(name))
                              Isee.incoming += deskMan.sayHello
                              Isee.incoming += maid.sayHello
                              
                              Isee.leaving += lambda name: print('\nM. {} is leaving...'.format(name))
                              Isee.leaving += maid.sayGoodbye
                              Isee.leaving += deskMan.sayGoodbye
                              
                              # remove listener from the event
                              
                              # fire event
                              Isee.incoming('Clinton')
                              Isee.leaving('Clinton')
                            
                              
                            
                            cvp 1 Reply Last reply Reply Quote 0
                            • cvp
                              cvp @jmv38 last edited by

                              @jmv38 Too complex for me 😀

                              jmv38 2 Replies Last reply Reply Quote 0
                              • jmv38
                                jmv38 @cvp last edited by

                                @cvp i can understand what you feel: it is exactly what i thought the first time saw this! It took me several months to start to understand it, but once i did, bam!, it opened a huge box of possibilties because it made a complex project so much simpler. But I wont try to convert you, you’ll see for yourself as i use it in my project if you think it is usefull...
                                Thanks.

                                1 Reply Last reply Reply Quote 0
                                • jmv38
                                  jmv38 @cvp last edited by

                                  @cvp i am in the final polishing phase of my project.
                                  I have pb with button icons: they render in color when i want a gray rendering (the one shown in the editor).
                                  my code:

                                  img = ui.Image('iow:refresh_32').with_rendering_mode(ui.RENDERING_MODE_TEMPLATE)
                                      clear_button.image = img
                                  

                                  any suggestion?
                                  thanks.

                                  cvp 2 Replies Last reply Reply Quote 0
                                  • cvp
                                    cvp @jmv38 last edited by

                                    @jmv38 did you try ui.RENDERING_MODE_ORIGINAL

                                    1 Reply Last reply Reply Quote 0
                                    • cvp
                                      cvp @jmv38 last edited by

                                      @jmv38 this is ok, I think

                                      img = ui.Image('iow:refresh_32')#.with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
                                      b.image = img
                                      b.tint_color = 'gray'
                                      
                                      jmv38 2 Replies Last reply Reply Quote 0
                                      • jmv38
                                        jmv38 @cvp last edited by

                                        @cvp thanks.
                                        but it still doesnt work: now the button shows in gray, not white, and is not visible on my gray background.
                                        I wonder how to get it simply as it shows in the editor?

                                        cvp 1 Reply Last reply Reply Quote 0
                                        • jmv38
                                          jmv38 @cvp last edited by

                                          @cvp you know what? it works with ORIGINAL
                                          looks like omz inverted TEMPLATE and ORIGINAL values
                                          thanks.

                                          1 Reply Last reply Reply Quote 0
                                          • cvp
                                            cvp @jmv38 last edited by

                                            @jmv38 said:

                                            but it still doesnt work: now the button shows in gray, not white, and is not visible on my gray background.
                                            I wonder how to get it simply as it shows in the editor?

                                            You asked gray and I didn't know you had a gray background

                                            jmv38 2 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors