Exemplo n.º 1
0
    def __init__(self,
                 parent,
                 ID=wx.ID_ANY,
                 title=wx.EmptyString,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 style=wx.DEFAULT_DIALOG_STYLE,
                 name=wx.DialogNameStr,
                 allow_custom=False):
        wx.Dialog.__init__(self,
                           parent,
                           ID,
                           title,
                           pos,
                           size,
                           style=style | wx.RESIZE_BORDER,
                           name=name)

        self.check_list = CheckList(self)

        # *** Buttons *** #

        layout_buttons = BoxSizer(wx.HORIZONTAL)

        btn_clear = CreateButton(self, btnid.CLEAR)
        btn_confirm = CreateButton(self, btnid.CONFIRM)
        btn_cancel = CreateButton(self, btnid.CANCEL)

        btn_clear.Bind(wx.EVT_BUTTON, self.OnClearList)

        # FIXME: Correct button order?
        layout_buttons.Add(btn_clear, 0, wx.LEFT, 5)
        layout_buttons.AddStretchSpacer(1)
        layout_buttons.Add(btn_confirm, 0, wx.RIGHT, 5)
        layout_buttons.Add(btn_cancel, 0, wx.RIGHT, 5)

        # *** Layout *** #

        layout_main = BoxSizer(wx.VERTICAL)

        layout_main.Add(self.check_list, 1, wx.EXPAND | wx.ALL, 5)
        layout_main.Add(layout_buttons, 0, wx.EXPAND | wx.BOTTOM, 5)

        if allow_custom:
            btn_add_custom = wx.Button(self, label=GT(u'Add custom'))
            btn_add_custom.Bind(wx.EVT_BUTTON, self.OnAddCustom)

            self.input_add_custom = wx.TextCtrl(self)

            layout_add_custom = BoxSizer(wx.HORIZONTAL)
            layout_add_custom.Add(btn_add_custom, 0, lyt.PAD_LR, 5)
            layout_add_custom.Add(self.input_add_custom, 1, wx.RIGHT, 5)

            layout_main.Insert(1, layout_add_custom, 0, wx.EXPAND)

        self.SetSizer(layout_main)
        self.SetAutoLayout(True)
        self.Layout()

        self.CenterOnParent()
Exemplo n.º 2
0
    def SetModeEasy(self):
        # Add sibling panel to hold menu & rename button
        pnl_top = wx.Panel(self)

        for C in self.GetChildren():
            if isinstance(C, wx.Button):
                C.Reparent(pnl_top)

        # FIXME: Hack
        temp_bar = BorderedPanel(pnl_top)

        menubar = PanelMenuBar(temp_bar)
        menubar.HideBorder()

        menu_add = PanelMenu(menubar, label=GT(u'Add'))
        menu_add.Append(manid.SINGLE, GT(u'Single line section'))
        menu_add.Append(manid.MULTILINE, GT(u'Multi-line section'))

        menubar.AddItem(menu_add)

        self.pnl_bottom = ScrolledPanel(self)

        # *** Banners *** #

        txt_banners = wx.StaticText(self.pnl_bottom, label=GT(u'Banners'))
        banners = ManBanner(self.pnl_bottom)
        pnl_banners = banners.GetPanel()

        # *** Event Handling *** #

        wx.EVT_MENU(self, manid.SINGLE, self.OnAddDocumentSection)
        wx.EVT_MENU(self, manid.MULTILINE, self.OnAddDocumentSection)

        # *** Layout *** #

        # FIXME: Hack
        temp_lyt = BoxSizer(wx.HORIZONTAL)
        temp_lyt.Add(menubar)
        temp_lyt.AddStretchSpacer(1)

        temp_bar.SetSizer(temp_lyt)

        lyt_top = BoxSizer(wx.VERTICAL)
        lyt_top.Add(self.lyt_buttons, 0, wx.EXPAND | wx.ALL, 5)
        # FIXME: temp_bar height is initially wrong
        lyt_top.Add(temp_bar, 0, wx.EXPAND | wx.ALL, 5)

        pnl_top.SetAutoLayout(True)
        pnl_top.SetSizer(lyt_top)

        # FIXME: Use GridBagSizer???
        lyt_bottom = BoxSizer(wx.VERTICAL)
        lyt_bottom.Add(txt_banners, 0, wx.ALIGN_BOTTOM | wx.LEFT | wx.TOP, 5)
        lyt_bottom.Add(pnl_banners, 0, wx.LEFT, 5)
        lyt_bottom.AddStretchSpacer(1)

        self.pnl_bottom.SetAutoLayout(True)
        self.pnl_bottom.SetSizer(lyt_bottom)

        self.lyt_main.Add(pnl_top, 0, wx.EXPAND)
        self.lyt_main.Add(self.pnl_bottom, 1, wx.EXPAND)

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

        # *** Default Sections *** #

        # This calls self.Layout
        self.AddDocumentSection(GT(u'Name'))
        self.AddDocumentSection(GT(u'Synopsis'),
                                style=DEFAULT_MANSECT_STYLE | manid.MULTILINE)
        self.AddDocumentSection(GT(u'Description'),
                                style=DEFAULT_MANSECT_STYLE | manid.MULTILINE)
        self.AddDocumentSection(GT(u'Options'),
                                style=DEFAULT_MANSECT_STYLE | manid.MULTILINE)
        self.AddDocumentSection(GT(u'Examples'),
                                style=DEFAULT_MANSECT_STYLE | manid.MULTILINE)
        self.AddDocumentSection(GT(u'See also'))
