First time here? Check out the FAQ!
1

Is it possible to add a function to automatically add headers?

I want to automatically update the header information when saving, and the format can be defined by myself, like psioniq File Header plugin in vscode, as shown below:

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
######################################################################
########################### yang's header ############################
######################################################################
# File:                                                      xxxx.py #
# Create Data:                                   2026/01/04 11:41:47 #
# Author:                                                  xxxxxxxxx #
# Email:                                       xxxxxxxxx@xxxxxxx.com #
# Last Modified:                                 2026/04/14 14:49:08 #
# Modified By:                                             xxxxxxxxx #
# Copyright (c) 2025 xxxxxxxxxxxxx Culture Media Co., Ltd            #
######################################################################

I wrote a plugin myself, but it has some bugs, the performance doesn't feel high, and there's no way to customize the format in the presets. To change the format, I have to modify the code. I wonder if the official team could add a similar feature, and also allow customization of formats within the presets.

mightyang's avatar
11
mightyang
asked 2026-05-15 02:35:30 +0000
Wingware Support's avatar
4.3k
Wingware Support
updated 2026-06-01 21:22:22 +0000
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

0

We don't have this feature now but will try to add it in the future. Thanks!

Wingware Support's avatar
4.3k
Wingware Support
answered 2026-05-20 20:34:10 +0000
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

Okay, could you help me take a look at this plugin I wrote? It works fine, but there is one issue. For example, if the header information has 5 lines, when the scrollbar scrolls to exactly show the 5th line, activating the plugin to update the header information will cause the scrollbar to automatically scroll to display the entire header, instead of staying at the 5th line position. If the plugin is activated to update when the header is not visible, there is no problem.

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
######################################################################
########################### yang's header ############################
######################################################################
# File:                                                autoheader.py #
# Create Data:                                   2026/02/28 11:22:14 #
# Author:                                                       xxxx #
# Email:                                            xxxx@hotmail.com #
# Last Modified:                                 2026/05/22 11:52:19 #
# Modified By:                                                 xxxXx #
# Copyright (c) 2025 xxxx Culture Media Co., Ltd                     #
######################################################################


import wingapi
import copy
import datetime
import platform
import subprocess
from pathlib import Path

app = wingapi.gApplication
_plugin_id = [None]
_preSaveId = [None]
_fileType = ['.py']


class header():
    def __init__(self, doc):
        # chars
        self.commentChar = "#"
        self.aroundChar = " "
        self.filler = " "  # space
        # attributes
        self.docObj = doc
        self.title = "Comment"
        self.fileNameLabel = "File:"
        self.fileName = ""
        self.fullFileName = ""
        self.emailLabel = "Email:"
        self.email = ""
        self.createTimeLabel = "Create Data:"
        self.modifyDataLabel = "Last Modified:"
        self.modifyByLabel = "Modified By:"
        self.modifyBy = ""
        self.authorLabel = "Author:"
        self.author = ""
        self.copyRightLine = ""
        # lines
        self.lines = {"preLines": [], "startLines": [], "titleLines": [], "bodyLines": [], "endLines": [], "postLines": [], }
        self.actualLines = {}
        self.bodyLines = []
        # controls
        self.maxChar = 70  # if less than bodyLine length, use length of bodyLine.
        self.bodyLineMax = self.maxChar
        self.withFullName = False
        self.lastSpaceLineCount = 2
        self.withStartLine = True
        self.withTitleLine = True

    def setheader(self):
        self.updateHeader()
        f = self.docObj.GetAsFileObject()
        charCount = 0
        # check preLines
        for preLine in self.actualLines["preLines"]:
            docLine = f.readline()
            if docLine.rstrip("\n") != preLine:
                print("preLines is different, insert all.")
                self.docObj.InsertChars(0, str(self))
                return True
            charCount += len(docLine)
        # check startLines
        if self.withStartLine:
            for startLine in self.actualLines["startLines"]:
                docLine = f.readline()
                if docLine.rstrip("\n") != startLine:
                    print("startLines is different, insert all.")
                    self.docObj.InsertChars(0, str(self))
                    return True
                charCount += len(docLine)
        # check ...
(more)
mightyang's avatar
11
mightyang
answered 2026-05-22 04:00:01 +0000
edit flag offensive 0 remove flag delete link

Comments

Try calling GetFirstVisibleLine on the editor object before setting the text, then use ScrollToLine(lineno, pos='top') afterward to restore the scroll position.

Wingware Support's avatar Wingware Support (2026-05-22 11:43:36 +0000) edit
1

it works, thanks~

mightyang's avatar mightyang (2026-06-03 09:55:35 +0000) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer