Guest User

Untitled

a guest
Jun 9th, 2021
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. from flowlauncher import FlowLauncher, FlowLauncherAPI
  4. import os
  5. from typing import List
  6. import json, os.path
  7. import copy
  8.  
  9.  
  10.  
  11. RESULT_TEMPLATE = {
  12.     "Title": "",
  13.     "SubTitle": "",
  14.     "IcoPath": "Images/app.ico",
  15. }
  16.  
  17. ACTION_TEMPLATE = {
  18.     "JsonRPCAction": {
  19.         "method": "",
  20.         "parameters": [],
  21.         "dontHideAfterAction": False
  22.     }
  23. }
  24.  
  25.  
  26. class Main(FlowLauncher):
  27.     messages_queue = []
  28.    
  29.  
  30.     def this_is_a_test_function(self, args):
  31.         # log_path = os.path.realpath(__file__).replace(os.path.basename(__file__), '') + "ha-commander.log"
  32.         fileTest = open("test.txt", "w")
  33.         fileTest.write("This is a test function!\n")
  34.         fileTest.write(str(args) + "\n")
  35.         fileTest.close()
  36.         # WoxAPI.change_query("ha " + title + " ",True)
  37.         # FlowLauncherAPI.change_query("ha this is a test query lolololol", True)
  38.  
  39.    
  40.  
  41.     def sendNormalMess(self, title: str, subtitle: str):
  42.         message = copy.deepcopy(RESULT_TEMPLATE)
  43.         message["Title"] = title
  44.         message["SubTitle"] = subtitle
  45.  
  46.         self.messages_queue.append(message)
  47.  
  48.     def sendActionMess(self, title: str, subtitle: str, method: str, value: List, dontHide: bool = True):
  49.         # information
  50.         message = copy.deepcopy(RESULT_TEMPLATE)
  51.         message["Title"] = title
  52.         message["SubTitle"] = subtitle
  53.  
  54.         # action
  55.         action = copy.deepcopy(ACTION_TEMPLATE)
  56.         action["JsonRPCAction"]["method"] = method
  57.         action["JsonRPCAction"]["parameters"] = value
  58.         action["JsonRPCAction"]["dontHideAfterAction"] = False
  59.         message.update(action)
  60.  
  61.         self.messages_queue.append(message)
  62.    
  63.  
  64.     def query(self, params: str) -> List[dict]:
  65.         q = params.strip()
  66.         args = q.split(" ")
  67.         # self.sendNormalMess("Normal Message 1", "Subtitle 1: {}".format(args))
  68.         # self.sendNormalMess("Normal Message 2", "Subtitle 2: {}".format(args))
  69.         self.sendActionMess("Action Message 1", "Subtitle: Args: {}".format(args), "this_is_a_test_function", [args], False)
  70.         self.sendActionMess("Action Message 2", "Subtitle: Args: {}".format(args), "Flow.Launcher.ChangeQuery", ["ha new test query", False], False)
  71.  
  72.        
  73.         return self.messages_queue
  74.  
  75.  
  76.  
  77. if __name__ == "__main__":
  78.     Main()
Advertisement
Add Comment
Please, Sign In to add comment