Exemplo n.º 3
0
class ManPage(wx.Panel):
    def __init__(self, parent, name=u'manual', easy_mode=True):
        wx.Panel.__init__(self, parent, name=name)

        # False is 'manual', True is 'easy'
        self.SetMode(easy_mode)

    ## Retrieves the child index that contains the object
    #
    #  \param item
    #    Object instance to search for
    #  \return
    #    \b \e Integer index of the item or -1
    def _get_object_section(self, item):
        index = 0

        for C1 in self.pnl_bottom.GetSizer().GetChildren():
            C1 = C1.GetWindow()

            if isinstance(C1, ManPanel):
                for C2 in C1.GetChildren():
                    if C2 == item:
                        return index

            index += 1

        return None

    ## Adds a new child section to the document
    #
    #  \param section_name
    #    \b \e String name of the section
    #  \param style
    #    \b \e Integer style comprised of globals.ident.mainid
    #  \return
    #    \b \e True if new section was added
    def AddDocumentSection(self,
                           section_name=None,
                           style=DEFAULT_MANSECT_STYLE):
        doc_section = ManSect(self.pnl_bottom, section_name, style=style)
        obj_section = doc_section.GetObject()

        if not obj_section:
            return False

        if doc_section.HasStyle(manid.CHOICE | manid.MUTABLE):
            labels = (GT(u'Name'), GT(u'Synopsis'), GT(u'Configuration'),
                      GT(u'Description'), GT(u'Options'), GT(u'Exit status'),
                      GT(u'Return value'), GT(u'Errors'), GT(u'Environment'),
                      GT(u'Files'), GT(u'Versions'), GT(u'Conforming to'),
                      GT(u'Notes'), GT(u'Bugs'), GT(u'Examples'),
                      GT(u'See also'))

            doc_section.Label.Set(labels)

            if section_name:
                doc_section.Label.SetStringSelection(section_name)

            if not doc_section.Label.GetSelection():
                doc_section.Label.SetSelection(0)

        if doc_section.HasStyle(manid.REMOVABLE):
            # FIXME: Replace with checkboxes
            btn_remove = doc_section.GetButton()
            if btn_remove:
                btn_remove.Bind(wx.EVT_BUTTON, self.OnRemoveDocumentSection)

        proportion = 0
        if doc_section.HasStyle(manid.MULTILINE):
            # FIXME: Proportion for multilines is not any bigger
            proportion = 2

        FLAGS = wx.LEFT | wx.RIGHT | wx.TOP

        layout = self.pnl_bottom.GetSizer()
        layout.AddKeepLast(obj_section, proportion, wx.EXPAND | FLAGS, 5)

        self.Layout()

        return True

    ## Retrieves manpage section & contents
    #
    #  \return
    #    \b \e String \b \e tuple of section name & value
    def Get(self):
        return (
            self.GetSection(),
            self.GetValue(),
        )

    ## Get the manpage section number
    #
    #  \return
    #    \b \e String section name
    def GetSection(self):
        return self.sel_section.GetStringSelection()

    ## TODO: Doxygen
    def InEasyMode(self):
        return self.EasyMode

    ## Adds a new section to the document via button press
    #
    #  \return
    #    Value of ui.manual.ManPage.AddDocumentSection
    def OnAddDocumentSection(self, event=None):
        style = DEFAULT_MANSECT_STYLE

        if event:
            event_object = event.GetEventObject()

            if isinstance(event_object, wx.Menu):
                event_id = event.GetId()

            else:
                event_id = event_object.GetId()

            if event_id == manid.MULTILINE:
                style = style | manid.MULTILINE

        return self.AddDocumentSection(style=style)

    ## Show a confirmation dialog when closing a tab
    #
    #  TODO: Find children & check default values
    def OnCloseTab(self, event=None):
        pass

    ## Removes selected section from manpage document via button press
    #
    #  \return
    #    Value of ui.manual.ManPage.RemoveDocumentSection
    def OnRemoveDocumentSection(self, event=None, index=None):
        if event:
            index = self._get_object_section(event.GetEventObject())

        return self.RemoveDocumentSection(index)

    ## Removes selected section from manpage document
    #
    #  \param index
    #    \b \e Integer index of the child section to remove
    #  \return
    #    \b \e True if section elements were removed
    def RemoveDocumentSection(self, index):
        if index == None:
            Logger.Error(__name__, u'Cannot remove desired index')

            return False

        Logger.Debug(__name__,
                     u'Removing manpage section at index {}'.format(index))

        layout = self.pnl_bottom.GetSizer()

        object_to_remove = layout.GetItem(index).GetWindow()

        # Object was returned as wx.Window instance
        if object_to_remove:
            layout.Detach(object_to_remove)
            object_to_remove.Destroy()

            self.Layout()

            return True

        return False

    ## Changes the displayed template mode
    #
    #  \b \e Easy mode dispays controls for adding individual sections. \b \e Manual
    #  mode shows a plain text area.
    #
    #  \param mode
    #    Mode to be displayed
    #    If is event object, retrieves mode from object's attribute 'Mode'
    #  \return
    #    Value of either ui.manual.ManPage.SetModeEasy or ui.manual.ManPage.SetModeManual
    def SetMode(self, mode):
        if isinstance(mode, wx.CommandEvent):
            mode = mode.GetEventObject().Mode

        self.EasyMode = mode

        # Restart with fresh panel
        # FIXME: Can be done without destroying children
        self.DestroyChildren()

        # Import/Export/Preview
        btn_browse = CreateButton(self, btnid.BROWSE)
        btn_save = CreateButton(self, btnid.SAVE)
        btn_preview = CreateButton(self, btnid.PREVIEW)

        # *** Layout *** #

        self.lyt_buttons = BoxSizer(wx.HORIZONTAL)
        self.lyt_buttons.AddStretchSpacer(1)
        self.lyt_buttons.Add(btn_browse)
        self.lyt_buttons.Add(btn_save)
        self.lyt_buttons.Add(btn_preview)

        self.lyt_main = BoxSizer(wx.VERTICAL)

        if mode:
            return self.SetModeEasy()

        return self.SetModeManual()

    ## Displays template in 'easy' mode
    #
    #  Uses controls to add & edit individual sections.
    def SetModeEasy(self):
        # Add sibling panel to hold menu & rename button
        pnl_top = wx.Panel(self)

        for C in self.GetChildren():
            if isinstance(C, wx.Button):
                C.Reparent(pnl_top)

        # FIXME: Hack
        temp_bar = BorderedPanel(pnl_top)

        menubar = PanelMenuBar(temp_bar)
        menubar.HideBorder()

        menu_add = PanelMenu(menubar, label=GT(u'Add'))
        menu_add.Append(manid.SINGLE, GT(u'Single line section'))
        menu_add.Append(manid.MULTILINE, GT(u'Multi-line section'))

        menubar.AddItem(menu_add)

        self.pnl_bottom = ScrolledPanel(self)

        # *** Banners *** #

        txt_banners = wx.StaticText(self.pnl_bottom, label=GT(u'Banners'))
        banners = ManBanner(self.pnl_bottom)
        pnl_banners = banners.GetPanel()

        # *** Event Handling *** #

        wx.EVT_MENU(self, manid.SINGLE, self.OnAddDocumentSection)
        wx.EVT_MENU(self, manid.MULTILINE, self.OnAddDocumentSection)

        # *** Layout *** #

        # FIXME: Hack
        temp_lyt = BoxSizer(wx.HORIZONTAL)
        temp_lyt.Add(menubar)
        temp_lyt.AddStretchSpacer(1)

        temp_bar.SetSizer(temp_lyt)

        lyt_top = BoxSizer(wx.VERTICAL)
        lyt_top.Add(self.lyt_buttons, 0, wx.EXPAND | wx.ALL, 5)
        # FIXME: temp_bar height is initially wrong
        lyt_top.Add(temp_bar, 0, wx.EXPAND | wx.ALL, 5)

        pnl_top.SetAutoLayout(True)
        pnl_top.SetSizer(lyt_top)

        # FIXME: Use GridBagSizer???
        lyt_bottom = BoxSizer(wx.VERTICAL)
        lyt_bottom.Add(txt_banners, 0, wx.ALIGN_BOTTOM | wx.LEFT | wx.TOP, 5)
        lyt_bottom.Add(pnl_banners, 0, wx.LEFT, 5)
        lyt_bottom.AddStretchSpacer(1)

        self.pnl_bottom.SetAutoLayout(True)
        self.pnl_bottom.SetSizer(lyt_bottom)

        self.lyt_main.Add(pnl_top, 0, wx.EXPAND)
        self.lyt_main.Add(self.pnl_bottom, 1, wx.EXPAND)

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

        # *** Default Sections *** #

        # This calls self.Layout
        self.AddDocumentSection(GT(u'Name'))
        self.AddDocumentSection(GT(u'Synopsis'),
                                style=DEFAULT_MANSECT_STYLE | manid.MULTILINE)
        self.AddDocumentSection(GT(u'Description'),
                                style=DEFAULT_MANSECT_STYLE | manid.MULTILINE)
        self.AddDocumentSection(GT(u'Options'),
                                style=DEFAULT_MANSECT_STYLE | manid.MULTILINE)
        self.AddDocumentSection(GT(u'Examples'),
                                style=DEFAULT_MANSECT_STYLE | manid.MULTILINE)
        self.AddDocumentSection(GT(u'See also'))

    ## Displays template in 'manual' mode
    #
    #  Manpage document must be entered 'manually' with plain text.
    def SetModeManual(self):
        self.ManualText = TextAreaPanel(self)

        # *** Layout *** #

        self.lyt_main.Add(self.lyt_buttons, 0, wx.EXPAND | wx.ALL, 5)
        self.lyt_main.Add(self.ManualText, 1, wx.EXPAND)

        self.SetAutoLayout(True)
        self.SetSizer(self.lyt_main)
        self.Layout()
