omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. tlinnet

    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.


    • Profile
    • Following 0
    • Followers 0
    • Topics 8
    • Posts 32
    • Best 0
    • Controversial 0
    • Groups 0

    tlinnet

    @tlinnet

    0
    Reputation
    1208
    Profile views
    32
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    tlinnet Unfollow Follow

    Latest posts made by tlinnet

    • RE: App was accepted in iTunes store

      I made it with pythonista 3.

      Using the template for Xcode (found on github)
      deleted unnessary files, and finally updating objc_util.py in the template folder (look in site packages) with the copy from pythonista on phone.

      posted in Pythonista
      tlinnet
      tlinnet
    • Anyone with experience in text recognition?

      So, I was thinking of a chemistry app.

      With a similar interface as this:
      https://phet.colorado.edu/en/simulation/balancing-chemical-equations

      But, of course the student should be able to use his/her own chemistry equation to balance.

      That could be an input text field, OR, take a picture of the equation, and then text
      recognition.

      Anyone with experience in this? :)

      posted in Pythonista
      tlinnet
      tlinnet
    • App was accepted in iTunes store

      Hi!

      I just wan't to tell, that my very first app was just accepted in iTunes store.

      I could not have done it without you!

      1. Thanks for getting help to access the printning utility.

      2. Thanks for fixing the IPv6 issue ! That was a app killer. ;)

      So now I have tried the whole path from idea to App release. Now it is time to get better ideas :)

      Merry Christmas

      posted in Pythonista
      tlinnet
      tlinnet
    • RE: Action on cell, when clicked in table?

      I ended up with this, which functions as expected.

      # Create a tableview, with data
      self.tv = ui.TableView()
      self.tv.row_height = 30
      self.tv.data_source = MyTableViewDataSource(self.tv.row_height)
      self.tv.delegate = MyTableViewDelegate()
      
      # Update tableview data
      self.tv.data_source.items = sorted(self.c.read_vouchers(), key=itemgetter(0), reverse=True)
      
      # Do not allow selection on the TableView
      #self.tv.allows_selection = False
      self.tv.allows_selection = True
      
      # Add the table
      self.add_subview(self.tv)
      
      
      # Define the class for the Table Data
      class MyTableViewDataSource(object):
          def __init__(self, row_height):
              self.row_height = row_height
              self.width = None
      
          def tableview_number_of_rows(self, tableview, section):
              return len(tableview.data_source.items)
      
          def tableview_cell_for_row(self, tableview, section, row):
              self.width, height = ui.get_screen_size()
              cell = ui.TableViewCell()
              cell.bounds = (0, 0, self.width, self.row_height)
              for i in range(3):
                  self.make_labels(cell, tableview.data_source.items[row][i], i)
              return cell
      
          def make_labels(self, cell, text, pos):
              label = ui.Label()
              label.border_color = 'lightgrey'
              label.border_width = 0.5
              label.text = str(text)
              if pos == 0:
                  label.frame = (self.width*0/5, 0, self.width/5, self.row_height)
              elif pos == 1:
                  label.frame = (self.width*1/5, 0, self.width*2/5, self.row_height)
              elif pos == 2:
                  label.frame = (self.width*3/5, 0, self.width*2/5, self.row_height)
              label.alignment = ui.ALIGN_CENTER
              cell.content_view.add_subview(label)
      
      class MyTableViewDelegate(object):
          @ui.in_background
          def tableview_did_select(self, tableview, section, row):
              select_voucher_index, select_voucher = tableview.data_source.items[row][:2]
              Common().write_config('select_voucher_index', select_voucher_index)
              Common().write_config('select_voucher', select_voucher)
              MyTableView().refresh_last_voucher()```
      posted in Pythonista
      tlinnet
      tlinnet
    • Action on cell, when clicked in table?

      Hi.

      I have a table. It contains 3 columns.
      I would like to make an interaction.

      When I click a row in the table, the 3 column information should be stored in a dict.

      # Create a tableview, with data
      self.tv = ui.TableView()
      self.tv.row_height = 30
      self.tv.data_source = MyTableViewDataSource(self.tv.row_height)
      #self.tv.delegate = MyTableViewDelegate()
      
      # Update tableview data
      self.tv.data_source.items = sorted(self.c.read_vouchers(), key=itemgetter(0), reverse=True)
      
      # Do not allow selection on the TableView
      self.tv.allows_selection = False
      #self.tv.allows_selection = True
      
      # Add the table
      self.add_subview(self.tv)
      

      And class

      class MyTableViewDataSource(object):
          def __init__(self, row_height):
              self.row_height = row_height
              self.width = None
      
          def tableview_number_of_rows(self, tableview, section):
              return len(tableview.data_source.items)
      
          def tableview_cell_for_row(self, tableview, section, row):
              self.width, height = ui.get_screen_size()
              cell = ui.TableViewCell()
              cell.bounds = (0,0,self.width,self.row_height)
              for i in range(3):
                  self.make_labels(cell, tableview.data_source.items[row][i], i)
              return cell
      
          def make_labels(self, cell, text, pos):
              label = ui.Label()
              label.border_color = 'lightgrey'
              label.border_width = 0.5
              label.text = str(text)
              if pos == 0:
                  label.frame = (self.width*0/5, 0, self.width/5, self.row_height)
      
              elif pos == 1:
                  label.frame = (self.width*1/5, 0, self.width*2/5, self.row_height)
      
              elif pos == 2:
                  label.frame = (self.width*3/5, 0, self.width*2/5, self.row_height)
      
      
              label.alignment = ui.ALIGN_CENTER
              cell.content_view.add_subview(label)
      
      #class MyTableViewDelegate(object):
      #    def tableview_did_select(self, tableview, section, row):
      #        print 'select'
      #    def tableview_did_deselect(self, tableview, section, row):
      #        print 'deselect'
      

      How would I do this?

      posted in Pythonista
      tlinnet
      tlinnet
    • RE: Use objc_util and NSURLConnection to make a GET request

      And now the last modification..

      Making exceptions work as well.

      https://gist.github.com/tlinnet/aff5decf31d07d0c0cccfad7961353f7

      posted in Pythonista
      tlinnet
      tlinnet
    • RE: Use objc_util and NSURLConnection to make a GET request

      I got it to work with, headers, ios basic authentication and parameters, and saving the response.

      Thanks!

      https://gist.github.com/tlinnet/31b35136e206ea2b4829a13799c89316

      posted in Pythonista
      tlinnet
      tlinnet
    • RE: Use objc_util and NSURLConnection to make a GET request

      Now getting a return.

      Don't know how to exactly to implement a "wait", but here is a try

      import objc_util
      from urlparse import urlparse
      from urllib import urlencode
      from ctypes import c_void_p
      import time
      
      class Web(object):
          def __init__(self, url=None, params=None):
              self.data = None
      
              if params:
                  params_encoded = urlencode(params)
              else:
                  params_encoded = ""
              url = objc_util.nsurl("{}?{}".format(url, params_encoded))
              request = objc_util.ObjCClass("NSURLRequest").request(URL=url)
              configuration = objc_util.ObjCClass("NSURLSessionConfiguration").defaultSessionConfiguration()
          
              session = objc_util.ObjCClass("NSURLSession").session(Configuration=configuration)
          
              completionHandler = objc_util.ObjCBlock(self.responseHandlerBlock, restype=None, argtypes=[c_void_p, c_void_p, c_void_p, c_void_p])
              objc_util.retain_global(completionHandler)
          
              dataTask = session.dataTask(Request=request, completionHandler=completionHandler)
              dataTask.resume()
      
          def responseHandlerBlock(self, _cmd, data, response, error):
              if error is not None:
                  error = objc_util.ObjCInstance(error)
                  print(error)
                  return
              response = objc_util.ObjCInstance(response)
              data = objc_util.ObjCInstance(data)
              self.data = (str(objc_util.nsdata_to_bytes(data)))
      
          def return_data(self):
              return self.data
      
      
      url = "http://validate.jsontest.com"
      params = {"json" : {"first" : "lukas", "last" : "kollmer"}}
      
      #validate(url, None, responseHandlerBlock)
      #validate(url, params, responseHandlerBlock)
      call = Web(url, params)
      
      wait = True
      while wait:
          data = call.return_data()
          if data != None:
              print data
              wait = False
      print "Done"```
      posted in Pythonista
      tlinnet
      tlinnet
    • RE: Use objc_util and NSURLConnection to make a GET request

      WOW!!!!

      Thanks! :)
      This works as expected. :)

      I get a json back, I can work with.
      I will try to implement this, and see if it passes the Apple review.

      Thanks!

      import objc_util
      from urlparse import urlparse
      from urllib import urlencode
      from ctypes import c_void_p
      
      NSURLRequest = objc_util.ObjCClass("NSURLRequest")
      NSURLSession = objc_util.ObjCClass("NSURLSession")
      NSURLSessionConfiguration = objc_util.ObjCClass("NSURLSessionConfiguration")
      
      def validate(url, params, responseHandler):
          if params:
              params_encoded = urlencode(params)
          else:
              params_encoded = ""
          url = objc_util.nsurl("{}?{}".format(url, params_encoded))
          request = NSURLRequest.request(URL=url)
          configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
          
          session = NSURLSession.session(Configuration=configuration)
          
          completionHandler = objc_util.ObjCBlock(responseHandler, restype=None, argtypes=[c_void_p, c_void_p, c_void_p, c_void_p])
          objc_util.retain_global(completionHandler)
          
          dataTask = session.dataTask(Request=request, completionHandler=completionHandler)
          dataTask.resume()
      
      def responseHandlerBlock(_cmd, data, response, error):
          if error is not None:
              error = objc_util.ObjCInstance(error)
              print(error)
              return
          response = objc_util.ObjCInstance(response)
          data = objc_util.ObjCInstance(data)
          print(str(objc_util.nsdata_to_bytes(data)))
      
      url = "http://validate.jsontest.com"
      params = {"json" : {"first" : "lukas", "last" : "kollmer"}}
      
      #validate(url, None, responseHandlerBlock)
      validate(url, params, responseHandlerBlock)
      
      posted in Pythonista
      tlinnet
      tlinnet
    • RE: Use objc_util and NSURLConnection to make a GET request

      I am here at the moment

      from objc_util import *
      
      class Web(object):
          def __init__(self, root=None, method=None, headers=None):
              #NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
              self.request = ObjCClass('NSMutableURLRequest').alloc().initWithURL_(nsurl(root))
              #[request setHTTPMethod:@"POST"];
              self.request.setHTTPMethod_(method)
      
              # Make headers
              for key in headers:
                  #[request setValue:@"es" forHTTPHeaderField:@"Accept-Language"];
                  self.request.setValue_forHTTPHeaderField_(key, headers[key])
      
              # Make request
              #NSURLConnection * theConnection = [[NSURLConnection alloc] initWithRequest:imageRequest delegate:self];
              #self.conn = ObjCClass('NSURLConnection').alloc().initWithRequest_delegate_(self.request, self)
              self.conn = ObjCClass('NSURLConnection').alloc().initWithRequest_delegate_startImmediately_(self.request, self, True)
      
              #[connection autorelease];
              self.conn.autorelease()
      

      But I dont know how to unpack or return the request?
      So I get the response from the server?

      posted in Pythonista
      tlinnet
      tlinnet