Exemplo n.º 1
0
 def _createComboTreeBox(self, style):
     comboBox = ComboTreeBox(self, style=style)
     self._bindEventHandlers(comboBox)
     for i in range(5):
         child = comboBox.Append('Item %d' % i)
         for j in range(5):
             grandChild = comboBox.Append('Item %d.%d' % (i, j), child)
             for k in range(5):
                 comboBox.Append('Item %d.%d.%d' % (i, j, k), grandChild)
     return comboBox
Exemplo n.º 2
0
    def __init__(self, parent, document):
        parent = parent
        self.doc = document
        num_pages = len(self.doc)
        self.is_single_page_document = document.is_single_page_document()

        # Translators: the title of a group of controls in the search dialog
        rangeBox = make_sized_static_box(parent, _("Search Range"))
        # Translators: the label of a radio button in the search dialog
        self.hasPage = wx.RadioButton(rangeBox,
                                      -1,
                                      _("Page Range"),
                                      style=wx.RB_GROUP)
        fromToPagePanel = make_sized_static_box(rangeBox, "")
        fromToPagePanel.SetSizerProps(expand=True)
        fromToPagePanel.SetSizerType("horizontal")
        # Translators: the label of an edit field in the search dialog
        # to enter the page from which the search will start
        fpage_label = wx.StaticText(fromToPagePanel, -1, _("From:"))
        self.fromPage = EnhancedSpinCtrl(fromToPagePanel,
                                         -1,
                                         min=1,
                                         max=num_pages,
                                         value="1")
        # Translators: the label of an edit field in the search dialog
        # to enter the page number at which the search will stop
        tpage_label = wx.StaticText(fromToPagePanel, -1, _("To:"))
        self.toPage = EnhancedSpinCtrl(fromToPagePanel,
                                       -1,
                                       min=1,
                                       max=num_pages,
                                       value=str(num_pages))
        # Translators: the label of a radio button in the search dialog
        self.hasSection = wx.RadioButton(rangeBox, -1, _("Specific section"))
        # Translators: the label of a combobox in the search dialog
        # to choose the section to which the search will be confined
        sec_label = wx.StaticText(rangeBox, -1, _("Select section:"))
        self.sectionChoice = ComboTreeBox(rangeBox, -1, style=wx.CB_READONLY)
        self.page_controls = (fpage_label, tpage_label, self.fromPage,
                              self.toPage)
        self.sect_controls = (sec_label, self.sectionChoice)
        for ctrl in chain(self.page_controls, self.sect_controls):
            ctrl.Enable(False)
        for radio in (self.hasPage, self.hasSection):
            radio.SetValue(0)
            parent.Bind(wx.EVT_RADIOBUTTON, self.onRangeTypeChange, radio)
        self.toc_tree_manager = TocTreeManager(self.sectionChoice._tree)
        self.toc_tree_manager.build_tree(self.doc.toc_tree)
        if self.is_single_page_document:
            self.hasPage.SetValue(False)
            self.hasPage.Enable(False)
            self.hasSection.SetValue(True)
            for ctrl in self.sect_controls:
                ctrl.Enable(True)
Exemplo n.º 3
0
    def CreateComboBox(self):
        def _createComboBox(comboBox, root, items):
            for item in items:
                if isinstance(item, dict):
                    child = comboBox.Append(item.keys()[0],
                                            root,
                                            clientData=item.values()[0])
                    _createComboBox(comboBox, child, item.values()[0])

        comboBox = ComboTreeBox(self, wx.CB_READONLY)
        root = comboBox.Append(u'หลัก', clientData=self.items)
        _createComboBox(comboBox, root, self.items)
        comboBox.SetSelection(root)
        comboBox.GetTree().ExpandAll()
        return comboBox
Exemplo n.º 4
0
        wx.CallAfter(dlg.Destroy)
        return False
            
        
