Changeset 12
- Timestamp:
- 09/23/07 07:04:02 (1 year ago)
- Files:
-
- branches/baptiste/fontypython/cli.py (modified) (19 diffs)
- branches/baptiste/fontypython/folder.py (modified) (1 diff)
- branches/baptiste/fontypython/fpsys.py (modified) (8 diffs)
- branches/baptiste/fontypython/wxgui.py (modified) (69 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/baptiste/fontypython/cli.py
r11 r12 65 65 #### 66 66 ## Let's handle those options that DO NOT require args 67 ## List - Quick and dirty. 67 ## List - Quick and dirty. 68 68 if options.list: 69 69 poglist = iPC.getPogNames() … … 93 93 if options.min: fpsys.config.max = False 94 94 if options.max: fpsys.config.max = True 95 95 96 96 #### 97 97 ## Size … … 99 99 if options.points > 0: 100 100 fpsys.config.points = int(options.points) 101 101 102 102 #### 103 103 ## View … … 113 113 if options.text: 114 114 fpsys.config.text = options.text 115 fpsys.config.Save() 115 fpsys.config.Save() 116 116 print _("Your text has been set to \"%s\"") % options.text 117 117 print _("Tip: Did you use quotes to surround your text?") 118 118 print _("Start FontyPython again to see the result.") 119 119 sys.exit() 120 120 121 121 #### 122 122 ## Let's just make sure the user has a .fonts folder … … 136 136 ## pog.purge() Raises 137 137 ## PogEmpty 138 ## PogInstalled 138 ## PogInstalled 139 139 pog.purge() 140 140 except(fontybugs.PogEmpty, fontybugs.PogInstalled), e: … … 144 144 fpsys.config.Save() 145 145 sys.exit(strings.done) 146 146 147 147 #### 148 148 ## Report stuff to console. … … 150 150 print message 151 151 152 #### 152 #### 153 153 ## Install: 154 154 if options.install: … … 164 164 ## PogEmpty 165 165 ## PogAllFontsFailedToInstall 166 ## PogSomeFontsDidNotInstall 166 ## PogSomeFontsDidNotInstall 167 167 print _("Installing %s") % pogtoinstall 168 168 pog.install() # will use progressCallBack to print each font name. 169 except (fontybugs.PogEmpty, 169 except (fontybugs.PogEmpty, 170 170 fontybugs.PogAllFontsFailedToInstall, 171 171 fontybugs.PogSomeFontsDidNotInstall, … … 176 176 fpsys.config.Save() 177 177 sys.exit(strings.done) 178 178 179 179 #### 180 180 ## uninstall … … 191 191 ## PogEmpty 192 192 ## PogLinksRemain 193 ## PogNotInstalled 193 ## PogNotInstalled 194 194 print _("Removing %s") % pogtouninstall 195 195 pog.uninstall() … … 202 202 fpsys.config.Save() 203 203 sys.exit(strings.done) 204 204 205 205 #### 206 206 ## If there are > 2 args then there is chaos: … … 208 208 ## The user may have chosen a pogname with spaces and no quotes 209 209 print _("""Please check your arguments, there seem to be too many. 210 (Remember: it's one pound for a five-minute argument, but only 210 (Remember: it's one pound for a five-minute argument, but only 211 211 eight pounds for a course of ten.) 212 212 213 213 NB: If you wanted to use spaces in a pogname or folder then 214 214 please put quotes around them.""") 215 sys.exit() 216 217 215 sys.exit() 216 218 217 #### 219 218 ## Handle Cases : … … 221 220 B = None 222 221 223 fakearg = False 222 fakearg = False 224 223 if not args: 225 224 args = [] … … 232 231 A = args [0] 233 232 if len(args) == 2: B = args [1] 234 233 235 234 ## Let's ensure that, should A be a pog, that it exists, BUT only if it was not a fakearg: 236 235 if not fpsys.isFolder(A) and not fpsys.isPog(A) and not fakearg: … … 241 240 if B and fpsys.isFolder(B): 242 241 sys.exit(_("You cannot use a folder as the target argument. Try --help")) 243 242 244 243 ## Let's ensure that B exists, else we must make it. 245 244 if B and not fpsys.isPog(B): … … 252 251 253 252 ## Build the fpsys structure 254 ## Calls to validateXYZ are vital. They are where the View or Target Objects get 253 ## Calls to validateXYZ are vital. They are where the View or Target Objects get 255 254 ## generated - i.e. where all their fontItems are built-up. 256 255 ## One arg: 257 256 if A and not B: 258 if fpsys.isFolder(A): 257 if fpsys.isFolder(A): 259 258 try: 260 259 fpsys.validateViewFolder(A) 261 260 except fontybugs.FolderHasNoFonts, e: 262 261 sys.exit(str(e)) 263 if fpsys.isPog(A): 262 if fpsys.isPog(A): 264 263 try: 265 264 fpsys.validateViewPog(A) … … 269 268 ## we must make an official "targetobject" set to None 270 269 fpsys.SetTargetPogToNone() 271 270 272 271 ## Two args: 273 272 if A and B: 274 if fpsys.isFolder(A)and fpsys.isPog(B): 273 if fpsys.isFolder(A)and fpsys.isPog(B): 275 274 ## "FP" 276 275 try: … … 283 282 sys.exit(str(e)) 284 283 if installed: sys.exit(_("The target pog (%s) is currently installed,\nyou can't use it as a target." % B)) 285 284 286 285 if fpsys.isPog(A)and fpsys.isPog(B): 287 286 ## "PP" … … 293 292 sys.exit(str(e)) 294 293 if empty: sys.exit(_("This pog is empty")) 295 294 296 295 try: 297 296 installed = fpsys.validateTargetPog(B) branches/baptiste/fontypython/folder.py
r11 r12 48 48 #print "f is ", f 49 49 try: 50 fi = FontItem(os.path.join(self.path, f), False) 50 fi = FontItem(os.path.join(self.path, f), False) 51 51 except UnicodeDecodeError, e: 52 52 sys.exit(_("The file %s has caused a unicode error.\nPlease rename it, removing any strange characters, and try again.") % f) 53 self.append(fi) 53 self.append(fi) 54 54 if len(self) == 0: 55 55 raise fontybugs.FolderHasNoFonts(self.path) 56 56 57 57 def label(self): 58 58 return str(self.path) branches/baptiste/fontypython/fpsys.py
r11 r12 39 39 ## other modules - so they are global to everything. 40 40 41 42 41 ## Ensure we have a .fontypython folder and a .fonts folder. 43 42 iPC = pathcontrol.PathControl() #Make an instance - hence the small 'i' … … 49 48 if os.path.islink(root): 50 49 root = os.path.realpath(root) 51 return os.path.dirname(os.path.abspath(root)) 50 return os.path.dirname(os.path.abspath(root)) 52 51 except: 53 52 print _("I'm sorry, but something is wrong.") 54 53 print _("There is no __file__ variable. Please contact the author.") 55 sys.exit() 54 sys.exit() 56 55 57 56 #### … … 61 60 return False 62 61 #### 63 ## 62 ## 64 63 def isPog(thing): 65 64 if thing in iPC.getPogNames(): return True … … 88 87 self.samepogs = False 89 88 self.numticks = 0 90 89 91 90 state = FPState() #The only instance of the state object -- app-wide 92 91 … … 103 102 ## Default assumptions in case of raised error. 104 103 state.viewobject = EmptyView() 105 state.viewpattern = "E" 104 state.viewpattern = "E" 106 105 ifolder = Folder(foldername) #raises : fontybugs.FolderHasNoFonts : BENIGN ERROR. 107 106 ## Only continues if there is no problem. … … 120 119 ipog = EmptyView() 121 120 else: 122 ipog = Pog(newpog_name) 121 ipog = Pog(newpog_name) 123 122 ## Test TARGETPOG to see if this is the same pogname 124 123 ## The not None test is for first run - there is no targetobject yet just after cli.py calls us, so we … … 150 149 def validateTargetPog(newpog_name): 151 150 if state.targetobject: del state.targetobject 152 ipog = Pog(newpog_name) 151 ipog = Pog(newpog_name) 153 152 ## Must gen the Pog to get a count of items: 154 153 ipog.genList() # Raises fontybugs.PogInvalid error THIS ENDS THE APP. … … 157 156 ## The pog clicked in the TARGET is the same as what's ALREADY selected in the VIEW 158 157 state.samepogs = True 159 else: 158 else: 160 159 state.samepogs = False 161 160 quickinstalledflag = False 162 161 if ipog.isInstalled(): quickinstalledflag = True 163 state.targetpattern = "P" 162 state.targetpattern = "P" 164 163 state.targetobject = ipog 165 164 markInactive() 166 165 flushTicks() 167 166 return quickinstalledflag 168 167 169 168 ## Mark each font item as inactive, as needs be. 170 169 ## Also clears the ticks. 171 170 def markInactive(): 172 171 if state.viewobject: state.viewobject.clearInactiveflags() 173 172 174 173 if state.viewobject and state.targetobject: 175 174 ## What's in TARGET must be inactive in VIEW branches/baptiste/fontypython/wxgui.py
r11 r12 60 60 def __init__(self,parent, pos ,fitem) : 61 61 self.name = fitem.name 62 62 63 63 self.fitem = fitem 64 64 self.parent = parent 65 65 66 66 ## I prevent font's own height due to mad ttfs. 67 67 ## I based this on my preference. Some ttfs had these crazy heights 68 68 ## and would shoot off the page. So, I nixed that. 69 69 self.height = fpsys.config.points * 1.55 70 70 71 71 self.bitmap, self.goodfont = self.__wxTtfBitmap(self.fitem.paf, fpsys.config.points, " " + fpsys.config.text + " ") 72 72 self.whitebrush = wx.Brush('WHITE',wx.SOLID) 73 73 74 74 sz = (self.bitmap.GetWidth() , self.height) 75 75 self.gsb = wx.lib.statbmp.GenStaticBitmap.__init__(self,parent, -1, self.bitmap, pos, sz) 76 76 77 77 self.width = self.bitmap.GetWidth() 78 78 79 79 self.Bind(wx.EVT_LEFT_UP,self.__onClick) 80 80 self.Bind(wx.EVT_PAINT, self.__onPaint) 81 81 82 82 def __onPaint(self, event) : 83 83 dc = wx.PaintDC(self) … … 153 153 if not self.fitem.ticked: fpsys.state.numticks -= 1 154 154 ps.pub(toggle_main_button) 155 155 156 156 def __wxTtfBitmap(self, paf, points, text) : 157 157 """Make a font and draw it using PIL. Then convert it to a wx bitmap. … … 206 206 self.fitmaps = [] 207 207 self.parent = parent 208 208 209 209 def DrawFitmaps(self, viewobject) : 210 210 """Draw X number of fitmaps down the control""" … … 214 214 215 215 self.fitmaps = [] 216 216 217 217 #### 218 218 ## It's NB to notice that the fitems being put into self.fitmaps are … … 222 222 ## you can rely on the the fitem within viewobject having a ticked True/False 223 223 ## attribute outside of this class. 224 224 225 225 i = 0 226 226 h = 0 … … 254 254 def __init__(self, parent): 255 255 wx.Panel.__init__(self, parent, id = -1) 256 256 257 257 self.pageindex = 1 # I start here 258 258 self.total_number_of_pages = 0 259 259 260 260 self.filter = "" 261 261 262 262 self.TICKMAP = None 263 263 self.TICK = wx.Bitmap(fpsys.mythingsdir + "tick.png", type=wx.BITMAP_TYPE_PNG) 264 264 self.CROSS = wx.Bitmap(fpsys.mythingsdir + "cross.png", type=wx.BITMAP_TYPE_PNG) 265 265 266 266 ## Main Label on top 267 267 sizerMainLabel = wx.BoxSizer(wx.HORIZONTAL) … … 269 269 self.textMainInfo.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD)) 270 270 sizerMainLabel.Add(self.textMainInfo,1,wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT) 271 271 272 272 ## Page choice and Filter controls 273 273 sizerOtherControls = wx.BoxSizer(wx.HORIZONTAL) … … 278 278 self.choicePage = wx.Choice(self, -1, choices = [_("busy")]) 279 279 self.choicePage.Bind(wx.EVT_CHOICE, self.__onPagechoiceClick) #Bind choice event 280 280 281 281 sizerOtherControls.Add(self.textFilter, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL) 282 282 sizerOtherControls.Add(self.inputFilter, 1, wx.ALIGN_LEFT | wx.EXPAND) 283 283 sizerOtherControls.Add(( 4,-1), 0, wx.EXPAND) 284 284 sizerOtherControls.Add(self.choicePage, 0 ,wx.EXPAND | wx.ALIGN_RIGHT) #Added it to the sizer 285 285 286 286 ## The FONT panell: 287 self.panelFontView = FontView(self) 288 289 buttonsSizer = wx.BoxSizer(wx.HORIZONTAL) 290 self.buttPrev = wx.Button(self, wx.ID_BACKWARD) 291 292 self.buttMain = wx.Button(self, label=_("loading"), id = 3) 293 self.buttNext = wx.Button(self, wx.ID_FORWARD) 287 self.panelFontView = FontView(self) 288 289 buttonsSizer = wx.BoxSizer(wx.HORIZONTAL) 290 self.buttPrev = wx.Button(self, wx.ID_BACKWARD) 291 292 self.buttMain = wx.Button(self, label=_("loading"), id = 3) 293 self.buttNext = wx.Button(self, wx.ID_FORWARD) 294 294 self.buttPrev.Enable(False) #Starts out disabled 295 296 buttonsSizer.Add(self.buttPrev,0,wx.EXPAND) 297 buttonsSizer.Add((10,1) ,0,wx.EXPAND) 298 buttonsSizer.Add(self.buttMain,1,wx.EXPAND) 299 buttonsSizer.Add((10,1) ,0,wx.EXPAND) 300 buttonsSizer.Add(self.buttNext,0,wx.EXPAND) 295 296 buttonsSizer.Add(self.buttPrev,0,wx.EXPAND) 297 buttonsSizer.Add((10,1) ,0,wx.EXPAND) 298 buttonsSizer.Add(self.buttMain,1,wx.EXPAND) 299 buttonsSizer.Add((10,1) ,0,wx.EXPAND) 300 buttonsSizer.Add(self.buttNext,0,wx.EXPAND) 301 301 302 302 ## Now the sizer to hold all the fontview controls … … 306 306 self.sizerFontView.Add(sizerOtherControls, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, border = 3) #Choice and Filter 307 307 self.sizerFontView.Add(buttonsSizer,0,wx.EXPAND) #The buttons 308 308 309 309 self.SetSizer(self.sizerFontView) 310 310 311 311 self.buttPrev.Bind(wx.EVT_LEFT_UP,self.__navClick) 312 312 self.buttNext.Bind(wx.EVT_LEFT_UP,self.__navClick) 313 313 self.buttMain.Bind(wx.EVT_LEFT_UP,self.__onMainClick) 314 314 315 315 ps.sub(toggle_main_button, self.ToggleMainButton) 316 316 317 317 ## Catch the ENTER key in the filter text input control 318 318 def __evtChar(self, e): … … 328 328 self.buttMain.SetFocus() 329 329 e.Skip() 330 330 331 331 def __drawTheFonts(self): 332 332 """Figure out what list of fonts to draw, divide them into pages and draw them.""" … … 354 354 #print "total_num_fonts=", total_num_fonts 355 355 gross = total_num_fonts / float(num_in_one_page) 356 356 357 357 if gross <= 1: 358 358 ## There are less than num_in_one_page fonts to be viewed at all. … … 364 364 if remainder > 0: whole_number_of_pages += 1 365 365 self.total_number_of_pages = whole_number_of_pages 366 367 366 368 367 start = current_page * num_in_one_page #leaf thru the pages to the one we are on now. 369 368 fin = start + num_in_one_page 370 369 if fin > len(filteredList): fin = len(filteredList) #Make sure we don't overshoot. 371 370 372 371 sublist = filteredList[start:fin] #Extract a single page of fonts to display 373 372 374 373 self.choicePage.Clear() #Empty the choice control, then refill it: 375 374 [self.choicePage.Append(str(n)) for n in range(1, self.total_number_of_pages +1)] … … 382 381 else: 383 382 self.choicePage.Enable(True) 384 383 385 384 self.panelFontView.DrawFitmaps(sublist) 386 385 self.__buttonState() 387 386 388 387 ## Main BUTTON click -- the main "do something" button. 389 388 def __onMainClick(self, e): … … 394 393 self.panelFontView.Scroll(xPos, yPos) 395 394 396 def __onPagechoiceClick(self,event) :395 def __onPagechoiceClick(self,event): 397 396 wx.BeginBusyCursor() 398 397 if self.pageindex != int(event.GetString() ) : #Only redraw if actually onto another page. … … 400 399 self.__drawTheFonts() 401 400 wx.EndBusyCursor() 402 def __navClick(self,event) : 401 402 def __navClick(self,event): 403 403 wx.BeginBusyCursor() 404 404 if event.GetId() == wx.ID_FORWARD: … … 414 414 self.__drawTheFonts() 415 415 wx.EndBusyCursor() 416 def __buttonState(self) : 416 417 def __buttonState(self): 417 418 #state of buttons 418 419 n = True … … 424 425 self.buttNext.Enable(n) 425 426 self.buttPrev.Enable(p) 427 426 428 def ToggleMainButton(self, args = None): 427 429 if fpsys.state.numticks > 0: self.buttMain.Enable(True) 428 430 else: self.buttMain.Enable(False) 429 431 430 432 def MainFontViewUpdate(self): 431 433 """Vital routine - the heart if the app. 432 434 This decides what to do based on what has been selected. 433 435 It draws the controls and the fonts as appropriate. It also sets flags in fpsys.state.""" 434 436 435 437 ## Get shorter vars to use. 436 438 V= fpsys.state.viewobject 437 439 T = fpsys.state.targetobject 438 440 439 441 Vpatt = fpsys.state.viewpattern # View Pattern 440 442 Tpatt = fpsys.state.targetpattern # Target pattern 441 443 442 444 Patt = Vpatt + Tpatt # Patt = Pattern 443 445 444 446 #print "Vpatt", Vpatt 445 447 #print "Tpatt", Tpatt … … 447 449 lab = "" 448 450 status = "" 449 451 450 452 if Vpatt == "E": #NOTE : TESTING VPATT, not PATT - ergo: this covers E, EN, EP 451 453 ## Empty "E" - when the chosen Folder or Pog has NO FONTS IN IT. … … 457 459 fpsys.state.cantick = False 458 460 fpsys.state.action = "CLOSE" # We will test this in mainframe::OnMainClick 459 461 460 462 elif Patt == "FN": 461 463 #View a Folder, no target … … 519 521 else: 520 522 sys.exit(_("%s and trouble") % Patt) 521 523 522 524 self.buttMain.SetLabel(btext) 523 525 self.textMainInfo.SetLabel(lab) … … 526 528 ps.pub(print_to_status_bar, status) 527 529 self.ToggleMainButton() 528 530 529 531 fpsys.markInactive() 530 532 self.__drawTheFonts() … … 532 534 def ResetToPageOne(self): 533 535 self.pageindex = 1 # I start here 534 536 535 537 ## Far right-hand side control. Chooses target pogs. Houses control buttons. 536 538 class TargetPogChooser(wx.Panel): … … 538 540 def __init__(self, parent): 539 541 wx.Panel.__init__(self, parent, id = -1) 540 542 541 543 self.icon = wx.StaticBitmap(self, -1, wx.Bitmap(fpsys.mythingsdir + 'icon_target_16x16.png', wx.BITMAP_TYPE_PNG)) 542 544 self.textInfo = wx.StaticText(self, -1, _("Target Pogs"), style = wx.ALIGN_LEFT) #CENTER_HORIZONTAL) … … 545 547 s = fpsys.state.targetobject.name 546 548 self.pogTargetlist = PogChooser(self, select = s) 547 549 548 550 ## Subscriptions: 549 551 ps.sub(pog_selected, self.OnPogTargetClick) 550 552 ps.sub(toggle_buttons, self.ToggleButtons) 551 553 ps.sub(select_no_target_pog, self.SelectNoTargetPog) 552 554 553 555 ## The "no pog" button 554 556 self.idnone = wx.NewId() … … 562 564 self.iddelete = wx.NewId() 563 565 self.idpurge = wx.NewId() 564 566 565 567 self.buttNew = wx.Button(self, label = _("New Pog"), id = self.idnew ) 566 568 self.buttInstall = wx.Button(self, label = _("Install Pog"), id = self.idinstall ) … … 568 570 self.buttDelete = wx.Button(self, label = _("Delete Pog"), id = self.iddelete) 569 571 self.buttPurge = wx.Button(self, label = _("Purge Pog"), id = self.idpurge) 570 572 571 573 self.sizer = wx.BoxSizer(wx.VERTICAL) 572 574 self.iconandtext = wx.BoxSizer(wx.HORIZONTAL) … … 582 584 self.sizer.Add(self.buttPurge, 0, wx.EXPAND) 583 585 self.SetSizer(self.sizer) 584 586 585 587 ## Bind the events: 586 588 self.buttNoPog.Bind(wx.EVT_LEFT_UP, self.__multiClick) … … 590 592 self.buttDelete.Bind(wx.EVT_LEFT_UP, self.__multiClick) 591 593 self.buttPurge.Bind(wx.EVT_LEFT_UP, self.__multiClick) 592 594 593 595 self.__toggleButtons() 594 596 ## Catch all the button clicks on the control. … … 622 624 dlg.Destroy() 623 625 return 624 626 625 627 ## DELETE 626 628 if e.GetId() == self.iddelete: … … 653 655 dlg.Destroy() 654 656 return 655 657 656 658 ## NO POG pressed 657 659 if e.GetId() == self.idnone: … … 693 695 if e.GetId() == self.iduninstall: 694 696 ps.pub(uninstall_pog) 695 697 696 698 def OnPogTargetClick(self, args): 697 699 ## id of the originating instance is sent in args [1] … … 713 715 ps.pub(update_font_view) 714 716 self.__toggleButtons() 715 717 716 718 def ToggleButtons(self, args): 717 719 ## Shadow the __toggleButtons func. … … 730 732 self.buttUninstall.Enable(installed) # UNINSTALL = True if pog is installed. 731 733 self.buttPurge.Enable(not(installed)) 732 734 733 735 def SelectNoTargetPog(self, args): 734 736 ## Shadow … … 747 749 self.indexselected = 0 748 750 self.lastindexselected = -1 749 751 750 752 il = wx.ImageList(16,16,True) 751 753 png = wx.Bitmap(fpsys.mythingsdir + "/pog16x16.png",wx.BITMAP_TYPE_PNG) … … 753 755 png = wx.Bitmap(fpsys.mythingsdir + "/pog16x16.installed.png",wx.BITMAP_TYPE_PNG) 754 756 il.Add(png) 755 757 756 758 wx.ListCtrl.__init__(self,parent,-1, style=wx.LC_LIST | wx.LC_AUTOARRANGE | wx.LC_SORT_ASCENDING) 757 759 self.AssignImageList(il, wx.IMAGE_LIST_SMALL) 758 760 759 761 self.__PC = pathcontrol.PathControl() 760 762 761 763 self.__fillPogList() 762 764 763 765 if select: 764 766 i = self.FindItem(-1, select) … … 769 771 self.ClearBackground() 770 772 self.items = None 771 773 772 774 ## These two work together: 773 775 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.__onSelect) 774 776 775 777 self.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) 776 778 777 779 ## A subscribe line here, will register TWICE since this PogChooser object is instanced 778 780 ## twice by the app... 779 781 ps.sub(change_pog_icon, self.ChangeIcon) 780 782 781 783 def __onSelect(self, e): 782 784 wx.BeginBusyCursor() … … 796 798 def __del__(self) : 797 799 del self.items 798 800 799 801 ## This is among the very FIRST things we do. 800 802 ## Fill the list with pogs. … … 818 820 except: 819 821 sys.exit(sys.exc_info()[0]) 820 822 821 823 def AddItem(self, pogname): 822 824 li = wx.ListItem() … … 824 826 li.SetText(pogname) 825 827 self.InsertItem(li) 826 828 827 829 def RemoveItem(self, pogname): 828 830 i = self.FindItem(-1, pogname) … … 832 834 self.Select(self.indexselected, False) 833 835 self.lastindexselected = -1 834 836 835 837 def ChangeIcon(self, args): 836 838 T = fpsys.state.targetobject … … 840 842 else: n = 0 841 843 self.SetItemImage(index, n) ## Found in wxWidgets documentation! 842 843 844 844 845 ## Need to reset the lastindexselected so that a click on the 845 846 ## same item as last time will register. This is used in the Notebook … … 854 855 wx.SplitterWindow.__init__(self, parent, -1, style = wx.SP_LIVE_UPDATE | wx.SP_3D) 855 856 856 857 857 ## A short class as I started to abstract the Directory Control. 858 858 ## Eventually I want a fully standalone version. 859 class DirControl(wx.GenericDirCtrl) :859 class DirControl(wx.GenericDirCtrl): 860 860 def __init__(self, parent): 861 if fpsys.state.viewpattern == "F": startdir = fpsys.state.viewobject.path 861 if fpsys.state.viewpattern == "F": 862 startdir = fpsys.state.viewobject.path 862 863 else: 863 864 ##Let's get it from the config object … … 867 868 else: 868 869 startdir = os.environ['HOME'] 869 wx.GenericDirCtrl.__init__(self, parent, -1, dir =startdir, style=wx.DIRCTRL_DIR_ONLY) #size=(200,225)870 self.tree = self.GetTreeCtrl() 870 wx.GenericDirCtrl.__init__(self, parent, -1, dir=startdir, style=wx.DIRCTRL_DIR_ONLY) #size=(200,225) 871 self.tree = self.GetTreeCtrl() 871 872 self.tree.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) 872 873 … … 874 875 ## Has two tabs - Folders and Pogs 875 876 ## THIS IS THE VIEW or SOURCE of fonts. 876 class NoteBook(wx.Notebook) :877 class NoteBook(wx.Notebook): 877 878 def __init__(self, parent): 878 879 wx.Notebook.__init__(self, parent) 879 880 self.imlist = wx.ImageList(16, 16) 880 881 881 882 pan1 = wx.Panel(self) 882 self.dircontrol = DirControl(pan1) 883 883 self.dircontrol = DirControl(pan1) 884 884 885 box = wx.BoxSizer(wx.HORIZONTAL) 885 886 box.Add(self.dircontrol,1, wx.EXPAND) … … 888 889 889 890 self.pogindexselected = 0 890 891 pan2 = wx.Panel(self) 892 891 892 pan2 = wx.Panel(self) 893 893 894 page = 0 894 895 s = None 895 if fpsys.state.viewpattern == "P": 896 if fpsys.state.viewpattern == "P": 896 897 s = fpsys.state.viewobject.name 897 898 if s == "EMPTY": s= None #Very first run, the view will be an EMPTY object. … … 901 902 ps.sub(pog_selected, self.OnViewPogClick) 902 903 ps.sub(select_no_view_pog, self.SelectNoView) 903 904 904 905 self.tree = self.dircontrol.GetTreeCtrl() 905 906 #self.tree.Bind(wx.EVT_LEFT_DCLICK, self.__onDirCtrlDClick) #Old system - double click. 906 907 #self.tree.Bind(wx.EVT_LIST_ITEM_SELECTED, self.__onDirCtrlDClick) #Did not fire. 907 908 self.tree.Bind(wx.EVT_LEFT_UP, self.__onDirCtrlClick) 908 909 909 910 box2 = wx.BoxSizer(wx.HORIZONTAL) 910 911 box2.Add(self.listctrl,1,wx.EXPAND) 911 912 pan2.SetSizer(box2) 912 913 box2.Layout() 913 914 914 915 self.AddPage(pan1, _("Folders")) 915 916 self.AddPage(pan2, _("Pogs")) 916 917 917 918 source_pog_icon = self.imlist.Add(wx.Bitmap(fpsys.mythingsdir + "/icon_source_pog_16x16.png",wx.BITMAP_TYPE_PNG)) 918 919 … … 921 922 self.SetPageImage(1, source_pog_icon) 922 923 self.SetPageImage(0, target_pog_icon) 923 924 924 925 self.SetSelection(page) 925 926 926 927 self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.__onPageChanged) # Bind page changed event 927 928 928 929 def __onPageChanged(self, e): 929 930 self.listctrl.ClearLastIndex() 930 931 e.Skip() 931 932 932 933 def __onDirCtrlClick(self, e): 933 934 wx.BeginBusyCursor() #Thanks to Suzuki Alex on the wxpython list! … … 940 941 ps.pub(update_font_view) 941 942 wx.EndBusyCursor() 942 943 943 944 def OnViewPogClick(self, args): 944 945 ## id of the originating instance is sent in args[1] … … 964 965 def RemoveItem(self, pogname): 965 966 self.listctrl.RemoveItem(pogname) 966 967 967 968 def SelectNoView(self, args): 968 969 ## Purpose: To select no viewobject and clear view pog list selections … … 972 973 fpsys.SetViewPogToEmpty() 973 974 wx.EndBusyCursor() 974 975 975 976 ## Status bar 976 977 class StatusBar(wx.StatusBar): … … 981 982 def Report(self, msg): 982 983 self.SetStatusText(msg, 0) 983 984 984 985 ## The main brain of the app. 985 986 class MainFrame(wx.Frame) : … … 988 989 wx.Frame.__init__(self,parent,-1,title,fpsys.config.pos,fpsys.config.size) 989 990 self.SetSizeHintsSz((300,400) ) #After hours of hell, this is all that seems to work. 990 991 991 992 ## Try to show an icon 992 993 try: … … 1000 1001 1001 1002 max = fpsys.config.max # Do we draw min or max interface? 1002 1003 1003 1004 PARENT = self 1004 1005 1005 1006 ## STATUS BAR 1006 1007 self.sb = StatusBar(self) 1007 1008 self.SetStatusBar(self.sb) 1008 1009 1009 1010 if max: 1010 1011 ## Prepare the menu bar 1011 1012 menuBar = wx.MenuBar() 1012 1013 1013 1014 ## 1st menu from left 1014 1015 menu1 = wx.Menu() … … 1018 1019 ## Add menu to the menu bar 1019 1020 menuBar.Append(menu1, _("&File")) 1020 1021 1021 1022 ## 2nd menu from left 1022 1023 menu2 = wx.Menu() … … 1025 1026 ## Append 2nd menu 1026 1027 menuBar.Append(menu2, _("&Help")) 1027 1028 1028 1029 ## Tell the frame the news 1029 1030 self.SetMenuBar(menuBar) 1030 1031 1031 1032 ## Setup the ESC key trap 1032 1033 accel = wx.AcceleratorTable([(wx.ACCEL_NORMAL, wx.WXK_ESCAPE, exit.GetId())]) 1033 1034 self.SetAcceleratorTable(accel) 1034 1035 1035 1036 self.Bind(wx.EVT_MENU, self.__onHandleESC, exit) 1036 1037 self.Bind(wx.EVT_MENU, self.__menuSettings, id = 101) … … 1044 1045 self.SetAcceleratorTable(self.accel) 1045 1046 self.Bind(wx.EVT_MENU, self.__onHandleESC, id=ID_ESC) 1046 1047 1047 1048 ## Create a splitter 1048 1049 if max: 1049 1050 self.splitter = Splitter(self) 1050 1051 1051 1052 ## The notebook : has a bunch of callbacks it needs to make. 1052 1053 self.panelNotebook = wx.Panel(self.splitter) 1053 1054 self.nb = NoteBook(self.panelNotebook) 1054 1055 1055 1056 self.sizerNotebook = wx.BoxSizer(wx.HORIZONTAL) 1056 1057 self.sizerNotebook.Add(self.nb,1,wx.EXPAND) 1057 1058 1058 1059 self.panelNotebook.SetSizer(self.sizerNotebook) 1059 1060 self.sizerNotebook.Layout() 1060 1061 1061 1062 PARENT = self.splitter 1062 1063 1063 1064 self.panelMain = wx.Panel(PARENT ) 1064 1065 1065 1066 ## Font View Panel Control: 1066 1067 self.panelFontView = FontViewPanel(self.panelMain) 1067 1068 1068 1069 self.sizerFontView = wx.BoxSizer(wx.VERTICAL) 1069 1070 self.sizerFontView.Add(self.panelFontView, 1, wx.EXPAND) 1070 1071 1071 1072 if max: 1072 1073 ## THE FAR RIGHT HAND SIDE … … 1077 1078 self.sizerRight = wx.BoxSizer(wx.HORIZONTAL) 1078 1079 self.sizerSpace.Add(self.panelTargetPogChooser, 1, wx.EXPAND | wx.LEFT, border = 3) ## couched the panelTargetPogChooser in this to allow space around edges 1079 1080 1080 1081 self.sizerRight.Add(self.sizerFontView, 1, wx.EXPAND) 1081 1082 self.sizerRight.Add(self.sizerSpace, 0, wx.EXPAND) 1082 1083 1083 1084 self.panelMain.SetSizer(self.sizerRight) 1084 1085 else: 1085 1086 self.panelMain.SetSizer(self.sizerFontView) 1086 1087 1087 1088 self.panelMain.Layout() 1088 1089 … … 1090 1091 self.splitter.SetMinimumPaneSize(64) 1091 1092 self.splitter.SplitVertically(self.panelNotebook, self.panelMain ,180) 1092 1093 1093 1094 1094 self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) 1095 1095 1096 1096 ## Now to subscribe to have my various def called from other places: 1097 1097 ps.sub(update_font_view, self.UpdateFontViewPanel) … … 1109 1109 ## call the big one - the big chief, the big cheese: 1110 1110 self.UpdateFontViewPanel() #Go and fill in the font view and surrounding controls 1111 1111 1112 1112 ## PUBLIC API: 1113 1113 def StatusbarPrint(self, args): … … 1120 1120 """Calls ResetToPageOne in the FontViewPanel""" 1121 1121 self.panelFontView.ResetToPageOne() 1122 1122 1123 1123 def MessageBox(self, args): 1124 1124 dlg = wx.MessageDialog(self, args[0] , _("Warning"), wx.OK | wx.ICON_INFORMATION) … … 1132 1132 self.ErrorBox(args) #Pass it along to be displayed 1133 1133 self.__endApp() 1134 1134 1135 1135 def UpdateFontViewPanel(self, args = None): 1136 1136 self.panelFontView.MainFontViewUpdate() 1137 1137 self.Refresh() 1138 1138 1139 1139 def InstallPog(self, args): 1140 1140 ## pog.install() Raises: … … 1178 1178 self.UpdateFontViewPanel() 1179 1179 1180 1181 1180 def OnMainClick(self, args) : 1182 1181 """Closes
