Ejemplo n.º 1
0
def askContinue(parent,settings,message,continueKey,title=_('Warning')):
    """Shows a modal continue query if value of continueKey is false. Returns True to continue.
    Also provides checkbox "Don't show this in future." to set continueKey to true."""
    #--ContinueKey set?
    if settings.get(continueKey):
        return wx.ID_OK
    #--Generate/show dialog
    dialog = wx.Dialog(parent,wx.ID_ANY,title,size=(350,200),style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
    icon = wx.StaticBitmap(dialog,wx.ID_ANY,
        wx.ArtProvider_GetBitmap(wx.ART_WARNING,wx.ART_MESSAGE_BOX, (32,32)))
    gCheckBox = checkBox(dialog,_("Don't show this in the future."))
    #--Layout
    sizer = vSizer(
        (hSizer(
            (icon,0,wx.ALL,6),
            (staticText(dialog,message,style=wx.ST_NO_AUTORESIZE),1,wx.EXPAND|wx.LEFT,6),
            ),1,wx.EXPAND|wx.ALL,6),
        (gCheckBox,0,wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM,6),
        (hSizer( #--Save/Cancel
            spacer,
            button(dialog,id=wx.ID_OK),
            (button(dialog,id=wx.ID_CANCEL),0,wx.LEFT,4),
            ),0,wx.EXPAND|wx.LEFT|wx.RIGHT|wx.BOTTOM,6),
        )
    dialog.SetSizer(sizer)
    #--Get continue key setting and return
    result = dialog.ShowModal()
    if gCheckBox.GetValue():
        settings[continueKey] = 1
    return result in (wx.ID_OK,wx.ID_YES)
Ejemplo n.º 2
0
def showWryeLog(parent,settings,logText,title='',
                style=0,asDialog=True,icons=None):
    """Convert logText from wtxt to html and display. Optionally, logText can be path to an html file."""
    try:
        import wx.lib.iewin
    except ImportError:
        # Comtypes not available most likely! so do it this way:
        import os
        if not isinstance(logText, Path):
            logPath = settings.get('balt.WryeLog.temp',
                                    Path.getcwd().join('WryeLogTemp.html'))
            cssDir = settings.get('balt.WryeLog.cssDir', GPath(''))
            ins = getStringBuffer(logText+'\n{{CSS:wtxt_sand_small.css}}')
            out = logPath.open('w')
            wtex.WryeText.genHtml(ins,out,cssDir)
            out.close()
            logText = logPath
        os.startfile(logText.s)
        return

    #--Sizing
    pos = settings.get('balt.WryeLog.pos', wx.DefaultPosition)
    size = settings.get('balt.WryeLog.size',(400,400))
    #--Dialog or Frame
    if asDialog:
        window = wx.Dialog(parent,wx.ID_ANY,title,pos=pos,size=size,
            style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
    else:
        window = wx.Frame(parent,wx.ID_ANY,title,pos=pos,size=size,
            style= (wx.RESIZE_BORDER | wx.CAPTION | wx.SYSTEM_MENU | wx.CLOSE_BOX | wx.CLIP_CHILDREN))
        if icons: window.SetIcons(icons)
    window.SetSizeHints(200,200)
    window.Bind(wx.EVT_CLOSE, lambda *a: showLogClose(settings, *a))
    #--Text
    textCtrl = wx.lib.iewin.IEHtmlWindow(window, wx.ID_ANY, style = wx.NO_FULL_REPAINT_ON_RESIZE)
    if not isinstance(logText, Path):
        logPath = settings.get('balt.WryeLog.temp', Path.getcwd().join('WryeLogTemp.html'))
        cssDir = settings.get('balt.WryeLog.cssDir', GPath(''))
        ins = getStringBuffer(logText+'\n{{CSS:wtxt_sand_small.css}}')
        out = logPath.open('w')
        wtex.WryeText.genHtml(ins,out,cssDir)
        out.close()
        logText = logPath
    textCtrl.Navigate(logText.s,0x2) #--0x2: Clear History
    #--Buttons
    bitmap = wx.ArtProvider_GetBitmap(wx.ART_GO_BACK,wx.ART_HELP_BROWSER, (16,16))
    gBackButton = bitmapButton(window,bitmap,onClick=lambda evt: textCtrl.GoBack())
    bitmap = wx.ArtProvider_GetBitmap(wx.ART_GO_FORWARD,wx.ART_HELP_BROWSER, (16,16))
    gForwardButton = bitmapButton(window,bitmap,onClick=lambda evt: textCtrl.GoForward())
    gOkButton = button(window,id=wx.ID_OK,onClick=lambda event: window.Close())
    gOkButton.SetDefault()
    if not asDialog:
        window.SetBackgroundColour(gOkButton.GetBackgroundColour())
    #--Layout
    window.SetSizer(
        vSizer(
            (textCtrl,1,wx.EXPAND|wx.ALL^wx.BOTTOM,2),
            (hSizer(
                gBackButton,
                gForwardButton,
                spacer,
                gOkButton,
                ),0,wx.ALL|wx.EXPAND,4),
            )
        )
    #--Show
    if asDialog:
        window.ShowModal()
        if window:
            settings['balt.WryeLog.pos'] = window.GetPositionTuple()
            settings['balt.WryeLog.size'] = window.GetSizeTuple()
            window.Destroy()
    else:
        window.Show()
Ejemplo n.º 3
0
def showLog(parent,settings,logText,title='',style=0,
            asDialog=True,fixedFont=False,icons=None,size=True,question=False):
    """Display text in a log window"""
    #--Sizing
    pos = settings.get('balt.LogMessage.pos',wx.DefaultPosition)
    if size:
        size = settings.get('balt.LogMessage.size',(400,400))
    #--Dialog or Frame
    if asDialog:
        window = wx.Dialog(parent,wx.ID_ANY,title,pos=pos,size=size,
                           style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
    else:
        window = wx.Frame(parent,wx.ID_ANY,title,pos=pos,size=size,
            style= (wx.RESIZE_BORDER | wx.CAPTION | wx.SYSTEM_MENU | wx.CLOSE_BOX | wx.CLIP_CHILDREN))
        if icons: window.SetIcons(icons)
    window.SetSizeHints(200,200)
    window.Bind(wx.EVT_CLOSE, lambda *a: showLogClose(settings, *a))
    window.SetBackgroundColour(wx.NullColour) #--Bug workaround to ensure that default colour is being used.
    #--Text
    textCtrl = wx.TextCtrl(window,wx.ID_ANY,logText,style=wx.TE_READONLY|wx.TE_MULTILINE|wx.TE_RICH2|wx.SUNKEN_BORDER  )
    if fixedFont:
        fixedFont = wx.SystemSettings_GetFont(wx.SYS_ANSI_FIXED_FONT )
        fixedFont.SetPointSize(8)
        fixedStyle = wx.TextAttr()
        #fixedStyle.SetFlags(0x4|0x80)
        fixedStyle.SetFont(fixedFont)
        textCtrl.SetStyle(0,textCtrl.GetLastPosition(),fixedStyle)
    global gQuestion
    if question:
        gQuestion = False
        #--Buttons
        gYesButton = button(window,id=wx.ID_YES)
        gYesButton.Bind(wx.EVT_BUTTON, lambda evt, temp=window: showQuestionLogCloseYes(evt, temp) )
        gYesButton.SetDefault()
        gNoButton = button(window,id=wx.ID_NO)
        gNoButton.Bind(wx.EVT_BUTTON, lambda evt, temp=window: showQuestionLogCloseNo(evt, temp) )
        #--Layout
        window.SetSizer(
            vSizer(
                (textCtrl,1,wx.EXPAND|wx.ALL^wx.BOTTOM,2),
                hSizer((gYesButton,0,wx.ALIGN_RIGHT|wx.ALL,4),
                    (gNoButton,0,wx.ALIGN_RIGHT|wx.ALL,4))
                )
            )
    else:
        #--Buttons
        gOkButton = button(window,id=wx.ID_OK,onClick=lambda event: window.Close())
        gOkButton.SetDefault()
        #--Layout
        window.SetSizer(
            vSizer(
                (textCtrl,1,wx.EXPAND|wx.ALL^wx.BOTTOM,2),
                (gOkButton,0,wx.ALIGN_RIGHT|wx.ALL,4),
                )
            )
    #--Show
    if asDialog:
        window.ShowModal()
        window.Destroy()
    else:
        window.Show()
    return gQuestion