[GRASS-dev] [GRASS GIS] #2915: i.segment.hierarchical: print statements should be replaced by messages

#2915: i.segment.hierarchical: print statements should be replaced by messages
---------------------------------------------+-------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.4
Component: Addons | Version: unspecified
Keywords: i.segment.hierarchical messages | CPU: Unspecified
Platform: Unspecified |
---------------------------------------------+-------------------------
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 ?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2915&gt;
GRASS GIS <https://grass.osgeo.org>

#2915: i.segment.hierarchical: print statements should be replaced by messages
--------------------------+---------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.4
Component: Addons | Version: unspecified
Resolution: | Keywords: i.segment.hierarchical messages
       CPU: Unspecified | Platform: Unspecified
--------------------------+---------------------------------------------

Comment (by zarch):

Replying to [ticket:2915 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()
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2915#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#2915: i.segment.hierarchical: print statements should be replaced by messages
--------------------------+---------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.7
Component: Addons | Version: unspecified
Resolution: | Keywords: i.segment.hierarchical messages
       CPU: Unspecified | Platform: Unspecified
--------------------------+---------------------------------------------

Comment (by martinl):

Still relevant?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2915#comment:5&gt;
GRASS GIS <https://grass.osgeo.org>