Opened 9 years ago

Last modified 5 years ago

#2915 new defect

i.segment.hierarchical: print statements should be replaced by messages

Reported by: mlennert Owned by: grass-dev@…
Priority: normal Milestone: 7.8.3
Component: Addons Version: unspecified
Keywords: i.segment.hierarchical messages Cc:
CPU: Unspecified Platform: Unspecified

Description

i.segment.hierarchical contains many print() statements. These should all be replaced by messages that can be "quieted".

I'm not very familiar with the message interface in pygrass: is there a need to create a new Messenger() for each different function & class ?

Change History (7)

in reply to:  description comment:1 by zarch, 9 years ago

Replying to mlennert:

i.segment.hierarchical contains many print() statements. These should all be replaced by messages that can be "quieted".

I'm not very familiar with the message interface in pygrass: is there a need to create a new Messenger() for each different function & class ?

You can get a Messenger instance using the get_msgr function.

from grass.pygrass.messages import get_msgr

def func0():
    msgr = get_msgr()
    msgr.message("Said something...")

def func1():
    msgr = get_msgr()
    msgr.message("Said something else...")

class MyClass(object):
    msgr = get_msgr()

    def mth(self):
        self.msgr.message("That's all!")
        
func0()
func1()
MyClass().mth()

or you can create a global variable

from grass.pygrass.messages import get_msgr

msgr = get_msgr()


def func0():
    msgr.message("Said something...")

def func1():
    msgr.message("Said something else...")

class MyClass(object):
    def mth(self):
        msgr.message("That's all!")
        
func0()
func1()
MyClass().mth()

comment:2 by martinl, 9 years ago

Milestone: 7.0.47.0.5

comment:3 by neteler, 8 years ago

Milestone: 7.0.57.0.6

comment:4 by neteler, 7 years ago

Milestone: 7.0.67.0.7

comment:5 by martinl, 6 years ago

Still relevant?

comment:6 by martinl, 6 years ago

Milestone: 7.0.7

Remove Milestone from Addons bugreports.

comment:7 by neteler, 5 years ago

Milestone: 7.8.3
Note: See TracTickets for help on using tickets.