Exemplo n.º 4
0
    def __init__(self, parent, size=(600, 558)):
        wx.Dialog.__init__(self,
                           parent,
                           wx.ID_ABOUT,
                           GT(u'About'),
                           size=size,
                           style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)

        self.SetMinSize(wx.Size(400, 375))
        self.CenterOnParent()

        # Create a tabbed interface
        tabs = wx.Notebook(self, -1)

        # Pages
        self.t_about = wx.Panel(tabs, -1)
        t_credits = wx.Panel(tabs, -1)
        t_changelog = wx.Panel(tabs, -1)
        t_license = wx.Panel(tabs, -1)

        # Add pages to tabbed interface
        tabs.AddPage(self.t_about, GT(u'About'))
        tabs.AddPage(t_credits, GT(u'Credits'))
        tabs.AddPage(t_changelog, GT(u'Changelog'))
        tabs.AddPage(t_license, GT(u'License'))

        # FIXME: Center verticall on about tab
        self.about_layout_V1 = BoxSizer(wx.VERTICAL)
        self.about_layout_V1.AddStretchSpacer()
        self.about_layout_V1.AddStretchSpacer()

        self.t_about.SetAutoLayout(True)
        self.t_about.SetSizer(self.about_layout_V1)
        self.t_about.Layout()

        ## List of credits
        self.credits = ListCtrl(t_credits)
        self.credits.SetSingleStyle(wx.LC_REPORT)
        self.credits.InsertColumn(0, GT(u'Name'), width=150)
        self.credits.InsertColumn(1, GT(u'Job'), width=200)
        self.credits.InsertColumn(2, GT(u'Email'), width=240)

        credits_sizer = BoxSizer(wx.VERTICAL)
        credits_sizer.Add(self.credits, 1, wx.EXPAND)

        t_credits.SetAutoLayout(True)
        t_credits.SetSizer(credits_sizer)
        t_credits.Layout()

        ## Changelog text area
        self.changelog = TextAreaPanel(t_changelog, style=wx.TE_READONLY)
        self.changelog.SetFont(MONOSPACED_MD)

        log_sizer = BoxSizer(wx.VERTICAL)
        log_sizer.Add(self.changelog, 1, wx.EXPAND)

        t_changelog.SetSizer(log_sizer)
        t_changelog.Layout()

        ## Licensing information text area
        self.license = TextAreaPanel(t_license, style=wx.TE_READONLY)
        self.license.SetFont(MONOSPACED_MD)

        license_sizer = BoxSizer(wx.VERTICAL)
        license_sizer.Add(self.license, 1, wx.EXPAND)

        t_license.SetSizer(license_sizer)
        t_license.Layout()

        # System info
        sys_info = wx.Panel(tabs, -1)
        tabs.AddPage(sys_info, GT(u'System Information'))

        ## System's <a href="https://www.python.org/">Python</a> version
        self.py_info = wx.StaticText(
            sys_info, -1,
            GT(u'Python version: {}').format(PY_VER_STRING))

        ## System's <a href="https://wxpython.org/">wxPython</a> version
        self.wx_info = wx.StaticText(
            sys_info, -1,
            GT(u'wxPython version: {}').format(WX_VER_STRING))

        ## Debreate's installation prefix
        install_prefix = wx.StaticText(
            sys_info, label=GT(u'App location: {}').format(PATH_app))

        if INSTALLED:
            install_prefix.SetLabel(
                GT(u'Installation prefix: {}').format(PREFIX))

        self.py_info.SetFont(sys_info_font)
        self.wx_info.SetFont(sys_info_font)

        sysinfo_layout_V1 = BoxSizer(wx.VERTICAL)
        sysinfo_layout_V1.AddStretchSpacer()
        sysinfo_layout_V1.Add(self.py_info, 0, wx.ALIGN_CENTER | wx.BOTTOM, 5)
        sysinfo_layout_V1.Add(self.wx_info, 0, wx.ALIGN_CENTER | wx.TOP, 5)
        sysinfo_layout_V1.AddSpacer(20)
        sysinfo_layout_V1.Add(install_prefix, 0, wx.ALIGN_CENTER | wx.TOP, 5)
        sysinfo_layout_V1.AddStretchSpacer()

        if OS_name:
            os_info = wx.StaticText(sys_info, label=OS_name)
            os_info.SetFont(sys_info_font)

            if OS_version:
                os_info.SetLabel(u'{} {}'.format(os_info.LabelText,
                                                 OS_version))

            if OS_codename:
                os_info.SetLabel(u'{} {}'.format(os_info.LabelText,
                                                 OS_codename))

            sysinfo_layout_V1.Insert(1, os_info, 0,
                                     wx.ALIGN_CENTER | wx.BOTTOM, 5)
            sysinfo_layout_V1.InsertSpacer(2, 20)

            if OS_upstream_name:
                os_upstream_info = wx.StaticText(sys_info,
                                                 label=OS_upstream_name)

                if OS_upstream_version:
                    os_upstream_info.SetLabel(u'{} {}'.format(
                        os_upstream_info.LabelText, OS_upstream_version))

                if OS_upstream_codename:
                    os_upstream_info.SetLabel(u'{} {}'.format(
                        os_upstream_info.LabelText, OS_upstream_codename))

                sysinfo_layout_V1.Insert(2, os_upstream_info, 0,
                                         wx.ALIGN_CENTER | wx.BOTTOM, 5)

        sys_info.SetSizer(sysinfo_layout_V1)
        sys_info.Layout()

        # Button to close the dialog
        btn_confirm = CreateButton(self, btnid.CONFIRM)

        sizer = BoxSizer(wx.VERTICAL)
        sizer.Add(tabs, 1, wx.EXPAND)
        sizer.Add(btn_confirm, 0, wx.ALIGN_RIGHT | lyt.PAD_RTB, 5)

        self.SetSizer(sizer)
        self.Layout()