if __name__ == "__main__":
    app = wx.PySimpleApp()
    import logging, sys
    logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
    p.load_file('/Users/afraser/cpa_example/example.properties')

    f = wx.Frame(None)
    f.Sizer = wx.BoxSizer(wx.VERTICAL)
    #f.Sizer.Add(CheckListComboBox(f, 'asdf'))
    
    
    treebox = ComboTreeBox(f, style=wx.CB_READONLY)
    def build_tree(colnames, parent=None):
        #i = 1
        #while 1:
            #prefixes, b = zip(*[col.split('_', i) for col in colnames])
            #prefixes = set(prefixes)
            #if len(prefixes) > 1 or :
                #break
            #i += 1
        for prefix in prefixes:
            subcols = [col.split('_', 1)[1] for col in colnames if col.startswith(prefix+'_')]
            if len(subcols) == 1:
                treebox.Append(prefix+'_'+subcols[0], parent)
            elif subcols:
                child = treebox.Append(prefix, parent)
                build_tree(subcols, child)
Exemplo n.º 5
0
class PageRangeControl(sc.SizedPanel):
    """A helper that allows the user to get a range of pages."""
    def __init__(self, parent, document):
        parent = parent
        self.doc = document
        num_pages = len(self.doc)
        self.is_single_page_document = document.is_single_page_document()

        # Translators: the title of a group of controls in the search dialog
        rangeBox = make_sized_static_box(parent, _("Search Range"))
        # Translators: the label of a radio button in the search dialog
        self.hasPage = wx.RadioButton(rangeBox,
                                      -1,
                                      _("Page Range"),
                                      style=wx.RB_GROUP)
        fromToPagePanel = make_sized_static_box(rangeBox, "")
        fromToPagePanel.SetSizerProps(expand=True)
        fromToPagePanel.SetSizerType("horizontal")
        # Translators: the label of an edit field in the search dialog
        # to enter the page from which the search will start
        fpage_label = wx.StaticText(fromToPagePanel, -1, _("From:"))
        self.fromPage = EnhancedSpinCtrl(fromToPagePanel,
                                         -1,
                                         min=1,
                                         max=num_pages,
                                         value="1")
        # Translators: the label of an edit field in the search dialog
        # to enter the page number at which the search will stop
        tpage_label = wx.StaticText(fromToPagePanel, -1, _("To:"))
        self.toPage = EnhancedSpinCtrl(fromToPagePanel,
                                       -1,
                                       min=1,
                                       max=num_pages,
                                       value=str(num_pages))
        # Translators: the label of a radio button in the search dialog
        self.hasSection = wx.RadioButton(rangeBox, -1, _("Specific section"))
        # Translators: the label of a combobox in the search dialog
        # to choose the section to which the search will be confined
        sec_label = wx.StaticText(rangeBox, -1, _("Select section:"))
        self.sectionChoice = ComboTreeBox(rangeBox, -1, style=wx.CB_READONLY)
        self.page_controls = (fpage_label, tpage_label, self.fromPage,
                              self.toPage)
        self.sect_controls = (sec_label, self.sectionChoice)
        for ctrl in chain(self.page_controls, self.sect_controls):
            ctrl.Enable(False)
        for radio in (self.hasPage, self.hasSection):
            radio.SetValue(0)
            parent.Bind(wx.EVT_RADIOBUTTON, self.onRangeTypeChange, radio)
        self.toc_tree_manager = TocTreeManager(self.sectionChoice._tree)
        self.toc_tree_manager.build_tree(self.doc.toc_tree)
        if self.is_single_page_document:
            self.hasPage.SetValue(False)
            self.hasPage.Enable(False)
            self.hasSection.SetValue(True)
            for ctrl in self.sect_controls:
                ctrl.Enable(True)

    def onRangeTypeChange(self, event):
        radio = event.GetEventObject()
        if radio == self.hasPage:
            controls = self.page_controls
        else:
            controls = self.sect_controls
        for ctrl in chain(self.page_controls, self.sect_controls):
            ctrl.Enable(ctrl in controls)

    def ShouldCloseParentDialog(self):
        """XXX: Hack to not close the dialog when the tree is shown."""
        return not self.sectionChoice._tree.HasFocus()

    def get_page_range(self):
        if self.is_single_page_document:
            from_page, to_page = 0, 0
        elif self.hasSection.GetValue():
            if selected_item := self.sectionChoice.GetSelection():
                selected_section = self.sectionChoice.GetClientData(
                    selected_item)
                pager = selected_section.pager
                from_page = pager.first
                to_page = pager.last
            else:
                from_page = 0
                to_page = len(self.doc)
        else: