4

I have tried notepad++ and eclipse but even then , it is showing me an indentation error at line 18. I don't know, why it is throwing me an error like that...? please help me.

from brisa.core.reactors.qtreactor import QtReactor
reactor = QtReactor()
from brisa.core import config
from brisa.upnp.device import Device
from brisa.upnp.device.service import Service, StateVariable
class QtDevice(QtGui.QWidget):
     def __init__(self):

         QtGui.QWidget.__init__(self)
         self.verticalLayout = QtGui.QVBoxLayout(self)
         self.title = QtGui.QLabel("Qt Simple Device")
         font = QtGui.QFont()
         font.setPointSize(15)
         self.title.setFont(font)
         self.title.setAlignment(QtCore.Qt.AlignCenter)
         self.verticalLayout.addWidget(self.title)
         self.lineEdit = QtGui.QLineEdit(self)
         self.verticalLayout.addWidget(self.lineEdit)
         self.search_btn = QtGui.QPushButton("Start Device", self)
         self.verticalLayout.addWidget(self.search_btn)
         QtCore.QObject.connect(self.search_btn, QtCore.SIGNAL("clicked()"), self.start)
         self.stop_btn = QtGui.QPushButton("Stop Device", self)
         self.verticalLayout.addWidget(self.stop_btn)
         QtCore.QObject.connect(self.stop_btn, QtCore.SIGNAL("clicked()"), self.stop)
         self.lineEdit.setText(’My Generic Device Name’)
         self.root_device = None
         self.upnp_urn = ’urn:schemas-upnp-org:device:MyDevice:1’


     def _add_root_device(self):
         project_page = ’http://brisa.garage.maemo.org’
         serial_no = config.manager.brisa_version.replace(’.’, ’’).rjust(7, ’0’)
         self.root_device = Device(self.upnp_urn,str(self.lineEdit.text()),
                                    manufacturer=’’,
                                    manufacturer_url=,
                                    model_description=’ ’

                                    model_name=’’,
                                    model_number=,
                                    model_url=,
                                    serial_number=)  


     def _add_services(self):
         service_name = ’MyService’
         service_type = ’urn:schemas-upnp-org:service:MyService:1’
         myservice = Service(service_name, service_type, ’’)
         var = StateVariable(self, "A_ARG_TYPE_Variable",True, False, "string")
         myservice.add_state_variable(var)
         self.root_device.add_service(myservice)

    def _load(self):
         self._add_root_device()
         self._add_services()
         def start(self):
         self.stop()
         self._load()
         self.root_device.start()
         reactor.add_after_stop_func(self.root_device.stop)  

     def stop(self):
         if self.root_device:
             self.root_device.stop()
             self.root_device = None

def main():
     qt_dev = QtDevice()
     qt_dev.show()
     reactor.main()
if __name__ == ’__main__’:
     main()          
Andrea Spadaccini
  • 12,378
  • 5
  • 40
  • 54
user597293
  • 49
  • 1
  • 2
  • 6
  • How about tell us what line 18 is, and show us the error message – Falmarri Feb 02 '11 at 18:35
  • 1
    Where do the funky single quotes come from? If they're in the source code, they'll trigger syntax errors galore. Also, the long `Device(...)` in `_add_root_device` has several errors: a missing comma and most keyword arguments lack values. –  Feb 02 '11 at 18:38
  • @user597293: First step in debugging is to assume that the warning is accurate. In the case of indentation errors it's trivially simple to simply delete all leading indentation and reinsert what you think is the right indentation. – Bryan Oakley Feb 02 '11 at 18:41
  • 1
    The `’` character is not `'` the apostrophe. It's not legal Python. Why is it in the code? – S.Lott Feb 02 '11 at 19:06

4 Answers4

13

In such cases it is usually a good idea to run python with the -t flag:

-t : issue warnings about inconsistent tab usage (-tt: issue errors)

This will help to find indentation problems caused by accidentally used tabs.

sth
  • 222,467
  • 53
  • 283
  • 367
  • 2
    +1 for a not exactly well-known (this is the first time I see it anywhere except on docs.python.org), but very useful trick. –  Feb 02 '11 at 18:43
7

The row

     self.verticalLayout.addWidget(self.lineEdit)

should be on the same level of the other rows.

You might be missing it because your editor mixes tabs and spaces.

If you click on "edit" in your own question, you'll see that this row is not correctly indented.

