简体   繁体   English

如何自定义(Windows OS)中的pybusyinfo窗口,使其出现在窗口的顶部和其他格式设置选项中?

[英]How to customize pybusyinfo window in (windows OS) to make it appear at top corner of window and the other formatting options?

I am writing a python script to get the climate conditions in particular area every 30 minutes and give a popup notification. 我正在编写一个python脚本,每隔30分钟获取特定区域的气候条件,并给出弹出通知。

This code gives popup at the center of the screen which is annoying.I wish to have the popup similar to notify-send in linux[which appears at right corner] and the message is aligned at the center of pybusyinfo window ,and how to align it to right? 这段代码使弹出窗口位于屏幕中央,这很烦人。我希望弹出窗口类似于linux中的notify-send [出现在右上角],并且消息在pybusyinfo窗口的中央对齐,以及如何对齐它对吗?

Any change of code in pybusyinfo would be helpful. pybusyinfo中的任何代码更改都将有所帮助。

import requests
from bs4 import BeautifulSoup
import datetime,time
import wx
import wx.lib.agw.pybusyinfo as PBI

now = datetime.datetime.now()
hour=now.hour
# gets current time
def main():
    chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

    g_link = 'http://www.accuweather.com/en/in/tambaram/190794/hourly-weather-forecast/190794?hour='+str(hour)
    g_res= requests.get(g_link)
    g_links= BeautifulSoup(g_res.text,"lxml")

    if hour > 18 :
        temp = g_links.find('td', {'class' :'first-col bg-s'}).text
        climate = g_links.find('td', {'class' :'night bg-s icon first-col'}).text
    else :
        temp = g_links.find('td', {'class' :'first-col bg-c'}).text
        climate = g_links.find('td', {'class' :'day bg-c icon first-col'}).text

    for loc in g_links.find_all('h1'):
        location=loc.text

    info = location +' ' + str(now.hour)+':'+str(now.minute)

    #print 'Temp : '+temp

    #print climate

    def showmsg():
        app = wx.App(redirect=False)
        title = 'Weather'
        msg= info+'\n'+temp + '\n'+ climate
        d = PBI.PyBusyInfo(msg,title=title)
        return d    

    if __name__ == '__main__':
        d = showmsg()
        time.sleep(6)

while True:
    main()
    time.sleep(1800)
screen_size = wx.DisplaySize()
d_size = d._infoFrame.GetSize()
pos_x = screen_size[0] - d_size[0] # Right - popup.width (aligned to right side)
pos_y = screen_size[1] - d_size[1] # Bottom - popup.height (aligned to bottom)
d.SetPosition((pos_x,pos_t))
d.Update() # force redraw ... (otherwise your "work " will block redraw)

to align the text you will need to subclass PyBusyFrame 对齐文本,您将需要子类化PyBusyFrame

class MyPyBusyFrame(PBI.PyBusyFrame):
    def OnPaint(self, event):
        """
        Handles the ``wx.EVT_PAINT`` event for L{PyInfoFrame}.

        :param `event`: a `wx.PaintEvent` to be processed.
        """

        panel = event.GetEventObject()

        dc = wx.BufferedPaintDC(panel)
        dc.Clear()

        # Fill the background with a gradient shading
        startColour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_ACTIVECAPTION)
        endColour = wx.WHITE

        rect = panel.GetRect()
        dc.GradientFillLinear(rect, startColour, endColour, wx.SOUTH)

        # Draw the label
        font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
        dc.SetFont(font)

        # Draw the message
        rect2 = wx.Rect(*rect)
        rect2.height += 20

        #############################################
        #  CHANGE ALIGNMENT HERE
        #############################################
        dc.DrawLabel(self._message, rect2, alignment=wx.ALIGN_CENTER|wx.ALIGN_CENTER)

        # Draw the top title
        font.SetWeight(wx.BOLD)
        dc.SetFont(font)
        dc.SetPen(wx.Pen(wx.SystemSettings_GetColour(wx.SYS_COLOUR_CAPTIONTEXT)))
        dc.SetTextForeground(wx.SystemSettings_GetColour(wx.SYS_COLOUR_CAPTIONTEXT))

        if self._icon.IsOk():
            iconWidth, iconHeight = self._icon.GetWidth(), self._icon.GetHeight()
            dummy, textHeight = dc.GetTextExtent(self._title)
            textXPos, textYPos = iconWidth + 10, (iconHeight-textHeight)/2
            dc.DrawBitmap(self._icon, 5, 5, True)
        else:
            textXPos, textYPos = 5, 0

        dc.DrawText(self._title, textXPos, textYPos+5)
        dc.DrawLine(5, 25, rect.width-5, 25)

        size = self.GetSize()
        dc.SetPen(wx.Pen(startColour, 1))
        dc.SetBrush(wx.TRANSPARENT_BRUSH)
        dc.DrawRoundedRectangle(0, 0, size.x, size.y-1, 12)

then you would have to create your own BusyInfo function that instanciated your frame and returns it (see https://github.com/wxWidgets/wxPython/blob/master/wx/lib/agw/pybusyinfo.py#L251 ) 那么您将必须创建自己的BusyInfo函数来实例化框架并返回它(请参阅https://github.com/wxWidgets/wxPython/blob/master/wx/lib/agw/pybusyinfo.py#L251

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM