saketh / notalon (http://notalon.org/)

Notalon is note-taking, simplified. It is a note-taking software for students, lifting the burden of formatting so that you can focus on taking notes.

Clone this repository (size: 2.2 MB): HTTPS / SSH
$ hg clone http://bitbucket.org/saketh/notalon/
commit 145: 2fb9e090f89d
parent 144: 53d141393793
branch: default
made bold/italicize toggle appropriate (based on wxpython richtextctrl example)
Saketh Bhamidipati / saketh
7 months ago

Changed (Δ968 bytes):

raw changeset »

notalonlib/window.py (33 lines added, 9 lines removed)

Up to file-list notalonlib/window.py:

@@ -391,9 +391,9 @@ class NotalonWindow(wx.Frame):
391
391
            inserttab = FM.FlatMenuItem(insertmenu, wx.NewId(), _("&Tab\tTab"), _("Insert tab"), wx.ITEM_NORMAL, None, self.resin.getImage("indent"))
392
392
            insertmenu.AppendItem(inserttab)
393
393
394
            formatbold = FM.FlatMenuItem(formatmenu, wx.NewId(), _("&Bold\tCtrl+B"), _("Bold selected text"), wx.ITEM_NORMAL, None, self.resin.getImage("formatbold")) # TODO: add image
394
            formatbold = FM.FlatMenuItem(formatmenu, wx.NewId(), _("&Bold\tCtrl+B"), _("Bold selected text"), wx.ITEM_CHECK, None, self.resin.getImage("formatbold")) # TODO: add image
395
395
            formatmenu.AppendItem(formatbold)
396
            formatitalicize = FM.FlatMenuItem(formatmenu, wx.NewId(), _("&Italicize\tCtrl+I"), _("Italicize selected text"), wx.ITEM_NORMAL, None, self.resin.getImage("formatitalicize")) # TODO: add image
396
            formatitalicize = FM.FlatMenuItem(formatmenu, wx.NewId(), _("&Italicize\tCtrl+I"), _("Italicize selected text"), wx.ITEM_CHECK, None, self.resin.getImage("formatitalicize")) # TODO: add image
397
397
            formatmenu.AppendItem(formatitalicize)
398
398
399
399
            helplicense = FM.FlatMenuItem(helpmenu, wx.NewId(), _("&License Agreement..."), _(" Text of the License Agreement"), wx.ITEM_NORMAL, None, self.resin.getImage("helplicense"))
@@ -463,7 +463,9 @@ class NotalonWindow(wx.Frame):
463
463
            self.Bind(FM.EVT_FLAT_MENU_SELECTED, self.content.OnIndent, inserttab)
464
464
465
465
            self.Bind(FM.EVT_FLAT_MENU_SELECTED, self.OnBold, formatbold)
466
            self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateBold, formatbold)
466
467
            self.Bind(FM.EVT_FLAT_MENU_SELECTED, self.OnItalicize, formatitalicize)
468
            self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateItalicize, formatitalicize)
467
469
468
470
            self.Bind(FM.EVT_FLAT_MENU_SELECTED, self.OnFullscreen, viewfullscreen)
469
471
@@ -573,9 +575,9 @@ class NotalonWindow(wx.Frame):
573
575
            inserttab = insertmenu.Append(wx.NewId(), _("&Tab\tTab"), _("Insert tab"))
574
576
            inserttab.SetBitmap(self.resin.getImage("indent"))
575
577
576
            formatbold = formatmenu.Append(wx.NewId(), _("&Bold\tCtrl+B"), _("Bold selected text"))
578
            formatbold = formatmenu.AppendCheckItem(wx.NewId(), _("&Bold\tCtrl+B"), _("Bold selected text"))
577
579
            formatbold.SetBitmap(self.resin.getImage("formatbold"))
578
            formatitalicize = formatmenu.Append(wx.NewId(), _("&Italicize\tCtrl+I"), _("Italicize selected text"))
580
            formatitalicize = formatmenu.AppendCheckItem(wx.NewId(), _("&Italicize\tCtrl+I"), _("Italicize selected text"))
579
581
            formatitalicize.SetBitmap(self.resin.getImage("formatitalicize"))
580
582
581
583
            helplicense = helpmenu.Append(wx.NewId(), _("&License Agreement..."), _(" Text of the License Agreement"))
@@ -622,7 +624,9 @@ class NotalonWindow(wx.Frame):
622
624
            self.Bind(wx.EVT_MENU, self.content.OnIndent, inserttab)
