Changeset 1238


Ignore:
Timestamp:
Mar 4, 2013 12:26:00 AM (9 years ago)
Author:
jemian
Message:

repaired menu handling on Linux with better id handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mda2idd_report/src/mda2idd_gui.py

    r1237 r1238  
    101101                              help=u'Save MDA data to ASCII text file')
    102102        self.Bind(wx.EVT_MENU, self.OnMenuFileItemSave, id=item.GetId())
    103 
    104         item = self.menu_file.Append(text=u'Convert entire &Directory\tCtrl+D', id=wx.ID_ANY,
    105                               help=u'Convert all MDA files in current directory to ASCII text files')
     103        #print "menu item: ", item.GetId(), item.GetLabel()
     104
     105        item = self.menu_file.Append(
     106            text=u'Convert entire &Directory\tCtrl+D',
     107            id=wx.ID_ANY,
     108            help=u'Convert all MDA files in current directory to ASCII text files')
    106109        self.Bind(wx.EVT_MENU, self.OnConvertAll, id=item.GetId())
     110        #print "menu item: ", item.GetId(), item.GetLabel()
    107111       
    108112        self.menu_file.AppendSeparator()
    109         item = self.menu_file.AppendCheckItem(text=u'Brief &Report\tCtrl+R', id=wx.ID_ANY,
    110                               help=u'Show a brief summary report of the selected MDA file')
     113
     114        item = self.menu_file.AppendCheckItem(
     115            text=u'Brief &Report\tCtrl+R',
     116            id=wx.ID_ANY,
     117            help=u'Show a brief summary report of the selected MDA file')
    111118        self.Bind(wx.EVT_MENU, self.OnMenuFileItemReportStyle, id=item.GetId())
    112119        self.id_menu_report = item.GetId()
     120        #print "menu item: ", item.GetId(), item.GetLabel()
    113121
    114122        # TODO: provide a control to let user edit self.preferences_file
     
    117125#                              help=u'Edit program preferences ...')
    118126#        self.Bind(wx.EVT_MENU, self.OnMenuFileItemPrefs, id=id_menu_prefs)
     127
    119128        self.menu_file.AppendSeparator()
    120129
     
    124133        self.menu_file.Enable(item.GetId(), False)
    125134        self.mrud_insertion_pos = self.menu_file.GetMenuItemCount()
     135        #print "menu item: ", item.GetId(), item.GetLabel()
     136
    126137        self.menu_file.AppendSeparator()
    127138       
     
    129140                              help=u'Quit this application')
    130141        self.Bind(wx.EVT_MENU, self.OnMenuFileItemExit, id=item.GetId())
     142        #print "menu item: ", item.GetId(), item.GetLabel()
    131143
    132144        self.menu_edit = wx.Menu(title='')
     
    136148                              help=u'About this application')
    137149        self.Bind(wx.EVT_MENU, self.OnAbout, id=item.GetId())
     150        #print "menu item: ", item.GetId(), item.GetLabel()
    138151
    139152        self.menuBar1 = wx.MenuBar()
     
    282295    def setCurrentDirectory(self, directory):
    283296        '''set the current directory'''
     297        #print "set directory:", str(directory)
    284298        self.dir.ExpandPath(directory)
    285299        self.dirPicker.SetPath(directory)
     
    287301    def setSummaryText(self, text):
    288302        '''post new text to the summary TextCtrl, clearing any existing text'''
     303        #print "new summary:", str(text)
    289304        self.textCtrl1.ChangeValue(str(text))
    290305   
    291306    def appendSummaryText(self, text):
    292307        '''post new text to the summary TextCtrl, appending to any existing text'''
     308        #print "additional summary:", str(text)
    293309        self.textCtrl1.AppendText(str(text))
    294310   
    295311    def setStatusText(self, text):
    296312        '''post new text to the status bar'''
     313        #print "new status:", str(text)
    297314        self.statusBar.SetStatusText(text)
    298315
     
    342359
    343360        node = root.find('mrud')
    344         self.prefs['mrud_max_directories'] = int(node.attrib['max_directories'])
    345         self.mrud = [subnode.text.strip() for subnode in node.findall('dir')]
     361        if node is not None:
     362            self.prefs['mrud_max_directories'] = int(node.attrib['max_directories'])
     363            self.mrud = [subnode.text.strip() for subnode in node.findall('dir')]
    346364       
    347365        self.prefs['file_filter'] = root.find('file_filter').text.strip()
     
    442460                text = '%s\tCtrl+%d' % (path, counter+1)
    443461                position = self.mrud_insertion_pos + counter
    444                 self.menu_file.Insert(position, wx.ID_ANY, text=text)
    445                 item_id = self.menu_file.FindItem(text)
    446                 self.Bind(wx.EVT_MENU, self.OnMrudItem, id=item_id)
     462                item = self.menu_file.Insert(position, wx.ID_ANY, text=text)
     463                self.Bind(wx.EVT_MENU, self.OnMrudItem, id=item.GetId())
     464                #print "menu item: ", item.GetId(), item.GetLabel()
    447465                counter += 1
    448466       
     
    450468        '''handle MRUD menu items'''
    451469        label = self.menu_file.GetLabelText(event.GetId())
     470        #print "onMrudItem: ", event.GetId(), str(label)
    452471        self.setCurrentDirectory(label)
    453472#        self.setStatusText(label)
     
    465484        author = __author__ +  " <" + __author_email__ + ">"
    466485        info.Developers = ['main author: ' + author,
    467                            'MDA support: Time Mooney <mooney@aps.anl.gov>']
     486                           'MDA file support: Time Mooney <mooney@aps.anl.gov>']
    468487        # Then we call wx.AboutBox giving it the info object
    469488        wx.AboutBox(info)
     
    471490    def OnConvertAll(self, event):
    472491        '''selected the "ConvertAll" menu item'''
     492        # use path from preferences
     493        path = self.prefs['start_dir']
    473494        # use path from self.dirPicker widget
    474         #path = self.prefs['start_dir']
    475         path = self.dirPicker.GetPath()
     495        #path = self.dirPicker.GetPath()
     496        #print "convert directory:", path
    476497        self.setStatusText('Converting all MDA files to ASCII in directory: ' + path)
    477498        self.convertMdaDir(path)
     
    482503            self.setSummaryText('non-existent path: ' + path)
    483504            return
    484         fileList = glob.glob(os.path.join(path, '*.mda'))
     505        # assumes self.prefs['file_filter'] is just '*.mda'
     506        fileList = glob.glob(os.path.join(path, self.prefs['file_filter']))
    485507        if len(fileList) == 0:
    486508            self.setSummaryText('No MDA files to convert in directory: ' + path)
    487509            return
    488510        self.setSummaryText('Converting these files:\n')
    489         for mdaFile in fileList:
     511        for mdaFile in sorted(fileList):
    490512            try:
    491513                answer = mda2idd_report.report(mdaFile, allowException=True)
Note: See TracChangeset for help on using the changeset viewer.