Exemplo n.º 5
0
class AboutDialog(wx.Dialog):
    ## Constructor
    #
    #  \param parent
    #	The <b><i>wx.Window</i></b> parent instance
    #  \param size
    #	Window size <b><i>tuple</i></b>
    def __init__(self, parent, size=(600, 558)):
        wx.Dialog.__init__(self,
                           parent,
                           wx.ID_ABOUT,
                           GT(u'About'),
                           size=size,
                           style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)

        self.SetMinSize(wx.Size(400, 375))
        self.CenterOnParent()

        # Create a tabbed interface
        tabs = wx.Notebook(self, -1)

        # Pages
        self.t_about = wx.Panel(tabs, -1)
        t_credits = wx.Panel(tabs, -1)
        t_changelog = wx.Panel(tabs, -1)
        t_license = wx.Panel(tabs, -1)

        # Add pages to tabbed interface
        tabs.AddPage(self.t_about, GT(u'About'))
        tabs.AddPage(t_credits, GT(u'Credits'))
        tabs.AddPage(t_changelog, GT(u'Changelog'))
        tabs.AddPage(t_license, GT(u'License'))

        # FIXME: Center verticall on about tab
        self.about_layout_V1 = BoxSizer(wx.VERTICAL)
        self.about_layout_V1.AddStretchSpacer()
        self.about_layout_V1.AddStretchSpacer()

        self.t_about.SetAutoLayout(True)
        self.t_about.SetSizer(self.about_layout_V1)
        self.t_about.Layout()

        ## List of credits
        self.credits = ListCtrl(t_credits)
        self.credits.SetSingleStyle(wx.LC_REPORT)
        self.credits.InsertColumn(0, GT(u'Name'), width=150)
        self.credits.InsertColumn(1, GT(u'Job'), width=200)
        self.credits.InsertColumn(2, GT(u'Email'), width=240)

        credits_sizer = BoxSizer(wx.VERTICAL)
        credits_sizer.Add(self.credits, 1, wx.EXPAND)

        t_credits.SetAutoLayout(True)
        t_credits.SetSizer(credits_sizer)
        t_credits.Layout()

        ## Changelog text area
        self.changelog = TextAreaPanel(t_changelog, style=wx.TE_READONLY)
        self.changelog.SetFont(MONOSPACED_MD)

        log_sizer = BoxSizer(wx.VERTICAL)
        log_sizer.Add(self.changelog, 1, wx.EXPAND)

        t_changelog.SetSizer(log_sizer)
        t_changelog.Layout()

        ## Licensing information text area
        self.license = TextAreaPanel(t_license, style=wx.TE_READONLY)
        self.license.SetFont(MONOSPACED_MD)

        license_sizer = BoxSizer(wx.VERTICAL)
        license_sizer.Add(self.license, 1, wx.EXPAND)

        t_license.SetSizer(license_sizer)
        t_license.Layout()

        # System info
        sys_info = wx.Panel(tabs, -1)
        tabs.AddPage(sys_info, GT(u'System Information'))

        ## System's <a href="https://www.python.org/">Python</a> version
        self.py_info = wx.StaticText(
            sys_info, -1,
            GT(u'Python version: {}').format(PY_VER_STRING))

        ## System's <a href="https://wxpython.org/">wxPython</a> version
        self.wx_info = wx.StaticText(
            sys_info, -1,
            GT(u'wxPython version: {}').format(WX_VER_STRING))

        ## Debreate's installation prefix
        install_prefix = wx.StaticText(
            sys_info, label=GT(u'App location: {}').format(PATH_app))

        if INSTALLED:
            install_prefix.SetLabel(
                GT(u'Installation prefix: {}').format(PREFIX))

        self.py_info.SetFont(sys_info_font)
        self.wx_info.SetFont(sys_info_font)

        sysinfo_layout_V1 = BoxSizer(wx.VERTICAL)
        sysinfo_layout_V1.AddStretchSpacer()
        sysinfo_layout_V1.Add(self.py_info, 0, wx.ALIGN_CENTER | wx.BOTTOM, 5)
        sysinfo_layout_V1.Add(self.wx_info, 0, wx.ALIGN_CENTER | wx.TOP, 5)
        sysinfo_layout_V1.AddSpacer(20)
        sysinfo_layout_V1.Add(install_prefix, 0, wx.ALIGN_CENTER | wx.TOP, 5)
        sysinfo_layout_V1.AddStretchSpacer()

        if OS_name:
            os_info = wx.StaticText(sys_info, label=OS_name)
            os_info.SetFont(sys_info_font)

            if OS_version:
                os_info.SetLabel(u'{} {}'.format(os_info.LabelText,
                                                 OS_version))

            if OS_codename:
                os_info.SetLabel(u'{} {}'.format(os_info.LabelText,
                                                 OS_codename))

            sysinfo_layout_V1.Insert(1, os_info, 0,
                                     wx.ALIGN_CENTER | wx.BOTTOM, 5)
            sysinfo_layout_V1.InsertSpacer(2, 20)

            if OS_upstream_name:
                os_upstream_info = wx.StaticText(sys_info,
                                                 label=OS_upstream_name)

                if OS_upstream_version:
                    os_upstream_info.SetLabel(u'{} {}'.format(
                        os_upstream_info.LabelText, OS_upstream_version))

                if OS_upstream_codename:
                    os_upstream_info.SetLabel(u'{} {}'.format(
                        os_upstream_info.LabelText, OS_upstream_codename))

                sysinfo_layout_V1.Insert(2, os_upstream_info, 0,
                                         wx.ALIGN_CENTER | wx.BOTTOM, 5)

        sys_info.SetSizer(sysinfo_layout_V1)
        sys_info.Layout()

        # Button to close the dialog
        btn_confirm = CreateButton(self, btnid.CONFIRM)

        sizer = BoxSizer(wx.VERTICAL)
        sizer.Add(tabs, 1, wx.EXPAND)
        sizer.Add(btn_confirm, 0, wx.ALIGN_RIGHT | lyt.PAD_RTB, 5)

        self.SetSizer(sizer)
        self.Layout()

    ## Displays logo in 'about' tab
    #
    #  \param graphic
    #	Path to image file
    def SetGraphic(self, graphic):
        insertion_point = GetContainerItemCount(self.about_layout_V1) - 1

        if not isinstance(graphic, wx.Bitmap):
            graphic = wx.Image(graphic)
            graphic.Rescale(64, 64, wx.IMAGE_QUALITY_HIGH)
            graphic = graphic.ConvertToBitmap()

        self.about_layout_V1.Insert(
            insertion_point, wx.StaticBitmap(self.t_about, wx.ID_ANY, graphic),
            0, wx.ALL | wx.ALIGN_CENTER, 10)

        self.t_about.Layout()

    ## Displays version in 'about' tab
    #
    #  \param version
    #	<b><i>String</i></b> to display
    def SetVersion(self, version):
        insertion_point = GetContainerItemCount(self.about_layout_V1) - 1

        app_label = wx.StaticText(self.t_about,
                                  label=u'{} {}'.format(APP_name, version))
        app_label.SetFont(bigfont)

        self.about_layout_V1.Insert(insertion_point, app_label, 0,
                                    wx.ALL | wx.ALIGN_CENTER, 10)

        self.t_about.Layout()

    ## Display author's name
    #
    #  \param author
    #	<b><i>String</i></b> to display
    def SetAuthor(self, author):
        insertion_point = GetContainerItemCount(self.about_layout_V1) - 1

        self.about_layout_V1.Insert(insertion_point,
                                    wx.StaticText(self.t_about, label=author),
                                    0, wx.ALL | wx.ALIGN_CENTER, 10)

        self.t_about.Layout()

    ## Sets a hotlink to the app's homepage
    #
    #  TODO: Remove: Deprecated, unused
    #
    #  \param URL
    #	URL to open when link is clicked
    def SetWebsite(self, URL):
        self.website.SetLabel(URL)
        self.website.SetURL(URL)

    ## Adds URL hotlinks to about dialog
    #
    #  \param url_list
    #	Label/URL <b><i>Tuple</i></b> (<i>string</i>, <i>string</i>) list
    def SetWebsites(self, url_list):
        insertion_point = GetContainerItemCount(self.about_layout_V1) - 1

        link_layout = BoxSizer(wx.VERTICAL)
        for label, link in url_list:
            link_layout.Add(
                Hyperlink(self.t_about, wx.ID_ANY, label=label, url=link), 0,
                wx.ALIGN_CENTER, 10)

        self.about_layout_V1.Insert(insertion_point, link_layout, 0,
                                    wx.ALL | wx.ALIGN_CENTER, 10)
        self.t_about.Layout()

    ## Displays a description about the app on the 'about' tab
    def SetDescription(self, desc):
        # Place between spacers
        insertion_point = GetContainerItemCount(self.about_layout_V1) - 1

        self.about_layout_V1.Insert(insertion_point,
                                    wx.StaticText(self.t_about, label=desc), 0,
                                    wx.ALL | wx.ALIGN_CENTER, 10)

        self.t_about.Layout()

    ## Adds a developer to the list of credits
    #
    #  \param name
    #	Developer's name
    #  \param email
    #	Developer's email address
    def AddDeveloper(self, name, email):
        next_item = self.credits.GetItemCount()
        self.credits.InsertStringItem(next_item, name)
        self.credits.SetStringItem(next_item, 2, email)
        self.credits.SetStringItem(next_item, 1, GT(u'Developer'))

    ## Adds a packager to the list of credits
    #
    #  \param name
    #	Packager's name
    #  \param email
    #	Packager's email address
    def AddPackager(self, name, email):
        next_item = self.credits.GetItemCount()
        self.credits.InsertStringItem(next_item, name)
        self.credits.SetStringItem(next_item, 2, email)
        self.credits.SetStringItem(next_item, 1, GT(u'Packager'))

    ## Adds a translator to the list of credits
    #
    #  \param name
    #	Translator's name
    #  \param email
    #	Translator's email address
    #  \param lang
    #	Locale code of the translation
    def AddTranslator(self, name, email, lang):
        job = GT(u'Translation')
        job = u'{} ({})'.format(job, lang)
        next_item = self.credits.GetItemCount()
        self.credits.InsertStringItem(next_item, name)
        self.credits.SetStringItem(next_item, 2, email)
        self.credits.SetStringItem(next_item, 1, job)

    ## Adds a general job to the credits list
    #
    #  \param name
    #	Contributer's name
    #  \param job
    #	Job description
    #  \param email
    #	str : Job holder's email address
    def AddJob(self, name, job, email=wx.EmptyString):
        next_item = self.credits.GetItemCount()
        self.credits.InsertStringItem(next_item, name)
        self.credits.SetStringItem(next_item, 1, job)

        if email != wx.EmptyString:
            self.credits.SetStringItem(next_item, 2, email)

    ## Adds list of jobs for single contributer
    #
    #  \param name
    #	<b><i>string</i></b>:
    #	  Contributer's name
    #  \param jobs
    #	<b><i>Tuple</i></b> (<i>string</i>, <i>string</i>):
    #	  List of contributer's jobs
    #  \param email
    #	<b><i>string</i></b>:
    #	  Optional contributer's email address
    def AddJobs(self, name, jobs, email=wx.EmptyString):
        if isinstance(jobs, str) or isinstance(jobs, unicode):
            Logger.Debug(__name__,
                         GT(u'Converting string argument "jobs" to tuple'))
            jobs = (jobs, )

        for x, value in enumerate(jobs):
            next_item = self.credits.GetItemCount()
            if x == 0:
                self.credits.InsertStringItem(next_item, name)
                if email != wx.EmptyString:
                    self.credits.SetStringItem(next_item, 2, email)
            else:
                self.credits.InsertStringItem(next_item, wx.EmptyString)

            self.credits.SetStringItem(next_item, 1, value)

    ## FIXME: Unused?
    def NoResizeCol(self, event=None):
        if event:
            event.Veto()

    ## Sets text to be shown on the 'Changelog' tab
    #
    #  FIXME: Change to create in class constructor
    def SetChangelog(self):
        ## Defines where the changelog is located
        #
        #  By default it is located in the folder 'doc'
        #   under the applications root directory. The
        #   install script or Makefile should change this
        #   to reflect installed path.
        if INSTALLED:
            # FIXME: Read compressed .gz changelog
            CHANGELOG = u'{}/share/doc/debreate/changelog.gz'.format(PREFIX)

        else:
            CHANGELOG = u'{}/docs/changelog'.format(PREFIX)

        if os.path.isfile(CHANGELOG):
            changelog_mimetype = GetFileMimeType(CHANGELOG)

            Logger.Debug(
                __name__,
                GT(u'Changelog mimetype: {}').format(changelog_mimetype))

            # Set log text in case of read error
            log_text = GT(u'Error reading changelog: {}\n\t').format(CHANGELOG)
            log_text = u'{}{}'.format(
                log_text,
                GT(u'Cannot decode, unrecognized mimetype: {}').format(
                    changelog_mimetype))

            if changelog_mimetype == u'application/gzip':
                temp_dir = CreateStage()

                shutil.copy(CHANGELOG, temp_dir)

                CMD_gzip = GetExecutable(u'gzip')

                if CMD_gzip:
                    prev_dir = os.getcwd()
                    os.chdir(temp_dir)

                    gzip_output = commands.getstatusoutput(u'{} -fd {}'.format(
                        CMD_gzip, os.path.basename(CHANGELOG)))

                    Logger.Debug(
                        __name__,
                        GT(u'gzip decompress; Code: {}, Output: {}').format(
                            gzip_output[0], gzip_output[1]))

                    os.chdir(prev_dir)

                changelog_file = os.path.basename(CHANGELOG).split(u'.')[0]
                changelog_file = u'{}/{}'.format(temp_dir, changelog_file)

                if os.path.isfile(changelog_file):
                    log_text = ReadFile(changelog_file)

                RemoveStage(temp_dir)

            elif changelog_mimetype == u'text/plain':
                log_text = ReadFile(CHANGELOG)

            else:
                ShowErrorDialog(log_text, parent=self)

        else:
            log_text = GT(
                u'ERROR: Could not locate changelog file:\n\t\'{}\' not found'.
                format(CHANGELOG))

        self.changelog.SetValue(log_text)
        self.changelog.SetInsertionPoint(0)

    ## Sets text to be shown on the 'License' tab
    def SetLicense(self):
        ## Defines where the LICENSE.txt is located
        #
        #  By default it is located in the folder 'doc'
        #   under the applications root directory. The
        #   install script or Makefile should change this
        #   to reflect installed path.
        if INSTALLED:
            license_path = u'{}/share/doc/debreate/copyright'.format(PREFIX)

        else:
            license_path = u'{}/docs/LICENSE.txt'.format(PREFIX)

        if os.path.isfile(license_path):
            lic_text = ReadFile(license_path)

        else:
            lic_text = GT(
                u'ERROR: Could not locate license file:\n\t\'{}\' not found'.
                format(license_path))
            lic_text += u'\n\nCopyright © {} {} <{}>'.format(
                GetYear(), AUTHOR_name, AUTHOR_email)
            lic_text += u'\n\nhttps://opensource.org/licenses/MIT'

        self.license.SetValue(lic_text)
        self.license.SetInsertionPoint(0)

    ## Defines action to take when 'Ok' button is press
    #
    #  Closes the dialog.
    #
    #  \param event
    #		<b><em>(wx.EVT_BUTTON)</em></b>
    def OnOk(self, event=None):
        self.Close()
