omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. chriswilson
    3. Posts

    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 1
    • Followers 1
    • Topics 6
    • Posts 79
    • Best 20
    • Controversial 0
    • Groups 0

    Posts made by chriswilson

    • RE: Today Widget - Just some comments

      @Phuket2

      Ah I see. Good to know. I tried this and it got me a nice transparent background to my widget, but of course setting alpha to zero would do the same thing!

      I was basing this on the Swift iOS colours (UIColor class which has a UIColor.clear) rather than CSS. I’m not sure if this is what is going on behind the scenes of the UI module though.

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: Today Widget - Just some comments

      @Phuket2

      Regarding the clear background thing: I’ve just started playing with the Today Widget as well and I used this code to load a standard PYUI file (as might be done for a normal script). It also sets a clear background. I hope it’s helpful!

      v = ui.load_view()
      v.background_color = ui.set_color("clear")
      appex.set_widget_view(v)
      
      posted in Pythonista
      chriswilson
      chriswilson
    • RE: Pythonista is now featured on Python.org

      Well done @omz!

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: Thank you Omz for the immense update!

      Seconded! Thanks omz!

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: Toy Scene Script: Drag a ball around with elastic string

      @edsuom
      This is great. Thanks!

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: Merry Christmas and Happy Python 3.6

      Thanks @ccc

      Happy Christmas all!

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: Player Collision , Hitbox

      @lance1994

      @ccc has been a big help on my journey too! :)

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: Player Collision , Hitbox

      The hitbox you created is just a Rect() object, which is simply coordinates and not actually something rendered on the screen. You could make a Shapenode() or SpriteNode() of the same size which would be visible.

      I'm not at my computer just now, but can show some code later if you like.

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: Bokeh, Matplotlib or Plotly?

      @Webmaster4o I'm starting to learn JS now, so hopefully it won't be a problem!

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: Bokeh, Matplotlib or Plotly?

      @Webmaster4o Looks great! I'll check it out.

      posted in Pythonista
      chriswilson
      chriswilson
    • Bokeh, Matplotlib or Plotly?

      I'm currently learning flask and hoping to make a web app that will pull user-selected data from a MySQL database.

      Graphing the data would be great, and I have just discovered Bokeh and Plotly, both of which have Python APIs. I am not familiar (yet) with Matplotlib.

      Has anyone any experience of using any of these options (particularly within Flask)?

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: How to post apps to the App Store?

      @happy_variable @bistrot

      I have gone through this process a few months ago and can give you some tips if you like. The Xcode template itself is great but there might be a few things need sorting out to get it to work (depending on the complexity of the app).

      You do have to make sure the app adapts to the screen sizes of different devices, as Apple will turn it down otherwise.

      Also, I might be wrong, but because the Python code is essentially inside a wrapper, you cannot interact with Apple frameworks like GameCentre etc (I'm open to being corrected on this - maybe it just takes some clever code).

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: UI for matplotlib

      This code will present a very basic button that will run the matplotlib stuff when pressed. No pyui file used here.

      As I mentioned, the matplotlib graph appears in the console rather than the UI. You might need to use a different UI element to display a matplotlib graph (maybe a ui.ImageView()) but I'm not sure of the specifics as regards working with matplotlib.

      import ui
      import matplotlib.pyplot as plt
      from random import choice, randint
      
      def button_tapped(sender):
          button.title = "Tapped!"
          show_walk()
      
      def fill_x_values(walk_length):
          x_values = [0]
          points = walk_length
          while len(x_values) < points:
              x_direction = choice([1, -1])
              x_distance = choice([1, 2, 3, 4])
              x_step = x_direction * x_distance
              next_x = x_values[-1] + x_step
              x_values.append(next_x)
          return x_values
      
      def fill_y_values(walk_length):
          y_values = [0]
          points = walk_length
          while len(y_values) < points:
              y_direction = choice([1, -1])
              y_distance = choice([1, 2, 3, 4])
              y_step = y_direction * y_distance
              next_y = y_values[-1] + y_step
              y_values.append(next_y)
          return y_values
      
      def show_walk():
          walk_length = 50000
          x_values = fill_x_values(walk_length)
          y_values = fill_x_values(walk_length)
      		
          plt.scatter(x_values, y_values,c='red', edgecolor='none', alpha=0.2, s=7)
          plt.axes().get_xaxis().set_visible(False)
          plt.axes().get_yaxis().set_visible(False)
          plt.show()
          
      button = ui.Button()
      button.present()
      button.title = "Press here!"
      button.action = button_tapped
      
      posted in Pythonista
      chriswilson
      chriswilson
    • RE: UI for matplotlib

      Hi @p_atrick
      Welcome to Pythonista.

      While I'm not familiar with matplotlib, I can suggest a couple of points regarding the UI.

      The lines...

      v = ui.load_view()
      v.present('sheet')
      

      ...need to go towards the end of your code, after the function definitions like def button_tapped(sender) so that the UI can "see" these definitions before it is initialised. Presenting the view should be the last thing you do.

      I see you use ui.load_view() which will load a pyui file with the same name as your script. It might be easier to define your button entirely in the interface builder (including setting its action attribute).

      Currently your last two lines of code only create a button object but do not place it anywhere within the UI (and as your UI is already "presented" it cannot be added anyway). These lines are unnecessary if the button is defined in the pyui file.

      Finally, I understand matplotlib draws things in the console, so you might not see anything on pressing the button unless you exit to the console.

      I hope this is helpful!

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: MySQL in pythonista

      If it's not working and you're using Pythonista 3, try putting the scripts in the site-packages-2 folder instead. It's for modules that don't work with Python 3.x (mysqldb might be compatible, but I'm not sure).

      Here's a quick example using INSERT:

      import mysqldb
      
      db = mysqldb.connect(host= "mysql.my_domain.co.uk", user = "my_username", passwd="my_password", db="my_database", port = 3306)
      
      c = db.cursor()
      	
      c.execute("INSERT INTO my_table (my_column1, my_column_2) VALUES (%s, %s)", (my_value_1, my_value_2))
      
      db.commit()
      
      db.disconnect()
      
      

      And another using SELECT:

      import mysqldb
      
      db = mysqldb.connect(host= "mysql.my_domain.co.uk", user = "my_username", passwd="my_password", db="my_database", port = 3306)
      
      c = db.cursor()
      
      c.execute("SELECT * FROM my_table ORDER BY my_column_1 DESC LIMIT 0, 100")
      
      my_variable = c.fetchall()
      
      db.disconnect()
      
      posted in Pythonista
      chriswilson
      chriswilson
    • RE: MySQL in pythonista

      Hi @skaboy71

      I use the same mysqldb module and it's great. Try putting the files in site-packages without them being in a subfolder. This works for me.

      I use it in a Python 2.x environment, so not sure if it works in Python 3.x or not.

      Be sure to import mysqldb at the start. This thread has some useful advice and code examples to get it going.

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: scene vs. ui

      @adessler

      I think the update() method gets called once per frame; at least 60 times per second usually, but I understand this is variable so it's not useful in itself for counting.

      As regards your second question, you can certainly use a SceneView to put a scene within a ui. I'm not sure about the other way around, but I think it can be done.

      I'll mess around with this and let you know if I work it out!

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: Paper for UIs

      @AtomBombed

      This is awesome. Thanks!

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: scene vs. ui

      Hi @adessler

      While ui is more natural as an interface, scene has some useful methods that you can use to make a timer and then bundle your scene in a SceneView in a ui like @abcabc suggested.

      For example, scene.Scene.t is the time (in seconds) since a scene was started. Setting a variable equal to this will give you a 'timestamp' to compare the current scene.Scene.t to in the update method.

      In my (limited) experience, this causes fewer problems than using things like time.sleep(), ui.delay() or recursion.

      I hope this helps!

      posted in Pythonista
      chriswilson
      chriswilson
    • RE: Pausing inside classes with "Scene" object

      Hi @happy_variable

      What exactly do you want to achieve. There are several methods that might help.

      If it is primarily animations etc, then SpriteNode.run_action() will allow you to apply actions to nodes. There is an Action.wait() method which might be what you are looking for. Action.sequence() and Action.group allow you to run multiple actions sequentially or together.

      Action.call() can call any function as part of an animation. It can thus be set up to function like a timer or delay.

      Another option would be ui.delay() which calls a function after a particular delay.

      time.sleep() functions might need to be decorated with @ui.in_background to work as expected. This can sometimes cause problems if several processes are running in the background as well.

      I hope this helps a little. Let me know exactly what you need to do and I could make specific suggestions.

      posted in Pythonista
      chriswilson
      chriswilson