googleitup.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:InstaGoogling 作者: Ivanca 项目源码 文件源码
def run(self, edit):
        global websocketHandler
        #return
        if websocketHandler.ready is False:
            sublime.error_message("InstaGoogling: No connection ready! " + DEFAULT_ERROR_ADVICE)
            return

        selected_text = ""

        for region in self.view.sel():  
            if not region.empty():  
                # Get the selected text  
                selected_text = self.view.substr(region)
                lang = re.search('(?<=source\.)[^. ]+', self.view.scope_name(region.a))
                if lang != None:
                    selected_text += " " + lang.group(0)

        x, y = self.view.text_to_layout(self.view.visible_region().a)
        offsetx, offsety = self.view.window_to_layout((0,0))
        view_width, view_height = self.view.viewport_extent()

        x -= offsetx
        y -= offsety

        w = int(round(view_width * 0.5))
        h = view_height + 10

        if w > 540:
            w = 540

        x += view_width - w
        # y += 3

        hwnd = self.view.window().hwnd()
        style = win32api.GetWindowLong(hwnd , win32con.GWL_STYLE)

        if style & win32con.WS_CAPTION != 0:
            y += 22

        if self.view.window().is_menu_visible():
            y += 20

        # Lets just offset from the right edge of the screen instead
        if isWindows:
            from win32api import GetSystemMetrics
            screenWidth = GetSystemMetrics(0)
            # 20 so scroll bar is still visible
            x = screenWidth - w - 15

        msg = {
            "request": "open",
            "position": {"x": x, "y": y},
            "size": {"width": w, "height": h},
            "search": selected_text
        }
        jsonmsg = json.dumps(msg)
        websocketHandler.sendMessage(jsonmsg)
        print("Sending JSON message")

        setSettingIsOpen(True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号