Announcement

Collapse
No announcement yet.

Can Kate run a Python script it is editing?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can Kate run a Python script it is editing?

    I've got Python IDEs like Eric and Spyder installed, but I still find myself starting Kate to get editing without screen clutter and all the editing tools I need -- and then I have to go to a Konsole any time I need to run the script. I expect there's a way to set up Kate to run the Python script that's currently being edited with a shortcut key -- with a plugin(?) -- but if there is it's not obvious to me. Help please.
    Last edited by Snowhog; Nov 09, 2017, 05:40 PM.

    #2
    If you go to Settings > Plugins you can enable 'Terminal tool view' which will give you an embedded terminal in Kate that you can run the script from.

    Comment


      #3
      I've figured out a solution. I can now run the Python (or other) script being edited with F2. Here's my notes:

      Kate setup:
      Settings -> Configure Kate -> Plugins -> Build Plugin -> Check
      View -> Tool Views -> Show Build Output -> Check

      Target Settings Pane -> dbl-click "T: Target Set" rename to "Run Scripts"
      Delete lines "Clean", "Config", and "ConfigClean" (click red "X")
      Build -> Check
      Dbl-click "make", replace with "%f" (assumes scripts will have suitable hashbang)

      Settings -> Configure Shortcuts -> search "build" ->
      Build Target -> Custom -> F2
      The output from the script then appears in the "Output" tab of the "Build Output" pane.

      Edit: Now I've found that Kate will lock up if I use the above method to run a Python script which I've accidentally forgotten to start with the hashbang line. (When the shell hits the Python script's first "import" line, it tries to execute the command-line "import" from ImageMagick. The same problem would also lock up Konsole if I ran the script from the command-line.) So to fix that I created a file called "kate-run-scripts" in "/usr/local/bin" as below, and changed Kate's "Build" line (see above) to: kate-run-scripts "%f"

      Code:
      #!/bin/bash
      if [[ -z $(head -n1 "$@" | grep '^#!') ]]; then
      echo "Script must start with hashbang."
      else
      $@
      fi
      Last edited by Dave Rove; Nov 11, 2017, 08:30 AM.

      Comment


        #4
        Can't find this:

        Target Settings Pane -> dbl-click "T: Target Set" rename to "Run Scripts"
        Delete lines "Clean", "Config", and "ConfigClean" (click red "X")
        Build -> Check
        "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
        – John F. Kennedy, February 26, 1962.

        Comment


          #5
          Originally posted by GreyGeek View Post
          Can't find this:
          The first two lines of the setup that I gave should have made the Target Settings Pane appear like so:

          Click image for larger version

Name:	kate-target-pane.jpg
Views:	1
Size:	54.2 KB
ID:	643667

          Comment


            #6
            Ah, that's much clearer.
            "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
            – John F. Kennedy, February 26, 1962.

            Comment


              #7
              Originally posted by GreyGeek View Post
              Ah, that's much clearer.
              Yup. A picture is worth . Hehe
              Using Kubuntu Linux since March 23, 2007
              "It is a capital mistake to theorize before one has data." - Sherlock Holmes

              Comment

              Working...
              X