-
-
Notifications
You must be signed in to change notification settings - Fork 548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to set the icon of the window #786
Changes from 9 commits
061cf48
fcc162b
2413ac8
b1127d3
7f25462
74f8b4d
150027b
f17f124
239c9e4
084cf3c
2eadec3
ad37b08
9915792
8caa7e2
e4d809a
8c489fb
1d7a225
63ac08f
73ed9e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,9 @@ | |
import shutil | ||
import sys | ||
import webbrowser | ||
import platform | ||
|
||
from ctypes import windll | ||
from ctypes import windll, wintypes | ||
from functools import wraps | ||
from uuid import uuid1 | ||
from threading import Event | ||
|
@@ -252,6 +253,20 @@ def _create(): | |
|
||
instances[window.uid] = browser | ||
window.shown.set() | ||
|
||
if window.icon: | ||
icon = window.icon+".ico" | ||
if os.path.isfile(icon): | ||
smallx = windll.user32.GetSystemMetrics(49) #SM_CXSMICON | ||
smally = windll.user32.GetSystemMetrics(50) #SM_CYSMICON | ||
small_icon = windll.user32.LoadImageW(0, icon, 1, smallx, smally, 0x00000010) | ||
windll.user32.SendMessageW(handle, 0x0080, 0, small_icon) | ||
|
||
bigx = windll.user32.GetSystemMetrics(11) #SM_CXICON | ||
bigy = windll.user32.GetSystemMetrics(12) #SM_CYICON | ||
big_icon = windll.user32.LoadImageW(0, icon, 1, bigx, bigy, 0x00000010) | ||
windll.user32.SendMessageW(handle, 0x0080, 1, big_icon) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code can be moved into winforms.py. CEF is just a component inside the winform. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, sure. I will try to do it this week-end |
||
|
||
|
||
window_info = cef.WindowInfo() | ||
window_info.SetAsChild(handle) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
logger.debug('Using Qt %s' % QT_VERSION_STR) | ||
|
||
from PyQt5.QtWidgets import QMainWindow, QApplication, QFileDialog, QMessageBox, QAction | ||
from PyQt5.QtGui import QColor, QScreen | ||
from PyQt5.QtGui import QColor, QScreen, QIcon | ||
|
||
try: | ||
from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView, QWebEnginePage as QWebPage | ||
|
@@ -58,6 +58,7 @@ class BrowserView(QMainWindow): | |
|
||
create_window_trigger = QtCore.pyqtSignal(object) | ||
set_title_trigger = QtCore.pyqtSignal(str) | ||
set_icon_trigger = QtCore.pyqtSignal(str) | ||
load_url_trigger = QtCore.pyqtSignal(str) | ||
html_trigger = QtCore.pyqtSignal(str, str) | ||
dialog_trigger = QtCore.pyqtSignal(int, str, bool, str, str) | ||
|
@@ -129,7 +130,7 @@ def show_inspector(self): | |
url = 'http://localhost:{}'.format(BrowserView.inspector_port) | ||
print(url) | ||
window = Window('web_inspector', title, url, '', 700, 500, None, None, True, False, | ||
(300, 200), False, False, False, False, False, False, '#fff', None, False, False, None) | ||
(300, 200), False, False, False, False, False, False, '#fff', None, False, False, '') | ||
window.localization = self.parent().localization | ||
|
||
inspector = BrowserView(window) | ||
|
@@ -232,6 +233,8 @@ def __init__(self, window): | |
self.title = window.title | ||
self.setWindowTitle(window.title) | ||
|
||
self.setWindowIcon(QIcon(window.icon)) | ||
|
||
# Set window background color | ||
self.background_color = QColor() | ||
self.background_color.setNamedColor(window.background_color) | ||
|
@@ -299,6 +302,7 @@ def __init__(self, window): | |
self.current_url_trigger.connect(self.on_current_url) | ||
self.evaluate_js_trigger.connect(self.on_evaluate_js) | ||
self.set_title_trigger.connect(self.on_set_title) | ||
self.set_icon_trigger.connect(self.on_set_icon) | ||
self.on_top_trigger.connect(self.on_set_on_top) | ||
|
||
if is_webengine and platform.system() != 'OpenBSD': | ||
|
@@ -332,6 +336,10 @@ def __init__(self, window): | |
def on_set_title(self, title): | ||
self.setWindowTitle(title) | ||
|
||
|
||
def on_set_icon(self, icon): | ||
self.setWindowIcon(QIcon(icon)) | ||
|
||
def on_file_dialog(self, dialog_type, directory, allow_multiple, save_filename, file_filter): | ||
if dialog_type == FOLDER_DIALOG: | ||
self._file_name = QFileDialog.getExistingDirectory(self, self.localization['linux.openFolder'], options=QFileDialog.ShowDirsOnly) | ||
|
@@ -462,6 +470,9 @@ def on_load_finished(self): | |
def set_title(self, title): | ||
self.set_title_trigger.emit(title) | ||
|
||
def set_icon(self, icon): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set_icon support should be added to winforms as well. |
||
self.set_icon_trigger.emit(icon) | ||
|
||
def get_current_url(self): | ||
self.loaded.wait() | ||
self.current_url_trigger.emit() | ||
|
@@ -631,6 +642,10 @@ def _create(): | |
def set_title(title, uid): | ||
BrowserView.instances[uid].set_title(title) | ||
|
||
def set_icon(icon, uid): | ||
BrowserView.instances[uid].set_icon(icon) | ||
|
||
|
||
|
||
def get_current_url(uid): | ||
return BrowserView.instances[uid].get_current_url() | ||
|
@@ -701,6 +716,9 @@ def get_position(uid): | |
def get_size(uid): | ||
window = BrowserView.instances[uid] | ||
return window.width(), window.height() | ||
|
||
def get_instance(uid): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems debug |
||
return BrowserView.instances[uid] | ||
|
||
|
||
def get_screens(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,9 +47,10 @@ 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, localization): | ||
background_color, js_api, text_select, transparent, localization, icon): | ||
self.uid = uid | ||
self.title = make_unicode(title) | ||
self.icon = icon | ||
self.original_url = None if html else url # original URL provided by user | ||
self.real_url = None # transformed URL for internal HTTP server | ||
self.html = html | ||
|
@@ -160,6 +161,10 @@ def get_elements(self, selector): | |
|
||
return self.evaluate_js(code) | ||
|
||
@_shown_call | ||
def get_instance(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems debug code i have used for test, must be removed |
||
return self.gui.get_instance(self.uid) | ||
|
||
@_shown_call | ||
def load_url(self, url): | ||
""" | ||
|
@@ -198,6 +203,14 @@ def set_title(self, title): | |
""" | ||
self.gui.set_title(title, self.uid) | ||
|
||
@_shown_call | ||
def set_icon(self, icon): | ||
""" | ||
Set a new title of the window | ||
""" | ||
self.gui.set_icon(icon, self.uid) | ||
|
||
|
||
@_loaded_call | ||
def get_current_url(self): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this work with png files? Ie. is it necessary to append the .ico suffix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows require .ico, ways to convert a .png to .ico are a little too complex for me. So I think easier to provide both .ico and .png and so, use a sufixless name of icon