1

I am new to PyQgis. I made a simple calculator with PyQt4, now I am trying to run it under QGIS. I connected calculator as plugin, and tested it, its GUI works without error but it does not calculates anything.

How can I get error log?

calculator.py:

# -*- coding: utf-8 -*-

from PyQt4 import QtCore, QtGui
from calculate_ui import Ui_Dialog
from math import *
from qgis.core import *

def derece(degrees):
    return degrees*((2*pi)/400)

class Dialog(QtGui.QDialog, Ui_Dialog):
    def __init__(self, iface):
      QtGui.QDialog.__init__(self)
      self.iface = iface
      self.setupUi(self)
      self.ui = Ui_Dialog()
      self.ui.setupUi(self)
      # Validations
      tempValidator = QtGui.QDoubleValidator()
      tempValidator.setNotation(QtGui.QDoubleValidator.StandardNotation)
      self.ui.at.setValidator(tempValidator)
      self.ui.Rt.setValidator(tempValidator)
      # Signal/slot connections.
      self.setupConnections()

    def calc(self):
      a = float(self.ui.at.text())
      R = float(self.ui.Rt.text())

      T=R*tan(derece(a/2))
      L=(2*pi*R*a)/400
      BS=(R/cos(derece(a/2)))-R

      self.ui.Tt.setText(str(T))
      self.ui.Lt.setText(str(L))
      self.ui.BSt.setText(str(BS))
    def silk(self):
      self.ui.at.clear()
      self.ui.Rt.clear()
      self.ui.Tt.clear()
      self.ui.Lt.clear()
      self.ui.BSt.clear()

    def setupConnections(self):

      self.connect(self.ui.hesaplak, QtCore.SIGNAL('clicked()'),
          self.calc)
      self.connect(self.ui.temizlek, QtCore.SIGNAL('clicked()'),
          self.silk)

You can take a look at the plugin from here.

1

Python messages can be printed to the python console.

This is accessed from Plugins> Python Console.

0

Probably your connections are wrong.

Remove your setupConnections function, and connect them under __init__:

self.ui.hesaplak.clicked.connect(self.calc)
self.ui.temizlek.clicked.connect(self.silk)

I guess your derece function also should be inside the class (then call it with self.).

  • Unfortunately the code link didnt work again. Thank you. – Edip Ahmet Jul 31 '15 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.