示例#1
0
    def EditControl(self):
        pg_control = GetPage(pgid.CONTROL)

        ctrl_info = pg_control.GetCtrlInfo()

        preview = TextPreview(title=GT(u'Edit Control File'),
                              text=ctrl_info,
                              size=(600, 400),
                              readonly=False)
        AddCustomButtons(preview, (
            wx.ID_SAVE,
            wx.ID_CANCEL,
        ),
                         parent_sizer=True)

        if preview.ShowModal() == wx.ID_SAVE:
            Logger.Debug(__name__, u'Updating control information ...')

            ctrl_info = preview.GetValue()

            depends_data = pg_control.Set(ctrl_info)
            GetPage(pgid.DEPENDS).Set(depends_data)
示例#2
0
    def AddButtons(self, button_ids):
        self.lyt_buttons = AddCustomButtons(self, button_ids)

        self.Sizer.Add(self.lyt_buttons, (4, 2),
                       flag=wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM | lyt.PAD_RTB,
                       border=5)
示例#3
0
class DetailedMessageDialog(BaseDialog, ButtonDialog):
    def __init__(self,
                 parent,
                 title=GT(u'Message'),
                 icon=ICON_INFORMATION,
                 text=wx.EmptyString,
                 details=wx.EmptyString,
                 style=wx.DEFAULT_DIALOG_STYLE,
                 buttons=(wx.ID_OK, ),
                 linewrap=0):

        BaseDialog.__init__(self, parent, wx.ID_ANY, title, style=style)

        # Allow using strings for 'icon' argument
        if isinstance(icon, (unicode, str)):
            icon = wx.Bitmap(icon)

        icon = wx.StaticBitmap(self, wx.ID_ANY, icon)

        txt_message = wx.StaticText(self, label=text)
        if linewrap:
            txt_message.Wrap(linewrap)

        # self.details needs to be empty for constructor
        self.details = wx.EmptyString
        details = details

        # *** Layout *** #

        self.lyt_urls = BoxSizer(wx.VERTICAL)

        # Only set if buttons are added to dialog
        self.lyt_buttons = None

        lyt_main = wx.GridBagSizer(5, 5)
        lyt_main.SetCols(3)
        lyt_main.AddGrowableRow(3)
        lyt_main.AddGrowableCol(2)
        lyt_main.Add(icon, (0, 0), (5, 1),
                     wx.ALIGN_TOP | lyt.PAD_LR | wx.BOTTOM, 20)
        lyt_main.Add(txt_message, (0, 1), (1, 2), lyt.PAD_RT, 20)
        lyt_main.Add(self.lyt_urls, (1, 1), (1, 2), wx.RIGHT, 5)

        self.SetAutoLayout(True)
        self.SetSizer(lyt_main)

        self.AddButtons(buttons)

        if not TextIsEmpty(details):
            # self.details will be set here
            self.CreateDetailedView(details)

        else:
            self.Layout()

            self.Fit()
            self.SetMinSize(self.GetSize())

        self.CenterOnParent()

    ## Add custom buttons to dialog
    #
    #  NOTE: Do not call before self.SetSizer
    #
    #  FIXME: Rename to SetButtons???
    #  FIXME: Should delete any previous buttons
    def AddButtons(self, button_ids):
        self.lyt_buttons = AddCustomButtons(self, button_ids)

        self.Sizer.Add(self.lyt_buttons, (4, 2),
                       flag=wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM | lyt.PAD_RTB,
                       border=5)

    ## Adds a clickable link to the dialog
    def AddURL(self, url):
        if not isinstance(url, Hyperlink):
            url = Hyperlink(self, wx.ID_ANY, label=url, url=url)

        self.lyt_urls.Add(url, 0, wx.ALIGN_CENTER_VERTICAL)

        self.Layout()
        self.Fit()
        self.SetMinSize(self.GetSize())
        self.CenterOnParent()

    ## Shows dialog modal & returns 'confirmed' value
    #
    #  \return
    #	\b \e bool : True if ShowModal return value one of wx.ID_OK, wx.OK, wx.ID_YES, wx.YES
    def Confirmed(self):
        return self.ShowModal() in (wx.ID_OK, wx.OK, wx.ID_YES, wx.YES)

    ## Adds buttons & details text to dialog
    #
    #  \param details
    #		\b \e unicode|str : Detailed text to show in dialog
    def CreateDetailedView(self, details):
        # Controls have not been constructed yet
        if TextIsEmpty(self.details):
            self.btn_details = wx.ToggleButton(self, label=GT(u'Details'))
            #btn_copy = wx.Button(self, label=GT(u'Copy details'))

            self.dsp_details = TextAreaPanel(self,
                                             value=details,
                                             style=wx.TE_READONLY)

            # *** Event handlers *** #

            self.btn_details.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleDetails)
            #btn_copy.Bind(wx.EVT_BUTTON, self.OnCopyDetails)

            layout = self.GetSizer()
            layout.Add(self.btn_details, (2, 1))
            #layout.Add(btn_copy, (2, 2), flag=wx.ALIGN_LEFT|wx.RIGHT, border=5)
            layout.Add(self.dsp_details, (3, 1), (1, 2), wx.EXPAND | wx.RIGHT,
                       5)

            self.ToggleDetails()

        if not TextIsEmpty(details):
            for C in self.GetChildren():
                if isinstance(C, TextAreaPanel):
                    self.details = details
                    C.SetValue(self.details)

                    return True

        return False

    ## Attempts to retrieve button instance matching btn_id
    #
    #  FIXME: This will fail if there are standard buttons in the dialog
    #  FIXME: Retrieving by label doesn't work
    #  \param btn_id
    #	ID of the button instance to retrieve
    #  \return
    #	\b \e wx.Button instance or None
    def GetButton(self, btn_id):
        # Allow search by label
        use_label = not isinstance(btn_id, int)

        if self.lyt_buttons:
            for sizer in self.lyt_buttons.GetChildren():
                sizer = sizer.GetSizer()

                btn_layout = sizer.GetChildren()

                if btn_layout:
                    BTN = btn_layout[0].GetWindow()
                    LBL = None

                    if len(btn_layout) < 2 and isinstance(BTN, wx.Button):
                        LBL = BTN.GetLabel()

                    else:
                        LBL = btn_layout[1]
                        if isinstance(LBL, wx.StaticText):
                            LBL = LBL.GetLabel()

                    if not use_label:
                        if BTN.GetId() == btn_id:
                            return BTN

                    else:
                        if LBL == btn_id:
                            return BTN

    ## TODO: Doxygen
    #
    #  FIXME: Layout initially wrong
    #  TODO: Allow copying details to clipboard
    def OnCopyDetails(self, event=None):
        print(u'DEBUG: Copying details to clipboard ...')

        DetailedMessageDialog(
            self, u'FIXME', ICON_EXCLAMATION,
            u'Copying details to clipboard not functional').ShowModal()
        return

        cb_set = False

        clipboard = wx.Clipboard()
        if clipboard.Open():
            print(u'DEBUG: Clipboard opened')

            details = wx.TextDataObject(self.dsp_details.GetValue())
            print(u'DEBUG: Details set to:\n{}'.format(details.GetText()))

            clipboard.Clear()
            print(u'DEBUG: Clipboard cleared')

            cb_set = clipboard.SetData(details)
            print(u'DEBUG: Clipboard data set')

            clipboard.Flush()
            print(u'DEBUG: Clipboard flushed')

            clipboard.Close()
            print(u'DEBUG: Clipboard cloased')

        del clipboard
        print(u'DEBUG: Clipboard object deleted')

        wx.MessageBox(u'FIXME: Details not copied to clipboard', GT(u'Debug'))

    ## Override inherited method to center on parent window first
    def ShowModal(self, *args, **kwargs):
        if self.Parent:
            self.CenterOnParent()

        return wx.Dialog.ShowModal(self, *args, **kwargs)

    ## TODO: Doxygen
    def SetDetails(self, details):
        return self.CreateDetailedView(details)

    ## TODO: Doxygen
    def ToggleDetails(self, event=None):
        try:
            if self.btn_details.GetValue():
                self.dsp_details.Show()

            else:
                self.dsp_details.Hide()

            self.Layout()
            self.Fit()
            self.SetMinSize(self.GetSize())

            return True

        except AttributeError:
            # Disable toggling details
            self.btn_details.Hide()

            self.Layout()
            self.Fit()
            self.SetMinSize(self.GetSize())

            return False