python / python/cpython

Add tkinter.systray.NotificationHandler — a logging handler which shows log records as desktop notifications

Đang mở
#157,749 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib topic-tkinter type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Feature or enhancement

The tkinter.systray module (gh-153259) wraps the tk sysnotify command in the notify() function. A natural application of desktop notifications is showing warnings and errors reported via the logging module: a GUI application usually has no console, and a message box for every error is too intrusive.

I propose to add the NotificationHandler class to tkinter.systray. It formats the record with the handler's formatter and sends it as a notification. The title of the notification is the title argument, or the level name of the record (e.g. WARNING) by default. The master argument is the Tk window used to send notifications; by default the default root window is looked up when a record is emitted, so the handler can be created before the root window. Failures are reported via handleError(), as usual for logging handlers.

import logging
import tkinter
from tkinter.systray import NotificationHandler

root = tkinter.Tk()
handler = NotificationHandler('My application')
handler.setLevel(logging.WARNING)
logging.getLogger().addHandler(handler)

The handler belongs to tkinter.systray rather than logging.handlers because it is specific to Tk applications: it needs a Tk root window and follows tkinter's rules for the default root and for calls from other threads. logging.handlers should not depend on an optional GUI package.

Linked PRs
  • gh-157760

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với mô-đun tkinter.systray hiện có và hàm notify() của mô-đun đó, sau đó kiểm tra PR gh-157760 được liên kết trước khi thực hiện bất kỳ công việc nào. Kết quả được yêu cầu là một NotificationHandler có nhiệm vụ định dạng các bản ghi, sử dụng title hoặc tên level, phân giải Tk master như mô tả và báo cáo các lỗi thông qua handleError(); không có tệp kiểm thử nào được nêu tên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
desktop
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.