Skip to content

Commit

Permalink
Merge pull request #1 from Ksengine/Ksengine-patch-qt
Browse files Browse the repository at this point in the history
auto icon
  • Loading branch information
Ksengine committed Oct 20, 2020
2 parents 51f49e7 + e4efec1 commit 5ccb75f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions webview/__init__.py
Expand Up @@ -118,7 +118,7 @@ def create_window(title, url=None, html=None, js_api=None, width=800, height=600
resizable=True, fullscreen=False, min_size=(200, 100), hidden=False,
frameless=False, easy_drag=True,
minimized=False, on_top=False, confirm_close=False, background_color='#FFFFFF',
transparent=False, text_select=False):
transparent=False, text_select=False, auto_title=False, auto_icon=False):
"""
Create a web view window using a native GUI. The execution blocks after this function is invoked, so other
program logic must be executed in a separate thread.
Expand All @@ -138,6 +138,8 @@ def create_window(title, url=None, html=None, js_api=None, width=800, height=600
:param background_color: Background color as a hex string that is displayed before the content of webview is loaded. Default is white.
:param text_select: Allow text selection on page. Default is False.
:param transparent: Don't draw window background.
:param auto_title: Automatically set title of webpage as window title
:param auto_icon: Automatically set icon of webpage as window icon
:return: window object.
"""

Expand All @@ -150,7 +152,7 @@ def create_window(title, url=None, html=None, js_api=None, width=800, height=600
window = Window(uid, make_unicode(title), url, html,
width, height, x, y, resizable, fullscreen, min_size, hidden,
frameless, easy_drag, minimized, on_top, confirm_close, background_color,
js_api, text_select, transparent)
js_api, text_select, transparent, auto_title, auto_icon)

windows.append(window)

Expand Down
10 changes: 8 additions & 2 deletions webview/platforms/qt.py
Expand Up @@ -89,7 +89,7 @@ def call(self, func_name, param, value_id):
class WebView(QWebView):
def __init__(self, parent=None):
super(BrowserView.WebView, self).__init__(parent)

if parent.frameless and parent.easy_drag:
QApplication.instance().installEventFilter(self)
self.setMouseTracking(True)
Expand Down Expand Up @@ -278,7 +278,13 @@ def __init__(self, window):

self.view.setPage(BrowserView.WebPage(self.view))
self.view.page().loadFinished.connect(self.on_load_finished)


if getattr(window, 'auto_title, False): # automatically set webpage title as window title
self.view.setWindowTitle.connect(self.set_title)

if getattr(window, 'auto_icon, False): # automatically set webpage icon as window icon
self.view.iconChanged.connect(lambda : self.setWindowIcon(self.view.icon()))

self.setCentralWidget(self.view)

self.create_window_trigger.connect(BrowserView.on_create_window)
Expand Down
4 changes: 3 additions & 1 deletion webview/window.py
Expand Up @@ -46,7 +46,7 @@ def _loaded_call(function):
class Window:
def __init__(self, uid, title, url, html, width, height, x, y, resizable, fullscreen,
min_size, hidden, frameless, easy_drag, minimized, on_top, confirm_close,
background_color, js_api, text_select, transparent):
background_color, js_api, text_select, transparent, auto_title, auto_icon):
self.uid = uid
self.title = make_unicode(title)
self.original_url = None if html else url # original URL provided by user
Expand All @@ -68,6 +68,8 @@ def __init__(self, uid, title, url, html, width, height, x, y, resizable, fullsc
self.on_top = on_top
self.minimized = minimized
self.transparent = transparent
self.auto_title = auto_title # auto_title
self.auto_icon = auto_icon # auto_icon

self._js_api = js_api
self._functions = {}
Expand Down

0 comments on commit 5ccb75f

Please sign in to comment.