Exemplo n.º 6
0
    def __init__(self, parent):
        WizardPage.__init__(self, parent, pgid.SCRIPTS)

        preinst = DebianScript(self, ID_INST_PRE)
        postinst = DebianScript(self, ID_INST_POST)
        prerm = DebianScript(self, ID_RM_PRE)
        postrm = DebianScript(self, ID_RM_POST)

        # Check boxes for choosing scripts
        chk_preinst = CheckBox(self,
                               ID_INST_PRE,
                               GT(u'Make this script'),
                               name=GT(u'Pre-Install'))
        preinst.SetCheckBox(chk_preinst)
        chk_postinst = CheckBox(self,
                                ID_INST_POST,
                                GT(u'Make this script'),
                                name=GT(u'Post-Install'))
        postinst.SetCheckBox(chk_postinst)
        chk_prerm = CheckBox(self,
                             ID_RM_PRE,
                             GT(u'Make this script'),
                             name=GT(u'Pre-Remove'))
        prerm.SetCheckBox(chk_prerm)
        chk_postrm = CheckBox(self,
                              ID_RM_POST,
                              GT(u'Make this script'),
                              name=GT(u'Post-Remove'))
        postrm.SetCheckBox(chk_postrm)

        for S in chk_preinst, chk_postinst, chk_prerm, chk_postrm:
            S.SetToolTipString(u'{} {}'.format(
                S.GetName(), GT(u'script will be created from text below')))

            S.Bind(wx.EVT_CHECKBOX, self.OnToggleScripts)

        # Radio buttons for displaying between pre- and post- install scripts
        # FIXME: Names settings for tooltips are confusing
        rb_preinst = wx.RadioButton(self,
                                    preinst.GetId(),
                                    GT(u'Pre-Install'),
                                    name=preinst.FileName,
                                    style=wx.RB_GROUP)
        rb_postinst = wx.RadioButton(self,
                                     postinst.GetId(),
                                     GT(u'Post-Install'),
                                     name=postinst.FileName)
        rb_prerm = wx.RadioButton(self,
                                  prerm.GetId(),
                                  GT(u'Pre-Remove'),
                                  name=prerm.FileName)
        rb_postrm = wx.RadioButton(self,
                                   postrm.GetId(),
                                   GT(u'Post-Remove'),
                                   name=postrm.FileName)

        # TODO: Remove check boxes from lists (no longer needed)
        self.script_objects = (
            (
                preinst,
                chk_preinst,
                rb_preinst,
            ),
            (
                postinst,
                chk_postinst,
                rb_postinst,
            ),
            (
                prerm,
                chk_prerm,
                rb_prerm,
            ),
            (
                postrm,
                chk_postrm,
                rb_postrm,
            ),
        )

        for DS, CHK, RB in self.script_objects:
            CHK.Hide()

        # Set script text areas to default enabled/disabled setting
        self.OnToggleScripts()

        # *** Auto-Link *** #

        pnl_autolink = BorderedPanel(self)

        # Auto-Link path for new link
        txt_autolink = wx.StaticText(pnl_autolink,
                                     label=GT(u'Path'),
                                     name=u'target')
        self.ti_autolink = PathCtrl(pnl_autolink,
                                    value=u'/usr/bin',
                                    defaultValue=u'/usr/bin',
                                    warn=True)
        self.ti_autolink.SetName(u'target')
        self.ti_autolink.Default = self.ti_autolink.GetValue()

        # Auto-Link executables to be linked
        self.Executables = BasicFileList(pnl_autolink,
                                         size=(200, 200),
                                         hlExe=True,
                                         name=u'al list')

        # Auto-Link import, generate and remove buttons
        btn_al_import = CreateButton(pnl_autolink, btnid.IMPORT)
        btn_al_remove = CreateButton(pnl_autolink, btnid.REMOVE)
        btn_al_generate = CreateButton(pnl_autolink, image=u'build')

        # Auto-Link help
        btn_help = CreateButton(pnl_autolink, btnid.HELP, size=64)

        # Initialize script display
        self.ScriptSelect(None)

        SetPageToolTips(self)

        # *** Event Handling *** #

        for DS, CHK, RB in self.script_objects:
            RB.Bind(wx.EVT_RADIOBUTTON, self.ScriptSelect)

        wx.EVT_BUTTON(btn_al_import, btnid.IMPORT, self.ImportExes)
        wx.EVT_BUTTON(btn_al_generate, wx.ID_ANY, self.OnGenerate)
        wx.EVT_BUTTON(btn_al_remove, btnid.REMOVE, self.ImportExes)
        wx.EVT_BUTTON(btn_help, btnid.HELP, self.OnHelpButton)

        # *** Layout *** #

        # Organizing radio buttons
        lyt_sel_script = BoxSizer(wx.HORIZONTAL)
        lyt_sel_script.AddMany((
            (chk_preinst),
            (chk_postinst),
            (chk_prerm),
            (chk_postrm),
        ))

        lyt_sel_script.AddStretchSpacer(1)

        lyt_sel_script.AddMany((
            (rb_preinst),
            (rb_postinst),
            (rb_prerm),
            (rb_postrm),
        ))

        # Sizer for left half of scripts panel
        lyt_left = BoxSizer(wx.VERTICAL)
        lyt_left.Add(lyt_sel_script, 0, wx.EXPAND | wx.BOTTOM, 5)

        for DS, CHK, RB, in self.script_objects:
            lyt_left.Add(DS, 1, wx.EXPAND)

        # Auto-Link/Right side
        lyt_ti_autolink = BoxSizer(wx.HORIZONTAL)
        lyt_ti_autolink.Add(txt_autolink, 0, lyt.ALGN_C)
        lyt_ti_autolink.Add(self.ti_autolink, 1, lyt.ALGN_C)

        lyt_btn_autolink = BoxSizer(wx.HORIZONTAL)
        lyt_btn_autolink.Add(btn_al_import, 0)
        lyt_btn_autolink.Add(btn_al_remove, 0, lyt.PAD_LR, 5)
        lyt_btn_autolink.Add(btn_al_generate, 0)

        lyt_autolink = BoxSizer(wx.VERTICAL)
        lyt_autolink.Add(lyt_ti_autolink, 0, wx.EXPAND | lyt.PAD_LRT, 5)
        lyt_autolink.Add(self.Executables, 3, wx.EXPAND | lyt.PAD_LRT, 5)
        lyt_autolink.Add(lyt_btn_autolink, 0, lyt.ALGN_CH)
        lyt_autolink.Add(btn_help, 1, lyt.ALGN_C)

        pnl_autolink.SetSizer(lyt_autolink)
        pnl_autolink.SetAutoLayout(True)
        pnl_autolink.Layout()

        # Sizer for right half of scripts panel
        lyt_right = BoxSizer(wx.VERTICAL)
        # Line up panels to look even
        lyt_right.AddSpacer(32)
        lyt_right.Add(wx.StaticText(self, label=GT(u'Auto-Link Executables')),
                      0, lyt.ALGN_LB)
        lyt_right.Add(pnl_autolink, 0, wx.EXPAND)

        lyt_main = BoxSizer(wx.HORIZONTAL)
        lyt_main.Add(lyt_left, 1, wx.EXPAND | wx.ALL, 5)
        lyt_main.Add(lyt_right, 0, lyt.PAD_RB, 5)

        self.SetAutoLayout(True)
        self.SetSizer(lyt_main)
        self.Layout()
