Disable ButtonPanel controls until PDF file chosen

Scale font metrics when rendering with Cairo (MSW only)
This commit is contained in:
David Hughes
2016-08-24 12:14:19 +01:00
committed by Robin Dunn
parent 6758e3870a
commit 4ca8c3e330
2 changed files with 28 additions and 15 deletions

View File

@@ -54,12 +54,17 @@ class pdfButtonPanel(bp.ButtonPanel):
"""
Add the buttons and other controls to the panel.
"""
self.disabled_controls = []
self.pagelabel = wx.StaticText(self, -1, 'Page')
self.page = wx.TextCtrl(self, -1, size=(30, -1), style=wx.TE_CENTRE|wx.TE_PROCESS_ENTER)
self.page.Enable(False)
self.disabled_controls.append(self.page)
self.page.Bind(wx.EVT_KILL_FOCUS, self.OnPage)
self.Bind(wx.EVT_TEXT_ENTER, self.OnPage, self.page)
self.maxlabel = wx.StaticText(self, -1, ' ')
self.zoom = wx.ComboBox(self, -1, style=wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER)
self.zoom.Enable(False)
self.disabled_controls.append(self.zoom)
self.comboval = (('Actual size', 1.0), ('Fit width', -1), ('Fit page', -2),
('25%', 0.25), ('50%', 0.5), ('75%', 0.75), ('100%', 1.0),
('125%', 1.25), ('150%', 1.5), ('200%', 2.0), ('400%', 4.0),
@@ -68,7 +73,6 @@ class pdfButtonPanel(bp.ButtonPanel):
self.zoom.Append(item[0], item[1]) # string value and client data
self.Bind(wx.EVT_COMBOBOX, self.OnZoomSet, self.zoom)
self.Bind(wx.EVT_TEXT_ENTER, self.OnZoomSet, self.zoom)
self.zoom.Bind(wx.EVT_KILL_FOCUS, self.OnZoomSet)
panelitems = [
('btn', images.PrintIt.GetBitmap(), wx.ITEM_NORMAL, "Print", self.OnPrint),
('sep',),
@@ -96,6 +100,8 @@ class pdfButtonPanel(bp.ButtonPanel):
btn = bp.ButtonInfo(self, wx.NewId(),image, kind=kind,
shortHelp=popup, longHelp='')
self.AddButton(btn)
btn.Enable(False)
self.disabled_controls.append(btn)
self.Bind(wx.EVT_BUTTON, handler, id=btn.GetId())
elif item[0].lower() == 'sep':
self.AddSeparator()
@@ -136,8 +142,14 @@ class pdfButtonPanel(bp.ButtonPanel):
is from 1 to numpages.
"""
if self.disabled_controls:
for item in self.disabled_controls:
item.Enable(True)
self.disabled_controls = []
self.Refresh()
self.pageno = pagenum + 1
self.page.SetValue('%d' % self.pageno)
self.page.ChangeValue('%d' % self.pageno)
if numpages != self.numpages:
self.maxlabel.SetLabel('of %d' % numpages)
self.numpages = numpages
@@ -202,10 +214,7 @@ class pdfButtonPanel(bp.ButtonPanel):
self.ChangePage()
except ValueError:
pass
if hasattr(self, 'pageno'):
self.page.SetValue('%d' % self.pageno)
else:
self.page.SetValue('')
event.Skip()
def OnZoomOut(self, event):
"Decrease page magnification"
@@ -264,8 +273,7 @@ class pdfButtonPanel(bp.ButtonPanel):
def ChangePage(self):
"""
Update viewer and self.page control with new page number.
Update viewer with new page number.
"""
self.page.SetValue('%d' % self.pageno)
self.viewer.GoPage(self.pageno - 1)

View File

@@ -344,11 +344,15 @@ class pdfViewer(wx.ScrolledWindow):
self.topage = 0
self.clientdc = dc = wx.ClientDC(self) # dc for device scaling
self.device_scale = dc.GetPPI()[0]/72.0 # pixels per inch / points per inch
self.font_scale = 1.0
# for Windows only wx.GraphicsContext fonts are too big
self.font_scale_metrics = 1.0
self.font_scale_size = 1.0
# for Windows only with wx.GraphicsContext the rendered font size is too big
# in the ratio of screen pixels per inch to points per inch
if wx.PlatformInfo[1] == 'wxMSW' and not have_cairo:
self.font_scale = 1.0 / self.device_scale
# and font metrics are too big in the same ratio for both for Cairo and wx.GC
if wx.PlatformInfo[1] == 'wxMSW':
self.font_scale_metrics = 1.0 / self.device_scale
if not have_cairo:
self.font_scale_size = 1.0 / self.device_scale
self.winwidth, self.winheight = self.GetClientSize()
if self.winheight < 100:
@@ -820,14 +824,15 @@ class pypdfProcessor(object):
"""
dlist = []
g = self.gstate
f = self.SetFont(g.font, g.fontSize*self.parent.font_scale)
dlist.append(['SetFont', (f, g.fillRGB), {}])
f0 = self.SetFont(g.font, g.fontSize*self.parent.font_scale_metrics)
f1 = self.SetFont(g.font, g.fontSize*self.parent.font_scale_size)
dlist.append(['SetFont', (f1, g.fillRGB), {}])
if g.wordSpacing > 0:
textlist = text.split(' ')
else:
textlist = [text,]
for item in textlist:
dlist.append(self.DrawTextItem(item, f))
dlist.append(self.DrawTextItem(item, f0))
return dlist
def DrawTextItem(self, textitem, f):