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.


    Calling console.quicklook() on a UI button action?

    Pythonista
    3
    5
    3679
    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.
    • HeyItsJono
      HeyItsJono last edited by

      Hi there,
      In my program I have a GUI with a button which, when pressed, is supposed to bring up a Quick Look of a particular file. I decorated the button function with @ui.in_background and yet when the button is pressed, no Quick Look view pops up. On the first press, nothing happens and on the second press Pythonista as a whole hangs and needs to be force-closed via the app switcher. An example is the following, where the pyui file just contains a single button whose action references the button function.

      # coding: utf-8
      
      import ui
      import console
      
      @ui.in_background
      def button(sender):
      	console.quicklook('file.ics')
      
      ui.load_view('Untitled 2').present('sheet')
      
      1 Reply Last reply Reply Quote 0
      • TutorialDoctor
        TutorialDoctor last edited by

        I think console.quicklook() needs a full file path as an argument. What is the path to the file?

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

          The file is in the same directory as the script so that is the full path of the file. The statement works just fine when it's not called from a ui function or when it's called from the console, it's just something about being called via a button action that prevents it from working.

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

            https://omz-forums.appspot.com/pythonista/post/5256919912546304

            Short answer: you must close any ui views before running quicklook. Longer answer, you have to use ui.delay to make sure the view is finished hiding before calling quicklook. For actual code. See thread above.

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

              Thank you, that worked brilliantly! Neither threading.Timer nor ui.delay were working properly; they just hung the program.<Br>
              <code>
              v.close()<Br>
              time.sleep(1)
              <br>console.quicklook('file.ics')</code>
              <Br>worked perfectly though.

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