Exemplo n.º 7
0
    def __init__(self, parent):
        WizardPage.__init__(self, parent,
                            pgid.MENU)  #, name=GT(u'Menu Launcher'))

        ## Override default label
        self.Label = GT(u'Menu Launcher')

        # --- Buttons to open/preview/save .desktop file
        btn_open = CreateButton(self,
                                btnid.BROWSE,
                                GT(u'Browse'),
                                u'browse',
                                name=u'btn browse')
        btn_save = CreateButton(self,
                                btnid.SAVE,
                                GT(u'Save'),
                                u'save',
                                name=u'btn save')
        btn_preview = CreateButton(self,
                                   btnid.PREVIEW,
                                   GT(u'Preview'),
                                   u'preview',
                                   name=u'btn preview')

        # --- CHECKBOX
        chk_enable = CheckBox(self, chkid.ENABLE,
                              GT(u'Create system menu launcher'))

        # --- TYPE
        opts_type = (
            u'Application',
            u'Link',
            u'Directory',
        )

        txt_type = wx.StaticText(self, label=GT(u'Type'), name=u'type')
        ti_type = ComboBoxESS(self,
                              inputid.TYPE,
                              choices=opts_type,
                              name=u'Type',
                              defaultValue=opts_type[0])

        # --- ENCODING
        opts_enc = (
            u'UTF-1',
            u'UTF-7',
            u'UTF-8',
            u'CESU-8',
            u'UTF-EBCDIC',
            u'UTF-16',
            u'UTF-32',
            u'SCSU',
            u'BOCU-1',
            u'Punycode',
            u'GB 18030',
        )

        txt_enc = wx.StaticText(self, label=GT(u'Encoding'), name=u'encoding')
        ti_enc = ComboBoxESS(self,
                             inputid.ENC,
                             choices=opts_enc,
                             name=u'Encoding',
                             defaultValue=opts_enc[2])

        # --- TERMINAL
        chk_term = CheckBoxESS(self,
                               chkid.TERM,
                               GT(u'Terminal'),
                               name=u'Terminal')

        # --- STARTUP NOTIFY
        chk_notify = CheckBoxESS(self,
                                 chkid.NOTIFY,
                                 GT(u'Startup Notify'),
                                 name=u'StartupNotify',
                                 defaultValue=True)

        # --- Custom output filename
        txt_filename = wx.StaticText(self,
                                     txtid.FNAME,
                                     GT(u'Filename'),
                                     name=u'filename')
        ti_filename = TextArea(self, inputid.FNAME, name=txt_filename.Name)

        chk_filename = CheckBox(
            self,
            chkid.FNAME,
            GT(u'Use "Name" as output filename (<Name>.desktop)'),
            name=u'filename chk',
            defaultValue=True)

        # --- NAME (menu)
        txt_name = wx.StaticText(self, label=GT(u'Name'), name=u'name*')
        ti_name = TextAreaESS(self, inputid.NAME, name=u'Name')
        ti_name.req = True

        # --- EXECUTABLE
        txt_exec = wx.StaticText(self, label=GT(u'Executable'), name=u'exec')
        ti_exec = TextAreaESS(self, inputid.EXEC, name=u'Exec')

        # --- COMMENT
        txt_comm = wx.StaticText(self, label=GT(u'Comment'), name=u'comment')
        ti_comm = TextAreaESS(self, inputid.DESCR, name=u'Comment')

        # --- ICON
        txt_icon = wx.StaticText(self, label=GT(u'Icon'), name=u'icon')
        ti_icon = TextAreaESS(self, inputid.ICON, name=u'Icon')

        txt_mime = wx.StaticText(self, label=GT(u'MIME Type'), name=u'mime')
        ti_mime = TextAreaESS(self,
                              inputid.MIME,
                              defaultValue=wx.EmptyString,
                              name=u'MimeType')

        # ----- OTHER/CUSTOM
        txt_other = wx.StaticText(self,
                                  label=GT(u'Custom Fields'),
                                  name=u'other')
        ti_other = TextAreaPanel(self, inputid.OTHER, name=txt_other.Name)
        ti_other.EnableDropTarget()

        # --- CATEGORIES
        opts_category = (
            u'2DGraphics',
            u'Accessibility',
            u'Application',
            u'ArcadeGame',
            u'Archiving',
            u'Audio',
            u'AudioVideo',
            u'BlocksGame',
            u'BoardGame',
            u'Calculator',
            u'Calendar',
            u'CardGame',
            u'Compression',
            u'ContactManagement',
            u'Core',
            u'DesktopSettings',
            u'Development',
            u'Dictionary',
            u'DiscBurning',
            u'Documentation',
            u'Email',
            u'FileManager',
            u'FileTransfer',
            u'Game',
            u'GNOME',
            u'Graphics',
            u'GTK',
            u'HardwareSettings',
            u'InstantMessaging',
            u'KDE',
            u'LogicGame',
            u'Math',
            u'Monitor',
            u'Network',
            u'OCR',
            u'Office',
            u'P2P',
            u'PackageManager',
            u'Photography',
            u'Player',
            u'Presentation',
            u'Printing',
            u'Qt',
            u'RasterGraphics',
            u'Recorder',
            u'RemoteAccess',
            u'Scanning',
            u'Screensaver',
            u'Security',
            u'Settings',
            u'Spreadsheet',
            u'System',
            u'Telephony',
            u'TerminalEmulator',
            u'TextEditor',
            u'Utility',
            u'VectorGraphics',
            u'Video',
            u'Viewer',
            u'WordProcessor',
            u'Wine',
            u'Wine-Programs-Accessories',
            u'X-GNOME-NetworkSettings',
            u'X-GNOME-PersonalSettings',
            u'X-GNOME-SystemSettings',
            u'X-KDE-More',
            u'X-Red-Hat-Base',
            u'X-SuSE-ControlCenter-System',
        )

        txt_category = wx.StaticText(self,
                                     label=GT(u'Categories'),
                                     name=u'category')

        # This option does not get set by importing a new project
        ti_category = ComboBox(self,
                               inputid.CAT,
                               choices=opts_category,
                               name=txt_category.Name,
                               defaultValue=opts_category[0])

        btn_catadd = CreateButton(self,
                                  btnid.ADD,
                                  GT(u'Add'),
                                  u'add',
                                  name=u'add category')
        btn_catdel = CreateButton(self,
                                  btnid.REMOVE,
                                  GT(u'Remove'),
                                  u'remove',
                                  name=u'rm category')
        btn_catclr = CreateButton(self,
                                  btnid.CLEAR,
                                  GT(u'Clear'),
                                  u'clear',
                                  name=u'clear category')

        # FIXME: Allow using multi-select + remove
        lst_categories = ListCtrl(self, listid.CAT, name=u'Categories')
        # Can't set LC_SINGLE_SEL in constructor for wx 3.0 (ListCtrl bug???)
        lst_categories.SetSingleStyle(wx.LC_SINGLE_SEL)

        self.OnToggle()

        SetPageToolTips(self)

        # *** Event Handling *** #

        btn_open.Bind(wx.EVT_BUTTON, self.OnLoadLauncher)
        btn_save.Bind(wx.EVT_BUTTON, self.OnExportLauncher)
        btn_preview.Bind(wx.EVT_BUTTON, self.OnPreviewLauncher)

        chk_enable.Bind(wx.EVT_CHECKBOX, self.OnToggle)

        chk_filename.Bind(wx.EVT_CHECKBOX, self.OnSetCustomFilename)

        wx.EVT_KEY_DOWN(ti_category, self.SetCategory)
        wx.EVT_KEY_DOWN(lst_categories, self.SetCategory)
        btn_catadd.Bind(wx.EVT_BUTTON, self.SetCategory)
        btn_catdel.Bind(wx.EVT_BUTTON, self.SetCategory)
        btn_catclr.Bind(wx.EVT_BUTTON, self.OnClearCategories)

        # *** Layout *** #

        LEFT_CENTER = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL
        LEFT_BOTTOM = lyt.ALGN_LB
        RIGHT_BOTTOM = wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM

        lyt_top = BoxSizer(wx.HORIZONTAL)
        lyt_top.Add(chk_enable, 0, LEFT_BOTTOM)
        lyt_top.AddStretchSpacer(1)
        lyt_top.Add(btn_open, 0, wx.ALIGN_TOP)
        lyt_top.Add(btn_save, 0, wx.ALIGN_TOP)
        lyt_top.Add(btn_preview, 0, wx.ALIGN_TOP)

        lyt_opts1 = wx.FlexGridSizer()
        lyt_opts1.SetCols(3)
        lyt_opts1.SetRows(2)

        lyt_opts1.Add(txt_type, 0, LEFT_CENTER)
        lyt_opts1.Add(ti_type, 0, wx.EXPAND | wx.LEFT, 5)
        lyt_opts1.Add(chk_term, 0, LEFT_CENTER | wx.LEFT, 5)
        lyt_opts1.Add(txt_enc, 0, LEFT_CENTER | wx.TOP, 5)
        lyt_opts1.Add(ti_enc, 0, lyt.PAD_LT, 5)
        lyt_opts1.Add(chk_notify, 0, LEFT_CENTER | lyt.PAD_LT, 5)

        lyt_mid = wx.GridBagSizer()
        lyt_mid.SetCols(4)
        lyt_mid.AddGrowableCol(1)
        lyt_mid.AddGrowableCol(3)

        # Row 1
        row = 0
        lyt_mid.Add(txt_filename, (row, 0), flag=LEFT_CENTER)
        lyt_mid.Add(ti_filename, (row, 1), flag=wx.EXPAND | wx.LEFT, border=5)
        lyt_mid.Add(chk_filename, (row, 2),
                    span=(1, 2),
                    flag=LEFT_CENTER | wx.LEFT,
                    border=5)

        # Row 2
        row += 1
        lyt_mid.Add(txt_name, (row, 0), flag=LEFT_CENTER | wx.TOP, border=5)
        lyt_mid.Add(ti_name, (row, 1), flag=wx.EXPAND | lyt.PAD_LT, border=5)
        lyt_mid.Add(txt_exec, (row, 2),
                    flag=LEFT_CENTER | lyt.PAD_LT,
                    border=5)
        lyt_mid.Add(ti_exec, (row, 3), flag=wx.EXPAND | lyt.PAD_LT, border=5)

        # Row 3
        row += 1
        lyt_mid.Add(txt_comm, (row, 0), flag=LEFT_CENTER | wx.TOP, border=5)
        lyt_mid.Add(ti_comm, (row, 1), flag=wx.EXPAND | lyt.PAD_LT, border=5)
        lyt_mid.Add(txt_icon, (row, 2),
                    flag=LEFT_CENTER | lyt.PAD_LT,
                    border=5)
        lyt_mid.Add(ti_icon, (row, 3), flag=wx.EXPAND | lyt.PAD_LT, border=5)

        # Row 4
        row += 1
        lyt_mid.Add(txt_mime, (row, 0), flag=LEFT_CENTER | wx.TOP, border=5)
        lyt_mid.Add(ti_mime, (row, 1), flag=wx.EXPAND | lyt.PAD_LT, border=5)

        lyt_bottom = wx.GridBagSizer()

        row = 0
        lyt_bottom.Add(txt_other, (row, 0), flag=LEFT_BOTTOM)
        lyt_bottom.Add(txt_category, (row, 2),
                       flag=LEFT_BOTTOM | wx.LEFT,
                       border=5)
        lyt_bottom.Add(ti_category, (row, 3),
                       flag=LEFT_BOTTOM | wx.LEFT,
                       border=5)
        lyt_bottom.Add(btn_catadd, (row, 4), flag=RIGHT_BOTTOM)
        lyt_bottom.Add(btn_catdel, (row, 5), flag=RIGHT_BOTTOM)
        lyt_bottom.Add(btn_catclr, (row, 6), flag=RIGHT_BOTTOM)

        row += 1
        lyt_bottom.Add(ti_other, (row, 0), (1, 2), wx.EXPAND)
        lyt_bottom.Add(lst_categories, (row, 2), (1, 5), wx.EXPAND | wx.LEFT,
                       5)

        lyt_bottom.AddGrowableRow(1)
        lyt_bottom.AddGrowableCol(1)
        lyt_bottom.AddGrowableCol(4)

        # --- Page 5 Sizer --- #
        lyt_main = BoxSizer(wx.VERTICAL)
        lyt_main.AddSpacer(5)
        lyt_main.Add(lyt_top, 0, wx.EXPAND | lyt.PAD_LR, 5)
        lyt_main.Add(lyt_opts1, 0, wx.EXPAND | lyt.PAD_LRT, 5)
        lyt_main.Add(lyt_mid, 0, wx.EXPAND | lyt.PAD_LRT, 5)
        lyt_main.Add(lyt_bottom, 1, wx.EXPAND | wx.ALL, 5)

        self.SetAutoLayout(True)
        self.SetSizer(lyt_main)
        self.Layout()
