Keypirinha / Keypirinha

A fast keystroke launcher for Windows
http://keypirinha.com
1.05k stars 21 forks source link

Custom category not preserved #125

Closed sepich closed 8 years ago

sepich commented 8 years ago

Steps to reproduce: copy test plugin and fix methods like this

    def on_catalog(self):
        self.dbg("On Catalog")
        item = self.create_item(
                category=kp.ItemCategory.USER_BASE + 2,
                label='test cat',
                short_desc='',
                target='test',
                args_hint=kp.ItemArgsHint.ACCEPTED,
                hit_hint=kp.ItemHitHint.NOARGS)

        self.dbg(item.category())
        self.set_catalog([item])

    def on_execute(self, item, action):
        msg = 'On Execute "{}" (category: {})'.format(item, item.category())
        self.dbg(msg)

Result in console:

22:18:19.020 Cat.Cat(26): DEBUG: On Start
22:18:19.022 Cat.Cat(29): DEBUG: On Catalog
22:18:19.027 Cat.Cat(38): DEBUG: 1002
22:18:24.765 Cat.Cat(51): DEBUG: On App Activated
22:18:25.737 Cat.Cat(43): DEBUG: On Suggest "t" (items_chain[0])
22:18:25.862 Cat.Cat(43): DEBUG: On Suggest "te" (items_chain[0])
22:18:26.076 Cat.Cat(43): DEBUG: On Suggest "tes" (items_chain[0])
22:18:26.163 Cat.Cat(43): DEBUG: On Suggest "test" (items_chain[0])
22:18:26.800 Cat.Cat(47): DEBUG: On Execute "test cat" (category: 1001)
22:18:26.913 Cat.Cat(54): DEBUG: On App Deactivated

Desired result:

22:18:26.800 Cat.Cat(47): DEBUG: On Execute "test cat" (category: 1002)

It would be nice to add more details to docs about those USER_BASE/USER_MAX. Novice questions per your note in #95

polyvertex commented 8 years ago

Is the code excerpt you provided the one you actually used to produce this output?

The USER_BASE constant serves as a reference for the plugin developer to define a new category. Categories are declared on a per plugin base so the only rule is not to define a new category with an ID that's in the reserved range (i.e. new id must be in [USER_BASE, USER_MAX]).

polyvertex commented 8 years ago

@sepich Is the code excerpt you provided the one you actually used to produce this output?

sepich commented 8 years ago

Yes, why? Complete file and ini if that matters: https://gist.github.com/sepich/f428cb55360d8fbc0aa1dd1d7cd5d0f9

polyvertex commented 8 years ago

Because the problem you exposed cannot be. Here is the output I got with v2.9.5 and the source code you shared:

Cat.Cat(26): DEBUG: On Start
Cat.Cat(29): DEBUG: On Catalog
Cat.Cat(38): DEBUG: 1002
Cat.Cat(51): DEBUG: On App Activated
Cat.Cat(43): DEBUG: On Suggest "t" (items_chain[0])
Cat.Cat(43): DEBUG: On Suggest "te" (items_chain[0])
Cat.Cat(43): DEBUG: On Suggest "tes" (items_chain[0])
Cat.Cat(43): DEBUG: On Suggest "test" (items_chain[0])
Cat.Cat(43): DEBUG: On Suggest "testc" (items_chain[0])
Cat.Cat(43): DEBUG: On Suggest "" (items_chain[1])
Cat.Cat(43): DEBUG: On Suggest "testc" (items_chain[0])
Cat.Cat(47): DEBUG: On Execute "test cat" (category: 1002)

And a dump of the item created by your plugin (Alt+Enter):

Item properties:
  label:           test cat
  args:            
  short_desc:      
  target:          test
  category:        #1002 (1002)
  args_hint:       accepted
  hit_hint:        noargs
  plugin:          Cat.Cat
  item_id:         12875778517861910943
  loop_on_suggest: false
  data_bag:
sepich commented 8 years ago

Just wanted to report a bug, but as you wish

21:12:41.957 Plugin loaded: Cat.Cat (instance #2)
21:12:41.992 Cat.Cat(26): DEBUG: On Start
21:12:41.996 Cat.Cat(29): DEBUG: On Catalog
21:12:41.997 Cat.Cat(38): DEBUG: 1002
21:12:44.078 Cat.Cat(51): DEBUG: On App Activated
21:12:47.656 Cat.Cat(43): DEBUG: On Suggest "t" (items_chain[0])
21:12:47.783 Cat.Cat(43): DEBUG: On Suggest "te" (items_chain[0])
21:12:47.998 Cat.Cat(43): DEBUG: On Suggest "tes" (items_chain[0])
21:12:48.087 Cat.Cat(43): DEBUG: On Suggest "test" (items_chain[0])
21:12:49.449 Cat.Cat(47): DEBUG: On Execute "test cat" (category: 1001)
21:12:49.462 Cat.Cat(54): DEBUG: On App Deactivated
21:12:52.428 Cat.Cat(51): DEBUG: On App Activated
21:12:52.703 Cat.Cat(43): DEBUG: On Suggest "t" (items_chain[0])
21:12:52.829 Cat.Cat(43): DEBUG: On Suggest "te" (items_chain[0])
21:12:53.006 Cat.Cat(43): DEBUG: On Suggest "tes" (items_chain[0])
21:12:54.951 Item properties:
  label:           test cat
  args:            
  short_desc:      
  target:          test
  category:        #1001 (1001)
  args_hint:       accepted
  hit_hint:        noargs
  plugin:          Cat.Cat
  item_id:         10613152646933304601
  loop_on_suggest: false
  data_bag:
polyvertex commented 8 years ago

Item with category 1001 probably comes from the history, in which case you are testing the wrong item, in which case if you fully type the label of the item in the LaunchBox, you'll see 2 test cat items.

sepich commented 8 years ago

Confirming that, after renaming Keypirinha.history it started return 1002.

         {
            "args_hint" : "accepted",
            "category" : "#1001",
            "hit_hint" : "noargs",
            "id" : 10613152646933304601,
            "label" : "test cat",
            "loop_on_suggest" : false,
            "plugin" : "Cat.Cat",
            "short_desc" : "",
            "target" : "test"
         }

That was unexpected. So choice is:

polyvertex commented 8 years ago