623
625
624
626
            self.Bind(wx.EVT_MENU, self.OnBold, formatbold)
627
            self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateBold, formatbold)
625
628
            self.Bind(wx.EVT_MENU, self.OnItalicize, formatitalicize)
629
            self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateItalicize, formatitalicize)
626
630
627
631
            self.Bind(wx.EVT_MENU, self.OnFullscreen, viewfullscreen)
628
632
@@ -843,12 +847,14 @@ class NotalonWindow(wx.Frame):
843
847
            self.toolbar.AddSeparator()
844
848
845
849
            tempid = wx.NewId()
846
            self.toolbarbold = self.toolbar.AddLabelTool(tempid, _('Bold'), self.resin.getImage("formatbold22"))
850
            self.toolbarbold = self.toolbar.AddCheckLabelTool(tempid, _("Bold"), self.resin.getImage("formatbold22"))
847
851
            self.Bind(wx.EVT_TOOL, self.OnBold, id=tempid)
852
            self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateBold, id=tempid)
848
853
849
854
            tempid = wx.NewId()
850
            self.toolbaritalicize = self.toolbar.AddLabelTool(tempid, _('Italicize'), self.resin.getImage("formatitalicize22"))
855
            self.toolbaritalicize = self.toolbar.AddCheckLabelTool(tempid, _("Italicize"), self.resin.getImage("formatitalicize22"))
851
856
            self.Bind(wx.EVT_TOOL, self.OnItalicize, id=tempid)
857
            self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateItalicize, id=tempid)
852
858
            
853
859
            self.toolbar.Realize()
854
860
@@ -897,10 +903,8 @@ class NotalonWindow(wx.Frame):
897
903
898
904
        if not self.tree.IsHeading():
899
905
            self.toolbarexportpdf.Enable(False)
900
            self.toolbarprintpreview.Enable(False)
901
906
        else:
902
907
            self.toolbarexportpdf.Enable(True)
903
            self.toolbarprintpreview.Enable(True)
904
908
905
909
    def OnRedo(self, e):
906
910
        self.undoer.redo()
@@ -1481,24 +1485,44 @@ class NotalonWindow(wx.Frame):
1481
1485
            log.debug("Saving to new file '%s'" % self.filename)
1482
1486
1483
1487
    def OnBold(self, e):
1488
        """Handler for when selected text is bolded.
1489
        
1490
        """
1484
1491
        log.debug('OnBold')
1485
1492
        self.content.ApplyBoldToSelection()
1486
1493
        self.SetModified(True)
1487
1494
        # Save the new formatting as HTML to the currently selected node's data field
1488
1495
        self.tree.SetPyData(self.tree.GetSelection(), self.content.GetHTML(stripped=True))
1489
1496
1497
    def OnUpdateBold(self, e):
1498
        """Handler for `wx.EVT_UPDATE_UI`.
1499
        
1500
        """
1501
        if hasattr(self, 'content'): # if we've gotten this far in the initialization
1502
            e.Check(self.content.IsSelectionBold())
1503
1490
1504
    def OnItalicize(self, e):
1505
        """Handler for when selected text is italicized.
1506
1507
        """
1491
1508
        log.debug('OnItalicize')
1492
1509
        self.content.ApplyItalicToSelection()
1493
1510
        self.SetModified(True)
1494
1511
        self.tree.SetPyData(self.tree.GetSelection(), self.content.GetHTML(stripped=True))
1495
1512
1513
    def OnUpdateItalicize(self, e):
1514
        """Handler for wx.EVT_UPDATE_UI`.
1515
        
1516
        """
1517
        if hasattr(self, 'content'): # if we've gotten this far in the initialization
1518
            e.Check(self.content.IsSelectionItalics())
1519
1496
1520
    def OnExportPDF(self, e):
1497
1521
        log.debug('Entered OnExportPDF')
1498
1522
        # If there are no headings, then there will be a corrupted PDF. 
1499
1523
        if not self.tree.ItemHasChildren(self.tree.GetRootItem()):
1500
1524
            d = wx.MessageDialog(self,
1501
                                _("You must have at least one heading before you can export to PDF."),
1525
                                _("Create a heading first, then try again."),
1502
1526
                                _("Error"),
1503
1527
                                wx.OK | wx.ICON_ERROR)
1504
1528
            d.ShowModal() # Show the dialog