[Wnd-commit] wnd/wnd/sample-guis/explorer .CVSIGNORE,NONE,1.1 expl.ini,NONE,1.1 expl.py,NONE,1.1 exp
Status: Alpha
Brought to you by:
jurner
|
From: jürgen u. <cer...@us...> - 2005-07-02 09:21:39
|
Update of /cvsroot/wnd/wnd/wnd/sample-guis/explorer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7310 Added Files: .CVSIGNORE expl.ini expl.py expl_dircombo.py expl_ini.py expl_menu.py expl_statusbar.py Log Message: bit of this and a bit of that --- NEW FILE: expl_ini.py --- import os, ConfigParser from wnd.api import winpath #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: INIPATH= os.path.join(os.path.split(__file__)[0], 'expl.ini') class Ini(ConfigParser.RawConfigParser): def __init__(self, mainframe): self.ini_sections= { 'mainwindow': ('size', ), 'dircombo': ('n_mru_items', ), 'mru_dircombo': None, 'panes': None, 'pane1': ('dir', ), 'pane2': ('dir', ), } ConfigParser.RawConfigParser.__init__(self) self.Main= mainframe try: self.read((INIPATH, )) except: pass ## remove the stupid defaults. ## Sorry, but this is a nonsense feature... if hasattr(self, '_defaults'): self._defaults= {} def GetMRU(self, section): if self.has_section(section): items= dict(self.items(section)) out= [] for i in range(len(items)): try: out.append(items[str(i)]) except: pass return out self.add_section(section) def SetMRU(self, section, values): if self.has_section(section): self.remove_section(section) self.add_section(section) for n, i in enumerate(values): self.set(section, str(n), i) def GetValue(self, section, name, default=None): if self.has_section(section): if self.has_option(section, name): return self.get(section, name) else: self.add_section(section) return default def SetValue(self, section, name, value): if not self.has_section(section): self.add_section(section) self.set(section, name, value) def GetInt(self, section, name, default=None): if not self.has_section(section): self.add_section(section) try: return self.getint(section, name) except: return default def Save(self): ## keep ini clean sections= self.sections() for section in sections: if section not in self.ini_sections: self.remove_section(section) else: names= self.ini_sections[section] options= self.options(section) if names: for option in options: if option not in names: self.remove_option(section, option) if 1: ## store cwds of the DirLists path= self.Main.DirList1.GetCwd(path=True) if not path: path= self.Main.DirList1.GetCLSIDL() if path: path= path[1] else: path= 'desktop' self.SetValue('pane1', 'dir', path) path= self.Main.DirList2.GetCwd(path=True) if not path: path= self.Main.DirList2.GetCLSIDL() if path: path= path[1] else: path= 'desktop' self.SetValue('pane2', 'dir', path) fp= open(INIPATH, 'w') try: self.write(fp) finally: fp.close() --- NEW FILE: expl.py --- """The very start of a file manager... """ import sys import wnd from wnd import gdi from wnd.wintypes import RECT from wnd.api import winpath, display from wnd.wintypes import RGB, GETRGB from wnd.controls.statusbar import Statusbar from wnd.custom.dirlist import DirList from wnd.custom.splitter import Splitter import expl_menu import expl_dircombo import expl_statusbar import expl_ini PATHICO= '%s\\py.ico' % sys.prefix #****************************************************************** #****************************************************************** class Window(wnd.Window): def __init__(self): self.activePane= None self.DirCombo= None self.title= 'wnd_explorer 01 -- %s' self.Ini= expl_ini.Ini(self) size= self.Ini.GetValue('mainwindow', 'size', default= None) if size: ## make shure window is visible on monitor try: x, y, w, h= map(int, size.split(',')) rc= display.GetMonitorXY(x, y)[3] ## working rect rc2= RECT(x, y, x+gdi.GetSystemMetric('cxmin'), y+gdi.GetSystemMetric('cymin')) if not rc2.InRect(rc): x= rc.left y= rc.top except: x= y= w= h= None else: x= y= w= h= None wnd.Window.__init__(self, 'wnd_explorer', self.title % '', x, y, w, h, 'overlappedwindow', 'clipchildren', 'dialoglike') ## set python icon try: ico= gdi.IconFromFile(PATHICO) self.SetIcon(ico) except: pass ## init combobox andstatusbar self.DirCombo= expl_dircombo.ExplDircombo(self) self.Statusbar= expl_statusbar.ExplStatusbar(self) ## init menu self.Menu= expl_menu.ExplMenu(self) self.Menu.Set(self) ## init dirlists self.DirList1= DirList(self, 0, 0, 0, 0, 'border', 'editlabels', 'showselalways', 'report', 'clientedge', 'tabstop') self.DirList2= DirList(self, 0, 0, 0, 0, 'largeicon', 'clientedge', 'editlabels', 'showselalways', 'report', 'tabstop') self.DirList1.onMSG= self.DirList2.onMSG= self.on_dirlist def init_dirlist(dirlist, inisection): flag= False dirr= self.Ini.GetValue(inisection, 'dir') if winpath.GetRoot(dirr): if winpath.Exists(dirr): if winpath.IsDir(dirr): dirlist.ListDir(dirr) flag= True else: flag= dirlist.ListDir(dirr) if not flag: dirlist.ListDir('desktop') init_dirlist(self.DirList1, 'pane1') init_dirlist(self.DirList2, 'pane2') ## init splitter w= self.GetClientRect().ToSize()[2] self.SplitteritterW= 5 self.Splitter= Splitter(self, (w/2)-(self.SplitteritterW/2), 0, self.SplitteritterW, 0, 'feedbackbar', 'vert') colorBk= gdi.GetSysColor('msgbox') self.Splitter.SetPageSize(30) #colorHi= gdi.GetSysColor('highlight') rgb= GETRGB(colorBk) colorHi= RGB(rgb[0]+30, rgb[1]+30, rgb[2]+30) self.Splitter.SetColors(colorBk, colorHi) self.Splitter.onMSG= self.on_splitter def on_dirlist(self, hwnd, msg, wp, lp): if msg=='itemchanged': if 'selected' in lp[0] and not 'selected' in lp[1]: ## an item has been deselected self.Statusbar.Expl_SetItemsSelected( self.activePane.GetSelectedCount()) if 'selected' not in lp[0] and 'selected' in lp[1]: ## an item has been selected size= 0 for i in self.activePane.IterSelected(): n= self.activePane.GetSize(i, asstring=False) if n != None: size += n self.Statusbar.Expl_SetItemsSelected( self.activePane.GetSelectedCount(), self.activePane.FormatInt(size)) elif msg=='shell_contextmenu': if wp=='open': self.Statusbar.SetSimple() elif wp=='helpstring': self.Statusbar.SetText(lp) elif wp=='close': self.Statusbar.SetText('') self.Statusbar.SetMultiple() elif msg in ('setfocus', 'dirchanged'): if hwnd== self.DirList1.Hwnd: self.cur_sel_pane1= [] self.activePane= self.DirList1 else: self.cur_sel_pane2= [] self.activePane= self.DirList2 path= self.activePane.GetCwd(path=True) self.SetText(self.title % path) self.DirCombo.SetText( path, self.activePane.GetFilespec()[0] ) size= 0 for i in self.activePane.IterSelected(): n= self.activePane.GetSize(i, asstring=False) if n != None: size += n self.Statusbar.Expl_SetItemsSelected( self.activePane.GetSelectedCount(), self.activePane.FormatInt(size)) def size_controls(self, ): x, y, w, h= self.GetClientRect().ToSize() paneOffsY= 4 stH= self.Statusbar.GetWindowRect().ToSize()[3] cmbH= self.DirCombo.GetWindowRect().ToSize()[3] #cmbH= self.DirCombo.GetItemHeight(-1) rcSpl= self.Splitter.GetWindowRect() rcSpl.ScreenToClient(self.Hwnd) #self.DirList2.SetRedraw(False) self.DeferWindows( (self.DirCombo, None, None, (w/10)*6, cmbH), (self.Splitter, rcSpl.left, cmbH+paneOffsY, self.SplitteritterW, h-stH-cmbH-paneOffsY), (self.DirList1, 0, 0+cmbH+paneOffsY, rcSpl.left-1, h-stH-cmbH-paneOffsY), (self.DirList2, rcSpl.right+1, 0+cmbH+paneOffsY, (w-rcSpl.right)-1, h-stH-cmbH-paneOffsY), (self.Statusbar, 0, h-stH, w, stH), ) w= w/10 self.Statusbar.SetParts(w, w*8, -1) def on_splitter(self, hwnd, msg, wp, lp): if msg=="moved": self.size_controls() def onMSG(self, hwnd, msg, wp, lp): if msg=="size": self.size_controls() elif msg in ('menu open', 'menu popup', 'menu choice'): self.Menu.handle_menu_msg(hwnd, msg, wp, lp) elif msg=="open": self.DirList1.SetFocus() self.activePane= self.DirList1 elif msg=="close": if self.DirCombo != None: ## combos have a __len_ attr !! self.DirCombo.Expl_SaveState() self.Ini.SetValue('mainwindow', 'size', '%s,%s,%s,%s' % self.GetWindowRect().ToSize()) self.Ini.Save() #********************************************************************* if __name__=='__main__': w = Window() w.Run() --- NEW FILE: expl_menu.py --- from wnd.controls import menu #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: class ExplMenu(menu.Menu): def __init__(self, main): menu.Menu.__init__(self) self.Main= main p= self.Popup('&File', IDM_FILE) p.Item('Quit', IDM_FILE_QUIT) p= self.Popup('&Mark', IDM_MARK) p.Item('&Select Group...', IDM_MARK_SELECTGROUP, 'disabled') # not impl p= self.Popup('&panes', IDM_PANES) p.Item('Pane1 Allow navigate', IDM_PANES_ALLOWNAVIGATE_1) p.Item(' Show Folders', IDM_PANES_SHOWFOLDERS_1) p.Separator(0) p.Item('Pane 2 Allow navigate', IDM_PANES_ALLOWNAVIGATE_2) p.Item(' Show Folders', IDM_PANES_SHOWFOLDERS_2) def handle_menu_msg(self, hwnd, msg, wp, lp): if msg=='menu popup': panes= self.GetPopup(IDM_PANES) if wp== panes.handle: ## if self.Main.DirList1.IsNavigateAllowed(): self.Check(IDM_PANES_ALLOWNAVIGATE_1) else: self.Uncheck(IDM_PANES_ALLOWNAVIGATE_1) if self.Main.DirList1.AreFoldersVisible(): self.Check(IDM_PANES_SHOWFOLDERS_1) else: self.Uncheck(IDM_PANES_SHOWFOLDERS_1) ## if self.Main.DirList2.IsNavigateAllowed(): self.Check(IDM_PANES_ALLOWNAVIGATE_2) else: self.Uncheck(IDM_PANES_ALLOWNAVIGATE_2) if self.Main.DirList2.AreFoldersVisible(): self.Check(IDM_PANES_SHOWFOLDERS_2) else: self.Uncheck(IDM_PANES_SHOWFOLDERS_2) elif msg=='menu choice': if lp[0]== IDM_FILE_QUIT: self.Main.Close() elif lp[0]==IDM_PANES_ALLOWNAVIGATE_1: self.CheckUncheck(lp[0]) self.Main.DirList1.AllowNavigate(self.IsChecked(lp[0])) elif lp[0]==IDM_PANES_ALLOWNAVIGATE_2: self.CheckUncheck(lp[0]) self.Main.DirList2.AllowNavigate(self.IsChecked(lp[0])) elif lp[0]==IDM_PANES_SHOWFOLDERS_1: self.CheckUncheck(lp[0]) self.Main.DirList1.ShowFolders(self.IsChecked(lp[0])) elif lp[0]==IDM_PANES_SHOWFOLDERS_2: self.CheckUncheck(lp[0]) self.Main.DirList2.ShowFolders(self.IsChecked(lp[0])) IDM_FILE= 1000 IDM_FILE_QUIT= IDM_FILE +1 IDM_MARK= 2000 IDM_MARK_SELECTGROUP= IDM_MARK +1 IDM_VIEW= 3000 IDM_PANES= 4000 IDM_PANES_ALLOWNAVIGATE_1= IDM_PANES +1 IDM_PANES_ALLOWNAVIGATE_2= IDM_PANES +2 IDM_PANES_SHOWFOLDERS_1= IDM_PANES +3 IDM_PANES_SHOWFOLDERS_2= IDM_PANES +4 #**************************************************************************** #**************************************************************************** --- NEW FILE: expl_statusbar.py --- from wnd.controls.statusbar import Statusbar #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: class ExplStatusbar(Statusbar): def __init__(self, mainframe): self.Main= mainframe Statusbar.__init__(self, mainframe) def Expl_SetItemsSelected(self, n, size=''): if len(self) > 1: if not n: self.SetText('' , 1) elif n==1: self.SetText(' 1 Item Selected %s bytes total' % size, 1) else: self.SetText(' %s Items Selected %s bytes total' % (n, size), 1) --- NEW FILE: expl_dircombo.py --- from wnd.api import winpath from wnd.controls.combobox import Combobox #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: class ExplDircombo(Combobox): def __init__(self, mainframe): self.Main= mainframe self.n_mru_items= self.Main.Ini.GetInt('dircombo', 'n_mru_items', default=10) self.maxW= 0 ## TODO ## calculate combobox height for nItems Combobox.__init__(self, mainframe, 0, 0, 0, 150, 'dropdown', 'vscroll', 'hscroll') self.SetExtendedUI(True) ## restore MRU list mru= self.Main.Ini.GetMRU('mru_dircombo') if mru: for n, i in enumerate(mru): if n >= self.n_mru_items: break if winpath.Exists(i): self.maxW= max(self.GetTextExtend(i)[0], self.maxW) self.Item(i) self.maxW += self.GetTextExtend('W')[0] Combobox.SetScrollWidth(self, self.maxW) #self.SetScrollWidth() self.ed= self.GetEditControl() self.ed.onMSG= self.onMSG def SetScrollWidth(self): self.maxW= 0 for i in self: text= self.GetItemText(i) self.maxW= max(self.GetTextExtend(text)[0], self.maxW) self.maxW += self.GetTextExtend('W')[0] Combobox.SetScrollWidth(self, self.maxW) def onMSG(self, hwnd, msg, wp, lp): if msg=='getdlgcode': lp.append('wantallkeys') return lp if msg=='return': refresh= False path= self.GetText() spec= winpath.GetFileName(path) if self.IsDroppedDown(): self.CloseDropdown() if spec: if spec.startswith('*'): path= winpath.RemoveFileSpec(path) self.Main.activePane.SetFilespec(spec) if len(path)==2 and path[1]==':': path= '%s\\' % path else: ## path may be spec if path.startswith('*'): self.Main.activePane.SetFilespec(path) refresh= True if refresh: self.Main.activePane.Refresh() else: if self.Main.activePane.ListDir(path): self.SetText(path, self.Main.activePane.GetFilespec()[0]) else: self.Beep('asterisk') def Expl_SaveState(self): self.Main.Ini.SetValue('dircombo', 'n_mru_items', self.n_mru_items) out= [] for i in self: out.append(self.GetItemText(i)) self.Main.Ini.SetMRU('mru_dircombo', out) def SetText(self, path, filespec): if path: out= [] for i in self: if self.GetItemText(i).lower()== path.lower(): out.append(i) if out: for i in reversed(out): self.RemoveItem(i) if path.endswith('\\'): Combobox.SetText(self, '%s%s' % (path, filespec)) else: Combobox.SetText(self, '%s\\%s' % (path, filespec)) self.InsertItem(0, path) if len(self) > self.n_mru_items: self.RemoveItem(self.n_mru_items) else: Combobox.SetText(self, filespec) self.SetScrollWidth() --- NEW FILE: .CVSIGNORE --- *.pyc *.pyo --- NEW FILE: expl.ini --- [mru_dircombo] 1 = D:\z 0 = D:\ 3 = C:\ 2 = D:\z\Neuer Ordner 5 = D:\_txt_ 4 = D:\_pyCvs 7 = C:\WINDOWS\DRWATSON\Desktop\py_tools 6 = D:\bookmarks 9 = C:\Eigene Dateien\My eBooks 8 = C:\Eigene Dateien [pane2] dir = D:\z\Neuer Ordner [pane1] dir = drives [dircombo] n_mru_items = 10 [mainwindow] size = 96,219,894,617 |