<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Thanks Vaclav,<br>
    I agree that it is a bit of a dirty implementation, but I guess I
    just wanted to make this work quickly.<br>
    First to your copy-paste solution: I was more looking for something
    more interactive/clickable to precisely avoid the
    typing/reformatting. Something to seamlessly parse a few arguments
    to existing modules/addons or even scripts.<br>
    Taking on your comments about the non-dependency and sqlite DB
    issue, I will rewrite g.gui.triggers to work with a file in
    ~/.grass7 and the existence of which could then be checked in the
    dbmgr.base file and the gui_core.query file. There could be a
    'Launch...' section in the right-click menu maybe?<br>
    I'll update you once I have come that far and maybe you can play
    around with it to see if it's useful for general inclusion.<br>
    <br>
    Best,<br>
    Michel<br>
    <br>
    <div class="moz-cite-prefix">On 08/19/2015 06:30 PM, Vaclav Petras
      wrote:<br>
    </div>
    <blockquote
cite="mid:CABo5uVttZb1wHeu7kF7G4F1dTtCh4-Xgun3tJGvX=f-sexm5Pw@mail.gmail.com"
      type="cite">
      <div dir="ltr"><br>
        <div class="gmail_extra"><br>
          <div class="gmail_quote">On Wed, Aug 19, 2015 at 11:33 AM,
            Michel Wortmann <span dir="ltr"><<a
                moz-do-not-send="true"
                href="mailto:wortmann@pik-potsdam.de" target="_blank">wortmann@pik-potsdam.de</a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div text="#000000" bgcolor="#FFFFFF"> Hi Vaclav,<br>
                thanks for the ideas. I have already implemented an idea
                which I find works very well and is based on an add on,
                which works well with GRASS' existing addon structure.
                But it did require me to add a few lines in the
                gui_core.query as well as the dbmgr.base python files,
                which I guess is the downside of it. Here is the
                implementation:<br>
                <br>
                g.gui.triggers is a little addon that manages a sqlite
                table (__triggers__) in the current mapset, it records
                the vector name, the command and the argument=column
                mapping and additional arguments to be used. It can also
                be called with the arguments map= and cat= to actually
                do the triggering of the command listed in the table for
                the respective cat.<br>
                <br>
                To implement the dbmgr double-clicking, I add the
                following to dbmgr.base to call g.gui.triggers if the
                addon exists and if the vector is listed in the
                __triggers__ table.<br>
                <br>
                %%%% in header:<br>
                try: import guitriggers<br>
                except: guitriggers=None<br>
                <br>
                %%%% line 1063<br>
                        if guitriggers and
                guitriggers.hasTrigger(**{a:self.dbMgrData['mapDBInfo'].layers[layer][a]
                for a in ['table','database']}):<br>
                            win.Bind(wx.EVT_LEFT_DCLICK,
                self.OnDataTrigger)<br>
                            win.Bind(wx.EVT_COMMAND_LEFT_DCLICK,
                self.OnDataTrigger)<br>
                        elif UserSettings.Get(group = 'atm', key =
                'leftDbClick', subkey = 'selection') == 0:<br>
                %%%%<br>
                <br>
                %%%% anywhere as method to the DbMgrBrowsePage class<br>
                    def OnDataTrigger(self,event):<br>
                        info  =
                self.dbMgrData['mapDBInfo'].layers[self.selLayer]<br>
                        tlist =
                self.FindWindowById(self.layerPage[self.selLayer]['data'])<br>
                        # get categories<br>
                        cats = map(int,tlist.GetSelectedItems())<br>
                       
                guitriggers.trigger(info['table'],cats,database=info['database'])<br>
                        return<br>
                %%%%<br>
                <br>
                <br>
                To implement the selection idea in the map display, I
                added a check box to the query dialog (if the addon
                exists). If it is checked, the command listed in the
                __triggers__ table is executed. I added the following to
                the gui_core.query file:<br>
                <br>
                %%%% in header:<br>
                try: import guitriggers<br>
                except: guitriggers=None<br>
                <br>
                %%%% in QueryDialog.__init__ line 77<br>
                        if guitriggers:<br>
                           self.trigger = wx.CheckBox(self.panel,
                label=_("Enable trigger"))<br>
                           self.trigger.SetValue(False)<br>
                           hbox = wx.BoxSizer(wx.HORIZONTAL)<br>
                           hbox.Add(item=self.trigger, proportion=0,
                flag=wx.EXPAND | wx.RIGHT, border=5)<br>
                           self.mainSizer.Add(item=hbox, proportion=0,
                flag=wx.EXPAND | wx.ALL, border=5)<br>
                %%%%<br>
                <br>
                %%%% in QueryDialog.SetData, line 99<br>
                        if guitriggers and self.trigger.IsChecked():<br>
                            for m in data[1:]:<br>
                                info = m[m.keys()[0]]
                #unpack             <br>
                                try:
                guitriggers.trigger(info['Table'].split()[0],[info['Category']],<br>
                                                   
                database=info['Database'].split()[0])<br>
                                except: pass<br>
                %%%%<br>
                <br>
                I have not found any major flaws with this approach, the
                only downside being the few added lines in the existing
                code (which are all pretty much copied from existing
                functionalities). The 'guitriggers' module is so far
                still imported as a python module, but I guess it doesnt
                take much to check whether it's an installed addon.<br>
              </div>
            </blockquote>
            <div><br>
            </div>
            <div>I'm glad you got that far. I don't have any opinion on
              this "triggers" yet. This seems like a general "custom
              action" system; something like a limited plugin system. 
              It could be quite useful but we should have a more general
              analysis of this before putting something to the main code
              base. Also, typically for wxGUI, some refactoring is
              needed before adding new features.<br>
              <br>
              Anyway, you should not put the "triggers" to SQLite
              database of the current Mapset, that's for data. This is
              GUI and behavior, this should go to ~/.grass7. It can be
              text file or anything else.<br>
              <br>
            </div>
            <div>Also, main code should not depend on an addon, either
              main code should implement a more general mechanism or
              addon's code should be moved to the main code.<br>
            </div>
            <div><br>
            </div>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div text="#000000" bgcolor="#FFFFFF"> <br>
                Let me know if you want more details or would like me to
                upload the addon to the GRASS addon repro.<br>
              </div>
            </blockquote>
            <div><br>
            </div>
            <div>When ready, please post here the code of the module to
              test and diff for the changes in existing code.<br>
              <br>
            </div>
            <div>Vaclav<br>
            </div>
            <div> </div>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div text="#000000" bgcolor="#FFFFFF"> Regards,<br>
                Michel
                <div>
                  <div class="h5"><br>
                    <br>
                    <br>
                    <br>
                    <div>On 08/19/2015 03:47 PM, Vaclav Petras wrote:<br>
                    </div>
                    <blockquote type="cite">
                      <div dir="ltr">Hi Michel,<br>
                        <div>
                          <div class="gmail_extra"><br>
                            <div class="gmail_quote">On Thu, Aug 13,
                              2015 at 10:32 AM, Michel Wortmann <span
                                dir="ltr"><<a moz-do-not-send="true"
                                  href="mailto:wortmann@pik-potsdam.de"
                                  target="_blank">wortmann@pik-potsdam.de</a>></span>
                              wrote:<br>
                              <blockquote class="gmail_quote"
                                style="margin:0 0 0 .8ex;border-left:1px
                                #ccc solid;padding-left:1ex">Dear Devs,<br>
                                what would be the best and least
                                invasive way of receiving input from the
                                grass GUI to use in python scripts. The
                                following functionalities are on my
                                mind:<br>
                                <br>
                                - when double-clicking a line in the
                                dbmgr, trigger a script/function using
                                the line's content as input<br>
                                - when selecting a feature in the map
                                display, trigger a script/function using
                                the query results as input<br>
                                <br>
                                I guess changing the effect of a dbmgr
                                line double-click can only be changed by
                                fiddling with the gui/wxpython/dbmgr
                                module files. Receiving the select query
                                results as input on the command line is
                                in theory possible with the 'Redirect to
                                console' option in the select pop-up,
                                but how can I read the GUI console?<br>
                                <br>
                                In case someone had similar intentions
                                and has some clues, I would appreciate
                                hearing about them.<br>
                              </blockquote>
                              <div><br>
                              </div>
                              <div>these are reasonable requests. I
                                suppose this would make your module more
                                convenient for users to use.
                                Unfortunately, there is no easy way.
                                Anyway, these are the options:<br>
                                <br>
                                1. Create a new functionality similar to
                                the button to select coordinates. Module
                                would specify option type as feature ID
                                and when the module's GUI is started
                                from the main GUI, the button is
                                associated with Map Display. User clicks
                                the button. Clicks in Map Display. Some
                                query function is invoked and result
                                goes to the input field in module's GUI.
                                There is already a "template" for
                                implementing this - the coordinates
                                button.<br>
                                <br>
                              </div>
                              <div>2. Create a plugin system for wxGUI
                                (thanks to Python relatively simple) and
                                writing a plugin. If somebody wants to
                                do that, please contact me, I can give
                                you few pointers.</div>
                              <div><br>
                              </div>
                              <div>3. Create a new feature in GUI
                                Command Console to start a module with
                                current output in console as standard
                                input for the module. I'm not sure if
                                this would overcomplicate things or how
                                this can be made actually convenient for
                                users, but it is en interesting option.<br>
                              </div>
                              <div><br>
                              </div>
                              <div>4. For attribute data (dbmgr), "copy
                                and paste" the line's content can be
                                enough. Same for query results. For
                                query, the copy is implemented but the
                                format might not be good for parsing.
                                For dbmgr, the button to copy should be
                                easy to add. This seems convenient
                                enough for user.<br>
                                <br>
                              </div>
                              <div>I suggest to first check the option
                                number 4. The most general option is
                                number 2 but when implemented, it would
                                require writing a module to do the
                                processing and then also a plugin for
                                GUI to do the interaction. In this light
                                option number 1 seems as a good way.<br>
                              </div>
                              <br>
                            </div>
                            <div class="gmail_quote">Best,<br>
                            </div>
                            <div class="gmail_quote">Vaclav<br>
                            </div>
                          </div>
                        </div>
                      </div>
                    </blockquote>
                    <br>
                  </div>
                </div>
              </div>
            </blockquote>
          </div>
          <br>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>