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.


    UniPAGe as a bridge between Kivy and Pythonista

    Pythonista
    10
    32
    31476
    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.
    • Ti Leyon
      Ti Leyon last edited by

      Hey @brumm if you wrote “PhoneManager.py” I am sorry for the mixup. It must be “GitHubGet.py” that I got from @JonB. These are the only two scripts from this forum that I modified and use occasionally. They are both very handy. As far as the “julia geeks” license is concerned I created it because it seems ridiculous that people want to officially license this little bit of code. This is more a proof of concept than a finished product that requires licensing. However, since someone wanted to take that step I had to counteract and “julia geeks” fits my intent perfectly: “look, learn and go do better”. There are no laws or even rules that forces a license to provide for commercial use. By the way, a copyright suffice and is well defined and protected by states and international laws.

      1 Reply Last reply Reply Quote 0
      • dgelessus
        dgelessus last edited by

        @tileyon If you don't provide a license and only add a copyright statement, then you're not actually allowing anyone to use your code. To run your code, the user has to copy or download it, which would be against the copyright. That's why a proper license is important, otherwise nobody is legally allowed to use your code.

        As far as I can tell, currently your license doesn't allow people to download your code. I'm not a lawyer though. If you really want to write your own license, you should get in contact with a lawyer to make sure that the license legally means what you expect it to mean.

        In almost all cases it's safer, easier and more useful to use an existing well-known open-source license, especially if you want others to contribute to your code. The https://choosealicense.com/ site from GitHub (which I linked to before) gives a good short overview. This and this page on the GNU website are also interesting, but they are of course biased towards copyleft licenses like the GPL. Unlike what they sometimes suggest, it's fine to use a less restrictive license (MIT, Apache, BSD, etc.).

        1 Reply Last reply Reply Quote 1
        • Ti Leyon
          Ti Leyon last edited by

          Relax @dgelessus this not a capital case. We do not need to bring layers in this, they will steal the fun. Licenses are just stipulations that broaden the scope of a copyright or patent. julia geeks allows you to improve and extend the code and to do so you must be able to download it. The fact is I never intended to put any kind of restriction on its use until licensing was mentioned by other parties under terms that were unacceptable to me. I thank you for your judicious suggestions and I will look into the matter. In the meantime anyone can download, experiment and improve UniPAGe regardless of their perception of julia geeks

          1 Reply Last reply Reply Quote 0
          • Niall
            Niall last edited by

            @Ti-Leyon
            Capital cases, lawyers be damned. You say this:
            "In the unfortunate event that the material should be reproduced, transformed or otherwise manipulated in whole or in parts then current local, state and international copyright laws should apply."

            What that means is that I can submit changes to your Git repository, but I can't actually any software with it built in, as that would be "reproduction". Thus any code I wrote with it would only be issuable in source form, for people who run a Python interpreter and who install your gui wrapper themselves.

            That means that I can't develop a package in Pythonista using it and then package it in XCode.
            It means I can't compile the package into an Android.apk or a Windows .exe .

            There is little point in me learning your API if I'm never going to be able to use it beyond tinkering for my own interest -- and if I'm tinkering for my own interest, then cross-platform dev clearly isn't a big issue and in the end I'd be just as well sticking with Pythonista ui or Kivy.

            1 Reply Last reply Reply Quote 0
            • Niall
              Niall @abcabc last edited by Niall

              @abcabc
              The only wrinkle with your approach is that it would be too easy to work away on Pythonista and build up a working UI, only to forget which methods were available in the cross-platform version.

              The way I would solve this is by renaming the package (eg pythonistaui, and having two versions -- a Pythonista one and a Kivy one. The job of the Pythonista package would be to simply throw an error any time you tried to use something that isn't implemented in the Kivy version.

              In its simplest version, it would just be a list of imports, but that wouldn't deal with classes that didn't have all methods fully implemented -- in that case you'd have to build subclasses and override unimplemented methods to throw exceptions.

              If you are considering developing such a wrapper, I think the Pythonista version could probably be generated automatically with a bit of clever programming -- write a script that takes the ui spec from Pythonista, checks each function, class and method to see if it's available in your Kivy wrapper, and builds up the Pythonista wrapper from there.

              1 Reply Last reply Reply Quote 0
              • ccc
                ccc last edited by

                In the Pythonista console, type: import ui ; help(ui) for a starting point.

                1 Reply Last reply Reply Quote 0
                • Ti Leyon
                  Ti Leyon last edited by Ti Leyon

                  @Niall here is an update to UniPAGE that may address your concerns. julia geeks was an expression of my frustration with people who wanted to license the code under their own terms without even mentioning the original source. I followed @dgelessus advice and investigated the common open source licensure, albeit superficially I must admit. I settled on the Creative Commons Attribution-ShareAlike 4.0 International License. It seems to reflect the general idea I had in mind. As far as I understand it you may use it in your own work and modify it whichever you want and even compile and sell the resulting app as long as you mention my original copyright at the beginning of the source code. If you want to publish the modified source you must do so under the same license. I am not a lawyer thus you may refer to the Creative Commons web site (www.creativecommons.org) for more information. Furthermore, I turned the "xratio" and "yratio" variables into class level entities as it was suggested by @JonB. I also added a "standard" view that will automatically set the main window at 800x600 under MS Windows, OSX and Linux (the Kivy default). It will fit the sheet in Pythonista according to the screen orientation. Under Android the window will maximize to occupy the entire screen. To use that "standardized structure" set the first tuple representing the view size to (0, 0). Thank you to @JonB, @ccc and @dgelessus for their suggestions.

                  # coding: utf-8
                  #-----------------------------------------------------------------------------
                  # Name:      UniPaGe
                  # Purpose:   Adaptable Graphic User Interface for Python
                  #
                  # Author:    Ti Leyon
                  #
                  # Created:   04/04/2017
                  # Copyright: (c) Ti Leyon 2017
                  # Licence:   This work is licensed under the
                  #            Creative Commons Attribution-ShareAlike 4.0 International License.
                  #            To view a copy of this license, visit:
                  #            http://creativecommons.org/licenses/by-sa/4.0/
                  #            or send a letter to:
                  #            Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
                  #-----------------------------------------------------------------------------
                  
                  class unipage(object):
                  
                      def __init__(self, kivy, screen_size):
                          self.kivy = kivy
                          self.screen_size = screen_size
                          self.unibuttons = []
                          self.unitexts = []
                          self.unilabels = []
                          self.unimages = []
                          self.uniframes = []
                          self.xratio = self.screen_size[0] / 800.0
                          self.yratio = self.screen_size[1] / 600.0
                  
                      def setscreen(self):
                          if self.kivy:
                              from kivy.uix.floatlayout import FloatLayout
                              from kivy.core.window import Window
                              self.root = FloatLayout()
                              if (self.xratio == 0) or (self.yratio == 0):
                                  from kivy.utils import platform as core_platform
                                  if core_platform == 'android':
                                      self.screen_size = Window.size
                                  else:
                                      self.screen_size = (800, 600)
                                  self.xratio = self.screen_size[0] / 800.0
                                  self.yratio = self.screen_size[1] / 600.0
                                  
                              Window.size = self.screen_size
                          else:
                              import ui
                              if (self.xratio == 0) or (self.yratio == 0):
                                  ss1 = ui.get_screen_size()[0]
                                  ss3 = ui.get_screen_size()[1]
                                  notoptimal = True
                                  while notoptimal:
                                      if ss1 % 8 == 0:
                                          notoptimal = False
                                      else:
                                          ss1 -= 1
                                  ss1 = ss1 - 124
                                  ss2 = (ss1 / 4) * 3
                                  if ss2 > ss3:
                                      print('yes')
                                      ss2 = ss3 - ss2 - ((ss3 - ss2) % 3)
                                      ss1 = (ss2 / 3) * 4
                                  self.screen_size = (ss1, ss2)
                                  self.xratio = self.screen_size[0] / 800
                                  self.yratio = self.screen_size[1] / 600
                                  
                              self.root = ui.View(frame=(0,0,self.screen_size[0], \
                                          self.screen_size[1]))
                  
                      def unibutton(self, params):
                          self.unibuttons.append([])
                          if len(params) == 6:
                              function = params[5]
                          else:
                              function = nofunction
                          if self.kivy:
                              from kivy.uix.button import Button
                              self.unibuttons[len(self.unibuttons) - 1] = Button(
                              text = params[4],
                              size_hint_y = None,
                              size_hint_x = None,
                              height = params[3] * self.yratio,
                              width = params[2] * self.xratio,
                              pos = (params[0] * self.xratio, params[1] * self.yratio),
                              on_press = function )
                              self.root.add_widget(self.unibuttons[len(self.unibuttons) - 1])
                          else:
                              import ui
                              self.unibuttons[len(self.unibuttons) - 1] = ui.Button(frame= \
                                  (params[0] * self.xratio, (600 - params[1] - params[3]) * self.yratio, \
                                  params[2] * self.xratio, params[3] * self.yratio), title = params[4])
                              self.unibuttons[len(self.unibuttons) - 1].background_color \
                                  = (0.4,0.4,0.4)
                              self.unibuttons[len(self.unibuttons) - 1].action = function
                              self.unibuttons[len(self.unibuttons) - 1].height = params[3] * self.xratio
                              self.unibuttons[len(self.unibuttons) - 1].width = params[2] * self.yratio
                              self.unibuttons[len(self.unibuttons) - 1].tint_color = 'white'
                              self.root.add_subview(self.unibuttons[len(self.unibuttons) - 1])
                  
                      def unitext(self, params):
                          self.unitexts.append([])
                          if self.kivy:
                              from kivy.uix.textinput import TextInput
                              self.unitexts[len(self.unitexts) - 1] = TextInput (
                              id = 'text' + str(len(self.unitexts) - 1),
                              size_hint_y = None,
                              size_hint_x = None,
                              height = params[3] * self.yratio,
                              width = params[2] * self.xratio,
                              text = params[4],
                              multiline = True,
                              pos = (params[0] * self.xratio, params[1] * self.yratio))
                              self.root.add_widget(self.unitexts[len(self.unitexts) - 1])
                          else:
                              import ui
                              self.unitexts[len(self.unitexts) - 1] = ui.TextField(frame=
                                  (params[0] * self.xratio, (600 - params[1] - params[3]) * \
                                  self.yratio, params[2] * self.xratio, params[3] * self.yratio))
                              self.unitexts[len(self.unitexts) - 1].bordered = False
                              self.unitexts[len(self.unitexts) - 1].background_color = 'white'
                              self.unitexts[len(self.unitexts) - 1].font = ('<system>', 23 * self.xratio)
                              self.unitexts[len(self.unitexts) - 1].text = params[4]
                              self.root.add_subview(self.unitexts[len(self.unitexts) - 1])
                  
                      def unilabel(self, params):
                          self.unilabels.append([])
                          if self.kivy:
                  
                              from kivy.uix.label import Label
                              self.unilabels[len(self.unilabels) - 1] = Label(pos = \
                                  (params[0] * self.xratio, params[1] * self.yratio), \
                                  size_hint=(1.0,1.0), halign="left", \
                                  valign="bottom", text = params[4])
                              self.unilabels[len(self.unilabels) - 1].bind(size= \
                                  self.unilabels[len(self.unilabels) - 1].setter('text_size'))
                              self.root.add_widget(self.unilabels[len(self.unilabels) - 1])
                  
                          else:
                  
                              import ui
                  
                              self.unilabels[len(self.unilabels) - 1] = ui.Label(frame= \
                                  (params[0] * self.xratio,  (600 - params[1] - params[3]) * self.yratio, \
                                  params[2] * self.xratio, params[3] * self.yratio))
                              self.unilabels[len(self.unilabels) - 1].text = params[4]
                              self.unilabels[len(self.unilabels) - 1].text_color = 'white'
                              self.unilabels[len(self.unilabels) - 1].alignment = ALIGN_LEFT = True
                              self.unilabels[len(self.unilabels) - 1].font = ('<system>', 18 * self.xratio)
                              self.root.add_subview(self.unilabels[len(self.unilabels) - 1])
                  
                      def unimage(self, params):
                          self.unimages.append([])
                          if self.kivy:
                              from kivy.uix.image import Image
                  
                              self.unimages[len(self.unimages) - 1] = Image( source= params[4],
                                  allow_stretch = True, size_hint = (None, None),
                                  size=(params[2] * self.xratio, params[3] * self.yratio),
                                  pos=(params[0] * self.xratio, params[1] * self.yratio))
                  
                              self.root.add_widget(self.unimages[len(self.unitexts) - 1])
                  
                          else:
                              import ui
                  
                              self.unimages[len(self.unimages) - 1] = (ui.ImageView
                              (name = 'Image', frame = (params[0] * self.xratio, \
                              (600 - params[1] - params[3]) * self.yratio, \
                              params[2] * self.xratio, params[3] * self.yratio)))
                  
                              self.root.add_subview (self.unimages[len(self.unimages) - 1])
                  
                              self.unimages[len(self.unitexts) - 1].image = ui.Image.named(params[4])
                  
                      def uniframe(self, params):
                          if self.kivy:
                              from kivy.graphics import Color
                              from kivy.graphics import Rectangle
                              self.root.canvas.add(Color (params[4][0],params[4][1], params[4][2]))
                              self.root.canvas.add(Rectangle(pos = (params[0] * self.xratio, \
                                  params[1] * self.yratio), size = (params[2] * self.xratio, \
                                  params[3] * self.yratio)))
                          else:
                              import ui
                              self.uniframes.append([])
                              self.uniframes[len(self.uniframes) - 1] = \
                                  ui.View(frame=(params[0] * self.xratio, \
                                  (600 - params[1] - params[3]) * self.yratio, \
                                  params[2] * self.xratio, params[3] * self.yratio))
                              self.uniframes[len(self.uniframes) - 1].background_color = \
                                  (params[4][0],params[4][1], params[4][2],1.0)
                              self.root.add_subview(self.uniframes[len(self.uniframes) - 1])
                  
                      def showpage(self):
                          if self.kivy:
                              from kivy.base import runTouchApp
                              runTouchApp(self.root)
                          else:
                              self.root.present('sheet')
                  
                  class uniscreen(unipage):
                      screendef = []
                      def __init__(self, screendef):
                          try:
                              from kivy.uix.floatlayout import FloatLayout
                              kivy = True
                          except:
                              import ui
                              kivy = False
                          unipage.__init__(self, kivy, screendef[0])
                          self.setscreen()
                          self.screendef = screendef
                  
                      def setpage(self):
                          for k in range(1, len(self.screendef)):
                              self.screendef[k][0](self, self.screendef[k][1])
                  
                  def closepage(sender):
                      if mypage.kivy:
                  
                          from kivy.utils import platform as core_platform
                          from kivy.core.window import Window
                          import sys
                  
                          if core_platform == 'android':
                              sys.exit()
                          else:
                              Window.close()
                  
                      else:
                  
                          mypage.root.close()
                  
                  def function_1(sender):
                      mypage.unitexts[0].text = 'Oh! You clicked my button.'
                  
                  def nofunction(sender):
                      pass
                  
                  if __name__ == '__main__':
                      unilabel = unipage.unilabel
                      uniframe = unipage.uniframe
                      unitext = unipage.unitext
                      unibutton = unipage.unibutton
                      unimage = unipage.unimage
                      widgets = [(0, 0),
                          (uniframe,(0, 0, 600, 450,(.6,.6,.6))),
                          (unilabel,(80, 300, 240, 20, 'Hey I am just a simple label.')),
                          (unibutton,(40, 40, 100, 40, 'Click me', function_1)),
                          (unibutton,(460, 40, 100, 40, 'Close me', closepage)),
                          (unitext,(40, 120, 300, 40, 'I am a text field')),
                          (unimage,(460, 310, 100, 100,'insidelogo.png'))
                          ]
                      mypage = uniscreen(widgets)
                      mypage.setpage()
                      mypage.showpage()
                      
                  
                  1 Reply Last reply Reply Quote 0
                  • komanguy
                    komanguy last edited by

                    Thanks a lot. You rock!

                    1 Reply Last reply Reply Quote 0
                    • Ti Leyon
                      Ti Leyon last edited by Ti Leyon

                      A visual designer that generates a UniPAGe based script? About a year ago I wrote a simple Python IDE for the Android platform. It was mainly an experiment to find out how for far I could push the Android version of RFO BASIC and how fast I could create a ready for market app on that platform. It was a rewarding experience and recently I decided to adapt it to produce UniPAGe scripts. Before I started it occurred to me that I should restart from scratch and write the visual interface designer using UniPAGe. That way the designer could run unmodified in all the environments covered by UniPAGe. That is exactly what I did and in doing so I discovered about a dozen bugs, inconsistencies and omissions in the original implementation of UniPAGe. They were promptly addressed and corrected. Below are a list of the corrections as well as a full listing of the latest implementation of UniPAGE. BTW @komanguy thank you for your kind comments and enjoy the this finely tuned release.

                      Improvements in this release:

                      • Set the font size for the Kivy environment to adapt to the current window resolution
                      • Created Android windows within the full screen resolution in all orientations because the Kivy environment responded erratically when the window is set directly.
                      • Fixed font ratio for the textfields in Pythonista UI
                      • Fixed the automated mode (0, 0) in the Pthonista UI for all iOS devices to present an "optimal" sheet (Tested on many iPhone and iPad models).
                      • Note: I could not locate a reference for the height of the title bar in a sheet presentation in Pythonista. A factor of 90 times the vertical ratios works on all tested devices although not quite optimal on higher resolution gears.
                      • Made the "closepage()" function independent of the global "mypage" variable so it could be used along with the UniPAGe classes in an external module if so desired.
                      #-----------------------------------------------------------------------------
                      # Name:      UniPaGe
                      # Purpose:   Adaptable Graphic User Interface for Python
                      #
                      # Author:    Ti Leyon
                      #
                      # Created:   04/07/2017
                      # Copyright: (c) Ti Leyon 2017
                      # Licence:   This work is licensed under the
                      #            Creative Commons Attribution-ShareAlike 4.0
                      #            International License.
                      #            To view a copy of this license, visit:
                      #            http://creativecommons.org/licenses/by-sa/4.0/
                      #            or send a letter to:
                      #            Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
                      #-----------------------------------------------------------------------------
                      
                      class unipage(object):
                      
                          def __init__(self, kivy, screen_size):
                              self.kivy = kivy
                              self.screen_size = screen_size
                              self.unibuttons = []
                              self.unitexts = []
                              self.unilabels = []
                              self.unimages = []
                              self.uniframes = []
                              self.xratio = self.screen_size[0] / 800.0
                              self.yratio = self.screen_size[1] / 600.0
                      
                          def setscreen(self):
                              if self.kivy:
                                  from kivy.config import Config
                                  Config.set('input', 'mouse', 'mouse,multitouch_on_demand')
                                  from kivy.uix.floatlayout import FloatLayout
                                  from kivy.core.window import Window
                                  from kivy.utils import platform as core_platform
                                  self.root = FloatLayout()
                                  if (self.xratio == 0) or (self.yratio == 0):
                                      if core_platform == 'android':
                                          self.screen_size = Window.size
                                          if self.screen_size[0] < self.screen_size[1]:
                                              x = self.screen_size[0]
                                              y = self.screen_size[0] / 4 * 3
                                              self.screen_size = (x, y)
                                      else:
                                          self.screen_size = (800, 600)
                                      self.xratio = self.screen_size[0] / 800.0
                                      self.yratio = self.screen_size[1] / 600.0
                      
                                  if core_platform == 'android':
                                      Window.softinput_mode = 'pan'
                                  else:
                                      Window.size = self.screen_size
                              else:
                                  import ui
                                  if (self.xratio == 0) or (self.yratio == 0):
                                      ss1 = ui.get_screen_size()[0]
                                      ss3 = ui.get_screen_size()[1]
                                      notoptimal = True
                                      while notoptimal:
                                          if ss1 % 8 == 0:
                                              notoptimal = False
                                          else:
                                              ss1 -= 1
                                      ss2 = (ss1 / 4) * 3
                                      title_bar_height = int(ss3 / 600 * 50)
                                      if ss2 > ss3 - title_bar_height:
                                          ss2 = ss3 - title_bar_height
                                          notoptimal = True
                                          while notoptimal:
                                              if ss2 % 6 == 0:
                                                  notoptimal = False
                                              else:
                                                  ss2 -= 1
                                          ss1 = (ss2 / 3) * 4
                                      self.screen_size = (ss1, ss2)
                                      self.xratio = ss1 / 800
                                      self.yratio = ss2 / 600
                      
                                  self.root = ui.View(frame=(0,0,self.screen_size[0], \
                                              self.screen_size[1]))
                      
                          def unibutton(self, params):
                              self.unibuttons.append([])
                              if len(params) == 6:
                                  function = params[5]
                              else:
                                  function = nofunction
                              if self.kivy:
                                  from kivy.uix.button import Button
                                  self.unibuttons[len(self.unibuttons) - 1] = Button(
                                  text = params[4],
                                  size_hint_y = None,
                                  size_hint_x = None,
                                  height = params[3] * self.yratio,
                                  width = params[2] * self.xratio,
                                  font_size = 17.5 * self.yratio,
                                  pos = (params[0] * self.xratio, params[1] * self.yratio),
                                  on_press = function )
                                  self.root.add_widget(self.unibuttons[len(self.unibuttons) - 1])
                              else:
                                  import ui
                                  self.unibuttons[len(self.unibuttons) - 1] = ui.Button(frame= \
                                      (params[0] * self.xratio, (600 - params[1] - \
                                      params[3]) * self.yratio, \
                                      params[2] * self.xratio, params[3] * self.yratio), \
                                      title = params[4])
                                  self.unibuttons[len(self.unibuttons) - 1].background_color \
                                      = (0.4,0.4,0.4)
                                  self.unibuttons[len(self.unibuttons) - 1].action = function
                                  self.unibuttons[len(self.unibuttons) - 1].height = params[3] * \
                                      self.xratio
                                  self.unibuttons[len(self.unibuttons) - 1].width = params[2] * \
                                      self.yratio
                                  self.unibuttons[len(self.unibuttons) - 1].tint_color = 'white'
                                  self.unibuttons[len(self.unibuttons) - 1].font = ('<system>', \
                                      17.5 * self.yratio)
                                  self.root.add_subview(self.unibuttons[len(self.unibuttons) - 1])
                      
                          def unitext(self, params):
                              self.unitexts.append([])
                              if self.kivy:
                                  from kivy.uix.textinput import TextInput
                                  self.unitexts[len(self.unitexts) - 1] = TextInput (
                                  id = 'text' + str(len(self.unitexts) - 1),
                                  size_hint_y = None,
                                  size_hint_x = None,
                                  height = params[3] * self.yratio,
                                  width = params[2] * self.xratio,
                                  text = params[4],
                                  multiline = True,
                                  font_size = 17.5 * self.yratio,
                                  pos = (params[0] * self.xratio, params[1] * self.yratio))
                                  self.root.add_widget(self.unitexts[len(self.unitexts) - 1])
                              else:
                                  import ui
                                  self.unitexts[len(self.unitexts) - 1] = ui.TextField(frame=
                                      (params[0] * self.xratio, (600 - params[1] - params[3]) * \
                                      self.yratio, params[2] * self.xratio, params[3] * self.yratio))
                                  self.unitexts[len(self.unitexts) - 1].bordered = False
                                  self.unitexts[len(self.unitexts) - 1].background_color = 'white'
                                  self.unitexts[len(self.unitexts) - 1].font = ('<system>', 17.5 * \
                                      self.yratio)
                                  self.unitexts[len(self.unitexts) - 1].text = params[4]
                                  self.root.add_subview(self.unitexts[len(self.unitexts) - 1])
                      
                          def unilabel(self, params):
                              self.unilabels.append([])
                              if self.kivy:
                                  from kivy.uix.label import Label
                                  self.unilabels[len(self.unilabels) - 1] = Label(pos = \
                                      (params[0] * self.xratio, params[1] * self.yratio), \
                                      size_hint=(1.0,1.0), halign="left", \
                                      valign="bottom", text = params[4])
                                  self.unilabels[len(self.unilabels) - 1].font_size = 17.5 * \
                                      self.yratio
                                  self.unilabels[len(self.unilabels) - 1].bind(size= \
                                      self.unilabels[len(self.unilabels) - 1].setter('text_size'))
                                  self.root.add_widget(self.unilabels[len(self.unilabels) - 1])
                      
                              else:
                      
                                  import ui
                                  self.unilabels[len(self.unilabels) - 1] = ui.Label(frame= \
                                      (params[0] * self.xratio,  (600 - params[1] - params[3]) * \
                                      self.yratio, params[2] * self.xratio, params[3] * self.yratio))
                                  self.unilabels[len(self.unilabels) - 1].text = params[4]
                                  self.unilabels[len(self.unilabels) - 1].text_color = 'white'
                                  self.unilabels[len(self.unilabels) - 1].alignment = \
                                      ui.ALIGN_LEFT
                                  self.unilabels[len(self.unilabels) - 1].font = ('<system>', 18 * \
                                      self.yratio)
                                  self.root.add_subview(self.unilabels[len(self.unilabels) - 1])
                      
                          def unimage(self, params):
                              self.unimages.append([])
                              if self.kivy:
                                  from kivy.uix.image import Image
                                  self.unimages[len(self.unimages) - 1] = Image( source= params[4],
                                      allow_stretch = True, size_hint = (None, None),
                                      size=(params[2] * self.xratio, params[3] * self.yratio),
                                      pos=(params[0] * self.xratio, params[1] * self.yratio))
                      
                                  self.root.add_widget(self.unimages[len(self.unimages) - 1])
                      
                              else:
                                  import ui
                                  self.unimages[len(self.unimages) - 1] = (ui.ImageView
                                  (name = 'Image', frame = (params[0] * self.xratio, \
                                  (600 - params[1] - params[3]) * self.yratio, \
                                  params[2] * self.xratio, params[3] * self.yratio)))
                      
                                  self.root.add_subview (self.unimages[len(self.unimages) - 1])
                                  self.unimages[len(self.unimages) - 1].image = \
                                      ui.Image.named(params[4])
                      
                          def uniframe(self, params):
                              if self.kivy:
                                  from kivy.graphics import Color
                                  from kivy.graphics import Rectangle
                                  self.root.canvas.add(Color (params[4][0],params[4][1], \
                                      params[4][2]))
                                  self.root.canvas.add(Rectangle(pos = (params[0] * self.xratio, \
                                      params[1] * self.yratio), size = (params[2] * self.xratio, \
                                      params[3] * self.yratio)))
                              else:
                                  import ui
                                  self.uniframes.append([])
                                  self.uniframes[len(self.uniframes) - 1] = \
                                      ui.View(frame=(params[0] * self.xratio, \
                                      (600 - params[1] - params[3]) * self.yratio, \
                                      params[2] * self.xratio, params[3] * self.yratio))
                                  self.uniframes[len(self.uniframes) - 1].background_color = \
                                      (params[4][0],params[4][1], params[4][2],1.0)
                                  self.root.add_subview(self.uniframes[len(self.uniframes) - 1])
                      
                          def showpage(self):
                              if self.kivy:
                                  from kivy.base import runTouchApp
                                  runTouchApp(self.root)
                              else:
                                  self.root.present('sheet')
                      
                      class uniscreen(unipage):
                          def __init__(self, screendef):
                              try:
                                  from kivy.uix.floatlayout import FloatLayout
                                  kivy = True
                              except:
                                  import ui
                                  kivy = False
                              unipage.__init__(self, kivy, screendef[0])
                              self.setscreen()
                              self.screendef = screendef
                      
                          def setpage(self):
                              for k in range(1, len(self.screendef)):
                                  self.screendef[k][0](self, self.screendef[k][1])
                      
                      def closepage(sender):
                          try:
                      
                              from kivy.utils import platform as core_platform
                              from kivy.core.window import Window
                              import sys
                      
                              if core_platform == 'android':
                                  sys.exit()
                              else:
                                  Window.close()
                      
                          except:
                      
                              sender.superview.close()
                      
                      def nofunction(sender):
                          pass
                      
                      def function_1(sender):
                          mypage.unitexts[0].text = 'Oh! You clicked my button.'
                      
                      if __name__ == '__main__':
                          unilabel = unipage.unilabel
                          uniframe = unipage.uniframe
                          unitext = unipage.unitext
                          unibutton = unipage.unibutton
                          unimage = unipage.unimage
                          widgets = [(0, 0),
                              (uniframe,(0, 0, 600, 450,(.6,.6,.6))),
                              (unilabel,(40, 300, 240, 20, 'Hey I am just a simple label.')),
                              (unibutton,(40, 40, 100, 40, 'Click me', function_1)),
                              (unibutton,(460, 40, 100, 40, 'Close me', closepage)),
                              (unitext,(40, 120, 300, 40, 'I am a text field')),
                              (unimage,(460, 310, 100, 100,'insidelogo.png'))
                              ]
                          mypage = uniscreen(widgets)
                          mypage.setpage()
                          if mypage.kivy:
                              mypage.unimages[len(mypage.unimages) - 1].source = \
                                  'data/logo/kivy-icon-512.png'
                          else:
                              mypage.unimages[len(mypage.unimages) - 1].source = \
                                  'test:Pythonista'
                          mypage.showpage()
                      
                      
                      1 Reply Last reply Reply Quote 0
                      • Ti Leyon
                        Ti Leyon last edited by

                        If you are using a lower resolution device such as most iPhones the optimal mode (0, 0) may not fit in landscape orientation. It will work fine in portrait though. This is because I cannot yet locate a reliable documentation for the height of title bar in a sheet presentation at any resolution. If you do want to use that orientation change the title_bar_height factor from 50 to 90.

                        1 Reply Last reply Reply Quote 1
                        • sfdemon
                          sfdemon @abcabc last edited by

                          @abcabc. What ever happened to your version? Because despite what @TiLeyon thinks you can not copyright ideas or conecpts thats what patents are for. Your code was comletely differnt that @TiLeyon and used a completely different approach. IMHO yous was also a lot cleaner approach.

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