• DavinE

    @cvp, @ccc
    Thank you very much, try; except I had not thought 🙈

    posted in Pythonista read more
  • DavinE

    Hi guys,

    I have a problem when using the camera.
    I have used the following code which I had from here:

    def scanner_app(self, label_text):
            #FUNKTION captureOutput_didOutputMetadataObjects_fromConnection_
            def captureOutput_didOutputMetadataObjects_fromConnection_(_self, _cmd, _output, _metadata_objects, _conn):
                global scannerCode
                objects = ObjCInstance(_metadata_objects)
                for obj in objects:
                    s = str(obj.stringValue())
                    if s not in scannerCode:
                        scannerCode = s
                scannerView.close()
    
            global scannerCode
            scannerCode = ''
    
            AVCaptureSession = ObjCClass('AVCaptureSession')
            AVCaptureDevice = ObjCClass('AVCaptureDevice')
            AVCaptureDeviceInput = ObjCClass('AVCaptureDeviceInput')
            AVCaptureMetadataOutput = ObjCClass('AVCaptureMetadataOutput')
            AVCaptureVideoPreviewLayer = ObjCClass('AVCaptureVideoPreviewLayer')
            dispatch_get_current_queue = c.dispatch_get_current_queue
            dispatch_get_current_queue.restype = c_void_p
            
            MetadataDelegate = create_objc_class('MetadataDelegate', methods=[captureOutput_didOutputMetadataObjects_fromConnection_], protocols=['AVCaptureMetadataOutputObjectsDelegate'])
            
            delegate = MetadataDelegate.new()
            scannerView = ui.View(frame=(0, 0, self.WIDTH, self.HEIGHT))
            scannerView.name = 'QR Code Scannen'
            session = AVCaptureSession.alloc().init()
            device = AVCaptureDevice.defaultDeviceWithMediaType_('vide')
            _input = AVCaptureDeviceInput.deviceInputWithDevice_error_(device, None)
            if _input:
                session.addInput_(_input)
            else:
                print('Failed to create input')
                return
            output = AVCaptureMetadataOutput.alloc().init()
            queue = ObjCInstance(dispatch_get_current_queue())
            output.setMetadataObjectsDelegate_queue_(delegate, queue)
            session.addOutput_(output)
            output.setMetadataObjectTypes_(output.availableMetadataObjectTypes())
            prev_layer = AVCaptureVideoPreviewLayer.layerWithSession_(session)
            prev_layer.frame = ObjCInstance(scannerView).bounds()
            prev_layer.setVideoGravity_('AVLayerVideoGravityResizeAspectFill')
            ObjCInstance(scannerView).layer().addSublayer_(prev_layer)
            label = ui.Label(frame=(0, 0, self.WIDTH, 30), flex='W', name='label')
            label.background_color = (0, 0, 0, 0.5)
            label.text_color = '#ffffff'
            label.text = label_text
            label.alignment = ui.ALIGN_CENTER
            scannerView.add_subview(label)
            session.startRunning()
            scannerView.present('fullscreen')
            scannerView.wait_modal()
            session.stopRunning()
            delegate.release()
            session.release()
            output.release()
            scannerView.close()
            return scannerCode 
    

    As you can see in this video:
    https://imgur.com/a/VDNN8A1

    Crashes the camera immediately call again....
    The problem I have with an iPhone 11 Pro IOS 15.6.1 on my other iPhone XS IOS 15.6.1 it goes without problems....

    Maybe someone can take a look at the problem and help me.

    Thanks in advance!

    posted in Pythonista read more
  • DavinE

    @cvp said:

    @DavinE please, try as method of an ui.View

      def get_screen_size(self):              
          app = UIApplication.sharedApplication().keyWindow() 
          for window in UIApplication.sharedApplication().windows():
              ws = window.bounds().size.width
              hs = window.bounds().size.height
              break
          return ws,hs
    

    @cvp my friend, this works wonderfully

    Thanks a lot :D

    posted in Pythonista read more
  • DavinE

    Hi guys,

    I need some help for my code example....
    I am using ui.get_screen_size() to get my width and height.... but when i use the iPad in split screen the width and height is not correct... in my case both 1366 (width)

    Is there a way to solve this here ?

    posted in Pythonista read more
  • DavinE

    @cvp said:

    @ihf I'm back from vacation but I brought the Covid with me 😢, thus I'll need some time before I'm really back on the ScrollView version.

    Get well soon @cvp

    posted in Pythonista read more
  • DavinE

    @JonB said:

    Are you pulling the data from MySQL from your datasource ? Why not set up your query so you get a sorted list.

    Or, are you passing in a list? In that case, just use sort or sorted instead before assigning to your datasource items.

    If the issue is that you have
    1
    10
    2

    And you want these sorted as numbers, rather than as alphabetical strings, then you need to sort on a key that converts to int first.

    i missed: ORDER BY barcode ASC lol....

    this works now.

    posted in Pythonista read more
  • DavinE

    I have two other Questions for it.

    Pic

    1. Is it possible to sort the Numbers correctly ? Image: 30/00001 then 30/00070 ?
    2. Can i set the TableView Height to my Keyboard ?

    posted in Pythonista read more
  • DavinE

    @cvp said:

    @DavinE said

    But the whole thing is displayed in the Console

    You only have to replace 'panel' by 'fullscreen' and display will be done in normal ui.View

    oh, okay if that's all it is, I'll take a look.

    posted in Pythonista read more
  • DavinE

    @JonB said:

    @cvp you might consider a search controller, which behaves the way one expects in iOS

    https://github.com/tdamdouni/Pythonista/blob/master/_2017/SearchableTable.py

    Yes that is of course nicer...
    But the whole thing is displayed in the Console... and I can not really understand the whole thing 🙈
    So that a customization would be modest for me....
    Will test it with @cvp's example and try.

    posted in Pythonista read more
  • DavinE

    @cvp said:

    @DavinE please try this quick and dirty example

    import ui
    
    class MyView(ui.View):
      def __init__(self,w,h):
          self.width = w
          self.height = h
          
          # init existing codes
          self.codes = ['1','2','25','2587','2549','256625/10000','3','33','4','44/45']
          
          # TextField for search
          search_width = self.width - 100
          search_text = ui.TextField(name='search_text')
          search_text.text = ''
          search_text.width = search_width - 100
          search_text.height = 32
          search_text.x = (self.width - search_width)/2
          search_text.y = 10
          search_text.border_color = 'blue'
          search_text.border_width = 3
          search_text.text_color = 'blue'
          search_text.keyboard_type = ui.KEYBOARD_DEFAULT
          search_text.autocorrection_type = False
          search_text.alignment = ui.ALIGN_LEFT
          search_text.clear_button_mode = 'while_editing'
          search_text.font= ('Helvetica',20)
          search_text.delegate = self
          self.add_subview(search_text)
          
          # ListDataSource for search TableView
          found_codes = ui.TableView(name='found_codes')
          found_codes.allows_multiple_selection = False
          found_codes.text_color = 'black'
          found_codes.font= ('Courier',12)
          found_codes.row_height = 50
          found_codes.x = search_text.x
          found_codes.y = search_text.y + search_text.height + 10
          found_codes.width = search_width
          found_codes.height = self.height - 130
          found_codes.border_color = 'blue'
          found_codes.border_width = 3
          found_codes.data_source = ui.ListDataSource(items=[])
          self.add_subview(found_codes)
          
      def textfield_did_change(self, field):
          txt = field.text
          lst = []
          for code in self.codes:
              if txt and code.startswith(txt):
                  lst.append(code)
          self['found_codes'].data_source.items = lst
    
    def main():
      w, h = ui.get_screen_size()
      my_back = MyView(w,h)
      my_back.background_color='white'
      my_back.name = 'for @DavinE'
      my_back.present('fullscreen',hide_title_bar=False)
    
    # Protect against import  
    if __name__ == '__main__':
      main()
    

    Yes, that's exactly what I meant.
    With it I can try the days once around 👍

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!