Andrea Spadaccini
  • 12,378
  • 5
  • 40
  • 54
  • 1
    If you click on "edit" in your own question, you'll see that this row is not correctly indented. – Andrea Spadaccini Feb 02 '11 at 18:36
  • 1
    Why are you posting important information as a comment to your answer? you know that you can edit your answer, right? – SilentGhost Feb 02 '11 at 18:38
  • I thought that the information on the answer would be enough. I'll however add it to the answer, thanks. :) – Andrea Spadaccini Feb 02 '11 at 18:39
  • yes./.ur right...but how do i make it correct? I am seeing on my notepad++ perfectly in the order. – user597293 Feb 02 '11 at 18:45
  • I don't know how your editor works, but I found this question that should help you: http://stackoverflow.com/questions/455037/notepad-tabs-to-spaces – Andrea Spadaccini Feb 02 '11 at 18:47
  • 1
    @user59793: Make up your mind and use either tabs only or spaces only (spaces are more common and recommended in the one widely-followed coding style, [PEP 8](http://www.python.org/dev/peps/pep-0008/) so you should propably just stick with that). –  Feb 02 '11 at 18:47
5

It is your quotes for example on line:

self.lineEdit.setText(’My Generic Device Name’)

try this:

from brisa.core.reactors.qtreactor import QtReactor
reactor = QtReactor()
from brisa.core import config
from brisa.upnp.device import Device
from brisa.upnp.device.service import Service, StateVariable
class QtDevice(QtGui.QWidget):
     def __init__(self):

         QtGui.QWidget.__init__(self)
         self.verticalLayout = QtGui.QVBoxLayout(self)
         self.title = QtGui.QLabel("Qt Simple Device")
         font = QtGui.QFont()
         font.setPointSize(15)
         self.title.setFont(font)
         self.title.setAlignment(QtCore.Qt.AlignCenter)
         self.verticalLayout.addWidget(self.title)
         self.lineEdit = QtGui.QLineEdit(self)
         self.verticalLayout.addWidget(self.lineEdit)
         self.search_btn = QtGui.QPushButton("Start Device", self)
         self.verticalLayout.addWidget(self.search_btn)
         QtCore.QObject.connect(self.search_btn, QtCore.SIGNAL("clicked()"), self.start)
         self.stop_btn = QtGui.QPushButton("Stop Device", self)
         self.verticalLayout.addWidget(self.stop_btn)
         QtCore.QObject.connect(self.stop_btn, QtCore.SIGNAL("clicked()"), self.stop)
         self.lineEdit.setText('My Generic Device Name')
         self.root_device = None
         self.upnp_urn = 'urn:schemas-upnp-org:device:MyDevice:1'


     def _add_root_device(self):
         project_page = 'http://brisa.garage.maemo.org'
         serial_no = config.manager.brisa_version.replace('.', '').rjust(7, '0')
         self.root_device = Device(self.upnp_urn,str(self.lineEdit.text()),
                                    manufacturer='',
                                    manufacturer_url=,
                                    model_description=' '

                                    model_name='',
                                    model_number=,
                                    model_url=,
                                    serial_number=)  


     def _add_services(self):
         service_name = 'MyService'
         service_type = 'urn:schemas-upnp-org:service:MyService:1'
         myservice = Service(service_name, service_type, '')
         var = StateVariable(self, "A_ARG_TYPE_Variable",True, False, "string")
         myservice.add_state_variable(var)
         self.root_device.add_service(myservice)

    def _load(self):
         self._add_root_device()
         self._add_services()
         def start(self):
         self.stop()
         self._load()
         self.root_device.start()
         reactor.add_after_stop_func(self.root_device.stop)  

     def stop(self):
         if self.root_device:
             self.root_device.stop()
             self.root_device = None

def main():
     qt_dev = QtDevice()
     qt_dev.show()
     reactor.main()
if __name__ == '__main__':
     main()   
garnertb
  • 9,454
  • 36
  • 38
  • It removes the indentation errors. Thanks. Not it is showing error on manufacturer url...whcih I have not given yet. So may be I will fix it. – user597293 Feb 02 '11 at 18:51
  • 1
    @User59: why is this answer accepted? it has little to do with the question as asked. – SilentGhost Feb 02 '11 at 19:02
3

It looks like you're using the wrong single quote mark. You need to use ', not .

Not sure if this is your problem though.

Falmarri
  • 47,727
  • 41
  • 151
  • 191
  • 1
    +1 to counter downvotes - explain yourself, @downvoters. This is not the exact error OP was asking about, but propably (if it's in the actual source code as well) another source of errors. –  Feb 02 '11 at 18:39
  • I downvoted because this answer doesn't address the actual question being asked. That, and because the person writing the answer admits they don't know if this is the real problem. I look at this from the perspective of someone getting the same error in the future and coming here to solve the problem. Does this answer help solve the problem of an indentation error? No, it does not. – Bryan Oakley Feb 03 '11 at 11:58
  • The question is about syntax errors, and that's a syntax error. – Falmarri Feb 03 '11 at 17:44