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.


    cell.image_view Button.action

    Pythonista
    2
    15
    1918
    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 @DavinE last edited by

      @DavinE no more time today but perhaps could you post your tableview_cell_for_row delegate

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

        @DavinE try something like

        import ui
        from objc_util import *
        
        class source (object):
            def tableview_number_of_rows(self, tv, s):
                return 4
            
            def tableview_cell_for_row(self, tv, s, r):
                cell = ui.TableViewCell(style='subtitle')
                w = cell.content_view.width
                h = cell.content_view.height
                b = ui.Button()
                b.frame = (10,0,h,h)
                b.image = ui.Image.named('emj:Baby_Chick_3').with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
                def b_action(sender):
                  print('b_action')
                b.action = b_action
                cell.content_view.add_subview(b)
                x = b.x+b.width+10
                t = ui.Label()
                t.frame = (x,0,w-x,h/2)
                t.font = cell.text_label.font
                t.text = 'Title'
                cell.content_view.add_subview(t)
                st = ui.Label()
                st.font = cell.detail_text_label.font
                st.frame = (x,t.y+t.height+h/6,w-x,h/3)
                st.text = 'SubTitle'
                cell.content_view.add_subview(st)
                return cell
        
        view = ui.TableView()
        
        view.data_source = source()
        
        view.present()
        
        DavinE 3 Replies Last reply Reply Quote 0
        • DavinE
          DavinE @cvp last edited by

          @cvp said:

          @DavinE no more time today but perhaps could you post your tableview_cell_for_row delegate

                  cell = ui.TableViewCell('subtitle')
          
                  if self.requestCustomers__selectCustomerMaterialsInsert[row][2]:
                      data_textLabel = f'{self.requestCustomers__selectCustomerMaterialsInsert[row][4]}'
                  else:
                      data_textLabel = f'{self.requestCustomers__selectCustomerMaterialsInsert[row][4]}, {self.requestCustomers__selectCustomerMaterialsInsert[row][3]}'
          
                  b = ui.Button()
                  b.image = ui.Image('iow:ios7_star_outline_32')
                  cell.content_view.add_subview(b)
                  
                  # 'iow:ios7_star_32'
                  
                  cell.text_label.text = data_textLabel
                  cell.detail_text_label.text = self.requestCustomers__selectCustomerMaterialsInsert[row][5]
                  
                  # Style der cell
                  style_cell(cell, self.DEVICE, 'tableview_cell_for_row')
                  
                  return cell
          

          I had tried something in the direction but now that I see yours I would never have gotten there.....

          many many thanks

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

            @cvp said:

            @DavinE try something like

            import ui
            from objc_util import *
            
            class source (object):
                def tableview_number_of_rows(self, tv, s):
                    return 4
                
                def tableview_cell_for_row(self, tv, s, r):
                    cell = ui.TableViewCell(style='subtitle')
                    w = cell.content_view.width
                    h = cell.content_view.height
                    b = ui.Button()
                    b.frame = (10,0,h,h)
                    b.image = ui.Image.named('emj:Baby_Chick_3').with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
                    def b_action(sender):
                      print('b_action')
                    b.action = b_action
                    cell.content_view.add_subview(b)
                    x = b.x+b.width+10
                    t = ui.Label()
                    t.frame = (x,0,w-x,h/2)
                    t.font = cell.text_label.font
                    t.text = 'Title'
                    cell.content_view.add_subview(t)
                    st = ui.Label()
                    st.font = cell.detail_text_label.font
                    st.frame = (x,t.y+t.height+h/6,w-x,h/3)
                    st.text = 'SubTitle'
                    cell.content_view.add_subview(st)
                    return cell
            
            view = ui.TableView()
            
            view.data_source = source()
            
            view.present()
            

            Thanks @cvp I'll try your code :D

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

              @cvp said:

              @DavinE try something like

              import ui
              from objc_util import *
              
              class source (object):
                  def tableview_number_of_rows(self, tv, s):
                      return 4
                  
                  def tableview_cell_for_row(self, tv, s, r):
                      cell = ui.TableViewCell(style='subtitle')
                      w = cell.content_view.width
                      h = cell.content_view.height
                      b = ui.Button()
                      b.frame = (10,0,h,h)
                      b.image = ui.Image.named('emj:Baby_Chick_3').with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
                      def b_action(sender):
                        print('b_action')
                      b.action = b_action
                      cell.content_view.add_subview(b)
                      x = b.x+b.width+10
                      t = ui.Label()
                      t.frame = (x,0,w-x,h/2)
                      t.font = cell.text_label.font
                      t.text = 'Title'
                      cell.content_view.add_subview(t)
                      st = ui.Label()
                      st.font = cell.detail_text_label.font
                      st.frame = (x,t.y+t.height+h/6,w-x,h/3)
                      st.text = 'SubTitle'
                      cell.content_view.add_subview(st)
                      return cell
              
              view = ui.TableView()
              
              view.data_source = source()
              
              view.present()
              

              This works great @cvp Thank you very much

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

                @DavinE you're always welcome

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

                  @cvp Thanks very kind of you

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

                    @cvp said:

                    @DavinE try something like

                    import ui
                    from objc_util import *
                    
                    class source (object):
                        def tableview_number_of_rows(self, tv, s):
                            return 4
                        
                        def tableview_cell_for_row(self, tv, s, r):
                            cell = ui.TableViewCell(style='subtitle')
                            w = cell.content_view.width
                            h = cell.content_view.height
                            b = ui.Button()
                            b.frame = (10,0,h,h)
                            b.image = ui.Image.named('emj:Baby_Chick_3').with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)
                            def b_action(sender):
                              print('b_action')
                            b.action = b_action
                            cell.content_view.add_subview(b)
                            x = b.x+b.width+10
                            t = ui.Label()
                            t.frame = (x,0,w-x,h/2)
                            t.font = cell.text_label.font
                            t.text = 'Title'
                            cell.content_view.add_subview(t)
                            st = ui.Label()
                            st.font = cell.detail_text_label.font
                            st.frame = (x,t.y+t.height+h/6,w-x,h/3)
                            st.text = 'SubTitle'
                            cell.content_view.add_subview(st)
                            return cell
                    
                    view = ui.TableView()
                    
                    view.data_source = source()
                    
                    view.present()
                    

                    @cvp question, why doesn't it work with this code part anymore ?

                    st.number_of_lines = 0 
                    
                    cvp 1 Reply Last reply Reply Quote 0
                    • cvp
                      cvp @DavinE last edited by

                      @DavinE said

                      question, why doesn't it work with this code part anymore ?

                      Sorry, I don't understand. What does not work with this line?

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

                        @cvp said:

                        @DavinE said

                        question, why doesn't it work with this code part anymore ?

                        Sorry, I don't understand. What does not work with this line?

                        I Found my Solution:

                               cell = ui.TableViewCell(style='subtitle')
                                
                                w = cell.content_view.width
                                h = cell.content_view.height
                                
                                b = ui.Button()
                                b.frame = (10, 0, h, h)
                                b.image = ui.Image.named('iob:ios7_star_outline_32')
                                b.tint_color = b.text_color = '#F1D565'
                                
                                def b_action(sender):
                                  print('b_action')
                                  print(r)
                                b.action = b_action
                                cell.content_view.add_subview(b)
                                
                                x = b.x+b.width+10
                                
                                t = ui.Label()
                                t.frame = (x,8,(tv.width - (b.width * 2)),h/2)
                                t.font = ('Anonymous Pro', 16)
                                t.text = 'Ich bin der sehr sehr sehr lange Text um etwas zu testen ob es nun so geht oder nicht reicht der Text denn?'
                                t.number_of_lines = 0
                                t.size_to_fit()
                                cell.content_view.add_subview(t)
                                
                                st = ui.Label()
                                st.font = ('Anonymous Pro', 13)
                                st.x = x
                                st.y = t.y+t.height+h/15
                                st.width = w-x
                                st.frame = (x,t.y+t.height+h/25,(tv.width - (b.width * 2)),h/3)
                                st.text = 'Ich bin der sehr sehr sehr lange Text um etwas zu testen ob es nun so geht oder nicht reicht der Text denn?'
                                st.number_of_lines = 0
                                st.size_to_fit()
                                cell.content_view.add_subview(st)
                                
                                tv.row_height = (t.height + st.height + 19)
                                b.y = ((tv.row_height - b.height) / 2)
                                return cell 
                        

                        But I don't know if the code is written that well 😂.

                        My problem was that it does not support multiple lines

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

                          @DavinE Said

                          My problem was that it does not support multiple lines

                          The frame of both titl and subtitle are not high enough for that.

                          Problem is that y of subtitle is function of height of title and with size_to_fit, this height can increase outside of the cell

                          Try with

                                  t = ui.Label()
                                  t.frame = (x,0,(tv.width - (b.width * 2)),2*h/3)
                                  t.font = ('Anonymous Pro',14)
                                  t.text = 'Ich bin der sehr sehr sehr lange Text um etwas zu testen ob es nun so geht oder nicht reicht der Text denn?'
                                  t.number_of_lines = 0
                                  #t.size_to_fit()
                                  cell.content_view.add_subview(t)
                                  st = ui.Label()
                                  st.font = ('Anonymous Pro', 10)
                                  st.frame = (x,2*h/3,(tv.width - (b.width * 2)),h/3)
                                  st.text = 'Ich bin der sehr sehr sehr lange Text um etwas zu testen ob es nun so geht oder nicht reicht der Text denn?'
                                  st.number_of_lines = 0
                                  #st.size_to_fit()
                                  cell.content_view.add_subview(st)
                          

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

                            @cvp Ah okay, now I know why it didn't work.
                            Thank you 👍

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            Powered by NodeBB Forums | Contributors