Exemplo n.º 8
0
    def __init__(self, parent, win_id=wx.ID_ANY, name=u'launcher'):
        ScrolledPanel.__init__(self, parent, win_id, name=name)

        # --- Buttons to open/preview/save .desktop file
        btn_open = CreateButton(self,
                                btnid.BROWSE,
                                GT(u'Browse'),
                                u'browse',
                                name=u'btn browse')
        btn_save = CreateButton(self,
                                btnid.SAVE,
                                GT(u'Save'),
                                u'save',
                                name=u'btn save')
        btn_preview = CreateButton(self,
                                   btnid.PREVIEW,
                                   GT(u'Preview'),
                                   u'preview',
                                   name=u'btn preview')

        # --- TYPE
        opts_type = (
            u'Application',
            u'Link',
            u'Directory',
        )

        txt_type = wx.StaticText(self, label=GT(u'Type'), name=u'type')
        ti_type = ComboBoxESS(self,
                              inputid.TYPE,
                              choices=opts_type,
                              name=u'Type',
                              defaultValue=opts_type[0])

        # --- ENCODING
        opts_enc = (
            u'UTF-1',
            u'UTF-7',
            u'UTF-8',
            u'CESU-8',
            u'UTF-EBCDIC',
            u'UTF-16',
            u'UTF-32',
            u'SCSU',
            u'BOCU-1',
            u'Punycode',
            u'GB 18030',
        )

        txt_enc = wx.StaticText(self, label=GT(u'Encoding'), name=u'encoding')
        ti_enc = ComboBoxESS(self,
                             inputid.ENC,
                             choices=opts_enc,
                             name=u'Encoding',
                             defaultValue=opts_enc[2])

        # --- TERMINAL
        chk_term = CheckBoxESS(self,
                               chkid.TERM,
                               GT(u'Terminal'),
                               name=u'Terminal')

        # --- STARTUP NOTIFY
        chk_notify = CheckBoxESS(self,
                                 chkid.NOTIFY,
                                 GT(u'Startup Notify'),
                                 name=u'StartupNotify',
                                 defaultValue=True)

        # --- NAME (menu)
        txt_name = wx.StaticText(self, label=GT(u'Name'), name=u'name*')
        ti_name = TextAreaESS(self, inputid.NAME, name=u'Name')
        ti_name.req = True

        # --- EXECUTABLE
        txt_exec = wx.StaticText(self, label=GT(u'Executable'), name=u'exec')
        ti_exec = TextAreaESS(self, inputid.EXEC, name=u'Exec')

        # --- COMMENT
        txt_comm = wx.StaticText(self, label=GT(u'Comment'), name=u'comment')
        ti_comm = TextAreaESS(self, inputid.DESCR, name=u'Comment')

        # --- ICON
        txt_icon = wx.StaticText(self, label=GT(u'Icon'), name=u'icon')
        ti_icon = TextAreaESS(self, inputid.ICON, name=u'Icon')

        txt_mime = wx.StaticText(self, label=GT(u'MIME Type'), name=u'mime')
        ti_mime = TextAreaESS(self,
                              inputid.MIME,
                              defaultValue=wx.EmptyString,
                              name=u'MimeType',
                              outLabel=u'MimeType')

        # ----- OTHER/CUSTOM
        txt_other = wx.StaticText(self,
                                  label=GT(u'Custom Fields'),
                                  name=u'other')
        btn_other = CreateButton(self,
                                 label=GT(u'Other'),
                                 image=u'add',
                                 name=u'btn other')
        btn_rm_other = CreateButton(self,
                                    btnid.REMOVE,
                                    GT(u'Remove Other'),
                                    u'remove',
                                    name=u'btn rm other')
        pnl_other = SectionedPanel(self, inputid.OTHER)

        btn_rm_other.Enable(pnl_other.HasSelected())

        # --- CATEGORIES
        opts_category = (
            u'2DGraphics',
            u'Accessibility',
            u'Application',
            u'ArcadeGame',
            u'Archiving',
            u'Audio',
            u'AudioVideo',
            u'BlocksGame',
            u'BoardGame',
            u'Calculator',
            u'Calendar',
            u'CardGame',
            u'Compression',
            u'ContactManagement',
            u'Core',
            u'DesktopSettings',
            u'Development',
            u'Dictionary',
            u'DiscBurning',
            u'Documentation',
            u'Email',
            u'FileManager',
            u'FileTransfer',
            u'Game',
            u'GNOME',
            u'Graphics',
            u'GTK',
            u'HardwareSettings',
            u'InstantMessaging',
            u'KDE',
            u'LogicGame',
            u'Math',
            u'Monitor',
            u'Network',
            u'OCR',
            u'Office',
            u'P2P',
            u'PackageManager',
            u'Photography',
            u'Player',
            u'Presentation',
            u'Printing',
            u'Qt',
            u'RasterGraphics',
            u'Recorder',
            u'RemoteAccess',
            u'Scanning',
            u'Screensaver',
            u'Security',
            u'Settings',
            u'Spreadsheet',
            u'System',
            u'Telephony',
            u'TerminalEmulator',
            u'TextEditor',
            u'Utility',
            u'VectorGraphics',
            u'Video',
            u'Viewer',
            u'WordProcessor',
            u'Wine',
            u'Wine-Programs-Accessories',
            u'X-GNOME-NetworkSettings',
            u'X-GNOME-PersonalSettings',
            u'X-GNOME-SystemSettings',
            u'X-KDE-More',
            u'X-Red-Hat-Base',
            u'X-SuSE-ControlCenter-System',
        )

        txt_category = wx.StaticText(self,
                                     label=GT(u'Categories'),
                                     name=u'category')
        btn_catclr = CreateButton(self,
                                  btnid.CLEAR,
                                  GT(u'Clear'),
                                  u'clear',
                                  name=u'clear category')
        lst_categories = CheckList(self,
                                   listid.CAT,
                                   opts_category,
                                   name=u'Categories')

        if not lst_categories.HasSelected():
            btn_catclr.Disable()

        txt_catcustom = wx.StaticText(
            self, label=GT(u'Custom Categories (Separate by "," or ";")'))
        # Set to 'True' to list custom categories first
        # FIXME: Should this be saved to project instead of config???
        chk_catcustom = CheckBoxCFG(self,
                                    chkid.CAT,
                                    GT(u'List first'),
                                    name=u'chk catcustom',
                                    cfgKey=u'prioritize custom categories')
        ti_catcustom = TextAreaESS(self, inputid.CAT2, name=u'category custom')

        # *** Event Handling *** #

        btn_open.Bind(wx.EVT_BUTTON, self.OnLoadLauncher)
        btn_save.Bind(wx.EVT_BUTTON, self.OnExportLauncher)
        btn_preview.Bind(wx.EVT_BUTTON, self.OnPreviewLauncher)

        btn_other.Bind(wx.EVT_BUTTON, self.OnOtherAdd)
        btn_rm_other.Bind(wx.EVT_BUTTON, self.OnOtherRemove)

        btn_catclr.Bind(wx.EVT_BUTTON, self.OnClearCategories)

        wx.EVT_CHECKBOX(self, inputid.OTHER, self.OnOtherSelect)
        wx.EVT_CHECKBOX(self, listid.CAT, self.OnCatSelect)

        # *** Layout *** #

        LEFT_CENTER = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL
        LEFT_BOTTOM = wx.ALIGN_LEFT | wx.ALIGN_BOTTOM
        RIGHT_BOTTOM = wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM

        lyt_opts1 = wx.FlexGridSizer()
        lyt_opts1.SetCols(3)
        lyt_opts1.SetRows(2)

        lyt_opts1.Add(txt_type, 0, LEFT_CENTER)
        lyt_opts1.Add(ti_type, 0, wx.EXPAND | wx.LEFT, 5)
        lyt_opts1.Add(chk_term, 0, LEFT_CENTER | wx.LEFT, 5)
        lyt_opts1.Add(txt_enc, 0, LEFT_CENTER | wx.TOP, 5)
        lyt_opts1.Add(ti_enc, 0, wx.LEFT | wx.TOP, 5)
        lyt_opts1.Add(chk_notify, 0, LEFT_CENTER | wx.LEFT | wx.TOP, 5)

        lyt_top = BoxSizer(wx.HORIZONTAL)
        lyt_top.Add(lyt_opts1, 0, wx.EXPAND | wx.ALIGN_BOTTOM)
        lyt_top.AddStretchSpacer(1)
        lyt_top.Add(btn_open, 0, wx.ALIGN_TOP)
        lyt_top.Add(btn_save, 0, wx.ALIGN_TOP)
        lyt_top.Add(btn_preview, 0, wx.ALIGN_TOP)

        lyt_mid = wx.GridBagSizer()
        lyt_mid.SetCols(4)
        lyt_mid.AddGrowableCol(1)
        lyt_mid.AddGrowableCol(3)

        # Row 1
        row = 0
        lyt_mid.Add(txt_name, (row, 0), flag=LEFT_CENTER)
        lyt_mid.Add(ti_name, (row, 1), flag=wx.EXPAND | wx.LEFT, border=5)
        lyt_mid.Add(txt_exec, (row, 2), flag=LEFT_CENTER | wx.LEFT, border=5)
        lyt_mid.Add(ti_exec, (row, 3), flag=wx.EXPAND | wx.LEFT, border=5)

        # Row 2
        row += 1
        lyt_mid.Add(txt_comm, (row, 0), flag=LEFT_CENTER | wx.TOP, border=5)
        lyt_mid.Add(ti_comm, (row, 1),
                    flag=wx.EXPAND | wx.LEFT | wx.TOP,
                    border=5)
        lyt_mid.Add(txt_icon, (row, 2),
                    flag=LEFT_CENTER | wx.LEFT | wx.TOP,
                    border=5)
        lyt_mid.Add(ti_icon, (row, 3),
                    flag=wx.EXPAND | wx.LEFT | wx.TOP,
                    border=5)

        # Row 3
        row += 1
        lyt_mid.Add(txt_mime, (row, 0), flag=LEFT_CENTER | wx.TOP, border=5)
        lyt_mid.Add(ti_mime, (row, 1),
                    flag=wx.EXPAND | wx.LEFT | wx.TOP,
                    border=5)

        lyt_bottom = wx.GridBagSizer()

        row = 0
        lyt_bottom.Add(txt_other, (row, 0), flag=LEFT_BOTTOM)
        lyt_bottom.Add(btn_other, (row, 1), flag=RIGHT_BOTTOM)
        lyt_bottom.Add(btn_rm_other, (row, 2), flag=RIGHT_BOTTOM)
        lyt_bottom.Add(txt_category, (row, 3),
                       flag=LEFT_BOTTOM | wx.LEFT,
                       border=5)
        lyt_bottom.Add(btn_catclr, (row, 4), flag=RIGHT_BOTTOM)

        row += 1
        lyt_bottom.Add(pnl_other, (row, 0), (3, 3), wx.EXPAND)
        lyt_bottom.Add(lst_categories, (row, 3), (1, 2), wx.EXPAND | wx.LEFT,
                       5)

        row += 1
        lyt_bottom.Add(txt_catcustom, (row, 3),
                       flag=LEFT_BOTTOM | wx.LEFT | wx.TOP,
                       border=5)
        lyt_bottom.Add(chk_catcustom, (row, 4), flag=RIGHT_BOTTOM)

        row += 1
        lyt_bottom.Add(ti_catcustom, (row, 3), (1, 2),
                       flag=wx.EXPAND | wx.LEFT,
                       border=5)

        lyt_bottom.AddGrowableRow(1)
        lyt_bottom.AddGrowableCol(1)
        lyt_bottom.AddGrowableCol(3)

        # --- Page 5 Sizer --- #
        lyt_main = BoxSizer(wx.VERTICAL)
        lyt_main.AddSpacer(5)
        lyt_main.Add(lyt_top, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
        lyt_main.Add(lyt_mid, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5)
        lyt_main.Add(lyt_bottom, 1, wx.EXPAND | wx.ALL, 5)

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