def ScaleFont(font_size): # Assume default DPI is 72 DEFAULT_DPI = 72 dpi = wx.GetDisplayPPI()[ 1] # Point size determines font height, so look at the vertical DPI return int(round((font_size * DEFAULT_DPI) / dpi)) # Rounding up seems to give better results
def do_toolbar(self): if os.name == 'nt': size = (24, 24) else: size = (-1, -1) dpi_scale_factor=wx.GetDisplayPPI()[0]/96. tb_bmp_size=int(dpi_scale_factor*20) space = (5, -1) button_names = ['Insert', 'Delete', 'Rename'] button_images = [wx.Bitmap(images.insert_layer.GetImage().Scale(tb_bmp_size,tb_bmp_size)), wx.Bitmap(images.delete.GetImage().Scale(tb_bmp_size,tb_bmp_size)), wx.Bitmap(images.change_name.GetImage().Scale(tb_bmp_size,tb_bmp_size))] callbacks = [self.eh_insert, self.eh_delete, self.eh_rename] tooltips = ['Insert', 'Delete', 'Rename'] boxbuttons = wx.BoxSizer(wx.HORIZONTAL) boxbuttons.Add((5,-1)) for i in range(len(button_names)): #button = wx.Button(self,-1, button_names[i]) button = wx.BitmapButton(self, -1, button_images[i], style=wx.NO_BORDER, size = size) boxbuttons.Add(button, 1, wx.EXPAND,5) boxbuttons.Add(space) button.SetToolTip(tooltips[i]) self.Bind(wx.EVT_BUTTON, callbacks[i], button) self.toolbar = boxbuttons
def create_toolbar(self): self.toolbar = wx.ToolBar(self.materials_panel, style=wx.TB_FLAT|wx.TB_HORIZONTAL) dpi_scale_factor=wx.GetDisplayPPI()[0]/96. tb_bmp_size=int(dpi_scale_factor*20) newid=wx.NewId() self.toolbar.AddTool(newid, label='Add', bitmap=wx.Bitmap(img.add.GetImage().Scale(tb_bmp_size,tb_bmp_size)), shortHelp='Add a material to the list') self.materials_panel.Bind(wx.EVT_TOOL, self.material_add, id=newid) newid=wx.NewId() self.toolbar.AddTool(newid, label='Delete', bitmap=wx.Bitmap(img.delete.GetImage().Scale(tb_bmp_size, tb_bmp_size)), shortHelp='Delete selected materials') self.materials_panel.Bind(wx.EVT_TOOL, self.material_delete, id=newid) newid=wx.NewId() self.toolbar.AddTool(newid, label='Apply', bitmap=wx.Bitmap(img.start_fit.GetImage().Scale(tb_bmp_size, tb_bmp_size)), shortHelp='New Layer/Apply to Layer') self.materials_panel.Bind(wx.EVT_TOOL, self.material_apply, id=newid) # self.sizer_hor=wx.BoxSizer(wx.HORIZONTAL) self.sizer_vert.Add(self.toolbar, proportion=0, flag=wx.EXPAND, border=2) self.toolbar.Realize()
def create_toolbar(self): dpi_scale_factor = wx.GetDisplayPPI()[0] / 96. tb_bmp_size = int(dpi_scale_factor * 20) size = wx.Size(tb_bmp_size, tb_bmp_size) self.bitmap_button_add = wx.BitmapButton( self.tool_panel, -1, wx.Bitmap(img.getaddImage().Scale(tb_bmp_size, tb_bmp_size)), size=size, style=wx.NO_BORDER) self.bitmap_button_add.SetToolTip('Add current parameters to Vault') self.bitmap_button_delete = wx.BitmapButton( self.tool_panel, -1, wx.Bitmap(img.getdeleteImage().Scale(tb_bmp_size, tb_bmp_size)), size=size, style=wx.NO_BORDER) self.bitmap_button_delete.SetToolTip('Delete selected parameter set') self.bitmap_button_apply = wx.BitmapButton( self.tool_panel, -1, wx.Bitmap(img.getstart_fitImage().Scale(tb_bmp_size, tb_bmp_size)), size=size, style=wx.NO_BORDER) self.bitmap_button_apply.SetToolTip( 'Apply selected parameter set to the model') self.bitmap_button_plot = wx.BitmapButton( self.tool_panel, -1, wx.Bitmap(img.getplottingImage().Scale(tb_bmp_size, tb_bmp_size)), size=size, style=wx.NO_BORDER) self.bitmap_button_plot.SetToolTip( 'Toggle plotting of the selected parameter set') space = (2, -1) self.sizer_hor = wx.BoxSizer(wx.HORIZONTAL) self.sizer_hor.Add(self.bitmap_button_add, proportion=0, border=2) self.sizer_hor.Add(space) self.sizer_hor.Add(self.bitmap_button_delete, proportion=0, border=2) self.sizer_hor.Add(space) self.sizer_hor.Add(self.bitmap_button_apply, proportion=0, border=2) self.sizer_hor.Add(space) self.sizer_hor.Add(self.bitmap_button_plot, proportion=0, border=2) self.parameter_panel.Bind(wx.EVT_BUTTON, self.parameter_list.AddItem, self.bitmap_button_add) self.parameter_panel.Bind(wx.EVT_BUTTON, self.parameter_list.DeleteItem, self.bitmap_button_delete) self.parameter_panel.Bind(wx.EVT_BUTTON, self.parameter_list.ApplyParameters, self.bitmap_button_apply) self.parameter_panel.Bind(wx.EVT_BUTTON, self.parameter_list.TogglePlot, self.bitmap_button_plot)
def __init__(self, url, icon, title, size): self.browser = None # Must ignore X11 errors like 'BadWindow' and others by # installing X11 error handlers. This must be done after # wx was intialized. if LINUX: cef.WindowUtils.InstallX11ErrorHandlers() global g_count_windows g_count_windows += 1 if WINDOWS: # noinspection PyUnresolvedReferences, PyArgumentList logging.debug("[wxpython.py] System DPI settings: %s" % str(cef.DpiAware.GetSystemDpi())) if hasattr(wx, "GetDisplayPPI"): logging.debug("[wxpython.py] wx.GetDisplayPPI = %s" % wx.GetDisplayPPI()) logging.debug("[wxpython.py] wx.GetDisplaySize = %s" % wx.GetDisplaySize()) logging.debug("[wxpython.py] MainFrame DPI scaled size: %s" % str(size)) wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, title=title) # wxPython will set a smaller size when it is bigger # than desktop size. logging.debug("[wxpython.py] MainFrame actual size: %s" % self.GetSize()) ic = wx.Icon(icon, wx.BITMAP_TYPE_ICO) self.SetIcon(ic) self.Bind(wx.EVT_CLOSE, self.OnClose) # Set wx.WANTS_CHARS style for the keyboard to work. # This style also needs to be set for all parent controls. self.browser_panel = wx.Panel(self, size=tuple(size)) self.browser_panel.Bind(wx.EVT_SIZE, self.OnSize) wx.Window.Fit(self) if MAC: # Make the content view for the window have a layer. # This will make all sub-views have layers. This is # necessary to ensure correct layer ordering of all # child views and their layers. This fixes Window # glitchiness during initial loading on Mac (Issue #371). NSApp.windows()[0].contentView().setWantsLayer_(True) if LINUX: self.Show() self.embed_browser(url) else: self.embed_browser(url) self.Show()
def __init__(self): self.browser = None # Must ignore X11 errors like 'BadWindow' and others by # installing X11 error handlers. This must be done after # wx was intialized. global g_count_windows g_count_windows += 1 print("[wxpython.py] System DPI settings: %s" % str(cef.DpiAware.GetSystemDpi())) if hasattr(wx, "GetDisplayPPI"): print("[wxpython.py] wx.GetDisplayPPI = %s" % wx.GetDisplayPPI()) print("[wxpython.py] wx.GetDisplaySize = %s" % wx.GetDisplaySize()) size = scale_window_size_for_high_dpi() print("[wxpython.py] MainFrame DPI scaled size: %s" % str(size)) wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, title=title, size=size) # wxPython will set a smaller size when it is bigger # than desktop size. print("[wxpython.py] MainFrame actual size: %s" % self.GetSize()) self.setup_icon() self.create_menu() self.Bind(wx.EVT_CLOSE, self.OnClose) # Set wx.WANTS_CHARS style for the keyboard to work. # This style also needs to be set for all parent controls. self.browser_panel = wx.Panel(self, style=wx.WANTS_CHARS) self.browser_panel.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self.browser_panel.Bind(wx.EVT_SIZE, self.OnSize) self.embed_browser() self.Show()
def do_toolbar(self, parent): """Create and return a toolbar that can be used to control the widget""" toolbar = wx.ToolBar(parent, style=wx.TB_FLAT | wx.TB_VERTICAL) dpi_scale_factor=wx.GetDisplayPPI()[0]/96. tb_bmp_size=int(dpi_scale_factor*20) button_names = ['View X', 'View Y', 'View Z', 'Isometric'] button_images = [sxrd_images.x, sxrd_images.y, sxrd_images.z, sxrd_images.isometric] callbacks = [self.OnViewX, self.OnViewY, self.OnViewZ, self.OnViewIsometric] tooltips = ['View along X', 'View along Y', 'View along Z', 'Isometric view'] for i in range(len(button_names)): new_id = wx.NewId() toolbar.AddTool(new_id, label=button_names[i], bitmap=wx.Bitmap(button_images[i].GetImage().Scale(tb_bmp_size, tb_bmp_size)), shortHelp=tooltips[i]) parent.Bind(wx.EVT_TOOL, callbacks[i], id=new_id) button_names = ['Select', 'Orbit', 'Zoom', 'Pan'] button_images = [sxrd_images.selection, sxrd_images.orbit, sxrd_images.zoom_small, sxrd_images.pan] callbacks = [self.OnChangeCursorState, self.OnChangeCursorState, self.OnChangeCursorState, self.OnChangeCursorState] tooltips = ['Object selection', 'Orbit', 'Zoom', 'Pan'] self.cursor_ids = [] for i in range(len(button_names)): new_id = wx.NewId() self.cursor_ids.append(new_id) #print button_images[i].GetBitmap() toolbar.AddCheckTool(new_id, button_names[i], wx.Bitmap(button_images[i].GetImage().Scale(tb_bmp_size, tb_bmp_size)), shortHelp=tooltips[i]) parent.Bind(wx.EVT_TOOL, callbacks[i], id=new_id) toolbar.ToggleTool(self.cursor_ids[1], True) self.toolbar = toolbar return toolbar
def __init__(self, parent, plugin): wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_EDIT_LABELS) ListCtrlAutoWidthMixin.__init__(self) self.plugin = plugin dpi_scale_factor = wx.GetDisplayPPI()[0] / 96. if sys.platform.startswith('win'): font = wx.Font(9, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, faceName="Lucida Sans Unicode") else: font = wx.Font(9, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, encoding=wx.FONTENCODING_UNICODE) self.SetFont(font) # Set list length self.SetItemCount(0) self.parameter_list = [] # Set the column headers for col, (text, width) in enumerate([ ("#", 24), ("FOM", 60), ("Show", 60), ("P1", 60), ("P2", 60), ]): self.InsertColumn(col, text, width=width)
def __init__(self): self.browser = None # Must ignore X11 errors like 'BadWindow' and others by # installing X11 error handlers. This must be done after # wx was intialized. if LINUX: cef.WindowUtils.InstallX11ErrorHandlers() global g_count_windows g_count_windows += 1 if WINDOWS: # noinspection PyUnresolvedReferences, PyArgumentList print("[wxpython.py] System DPI settings: %s" % str(cef.DpiAware.GetSystemDpi())) if hasattr(wx, "GetDisplayPPI"): print("[wxpython.py] wx.GetDisplayPPI = %s" % wx.GetDisplayPPI()) print("[wxpython.py] wx.GetDisplaySize = %s" % wx.GetDisplaySize()) print("[wxpython.py] MainFrame declared size: %s" % str( (WIDTH, HEIGHT))) size = scale_window_size_for_high_dpi(WIDTH, HEIGHT) print("[wxpython.py] MainFrame DPI scaled size: %s" % str(size)) wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, title='wxPython example', size=size) # wxPython will set a smaller size when it is bigger # than desktop size. print("[wxpython.py] MainFrame actual size: %s" % self.GetSize()) self.setup_icon() self.create_menu() self.Bind(wx.EVT_CLOSE, self.OnClose) # Set wx.WANTS_CHARS style for the keyboard to work. # This style also needs to be set for all parent controls. self.browser_panel = wx.Panel(self, style=wx.WANTS_CHARS) self.browser_panel.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self.browser_panel.Bind(wx.EVT_SIZE, self.OnSize) if MAC: # Make the content view for the window have a layer. # This will make all sub-views have layers. This is # necessary to ensure correct layer ordering of all # child views and their layers. This fixes Window # glitchiness during initial loading on Mac (Issue #371). NSApp.windows()[0].contentView().setWantsLayer_(True) if LINUX: # On Linux must show before embedding browser, so that handle # is available (Issue #347). self.Show() # In wxPython 3.0 and wxPython 4.0 on Linux handle is # still not yet available, so must delay embedding browser # (Issue #349). if wx.version().startswith("3.") or wx.version().startswith("4."): wx.CallLater(100, self.embed_browser) else: # This works fine in wxPython 2.8 on Linux self.embed_browser() else: self.embed_browser() self.Show()
def get_screen_dpi(): return wx.GetDisplayPPI()
def __init__(self): self.browser = None # begin wxGlade: MyFrame.__init__ if WINDOWS: # noinspection PyUnresolvedReferences, PyArgumentList print("[wxpython.py] System DPI settings: %s" % str(cef.DpiAware.GetSystemDpi())) if hasattr(wx, "GetDisplayPPI"): print("[wxpython.py] wx.GetDisplayPPI = %s" % wx.GetDisplayPPI()) print("[wxpython.py] wx.GetDisplaySize = %s" % wx.GetDisplaySize()) print("[wxpython.py] MainFrame declared size: %s" % str( (WIDTH, HEIGHT))) size = scale_window_size_for_high_dpi(WIDTH, HEIGHT) print("[wxpython.py] MainFrame DPI scaled size: %s" % str(size)) wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, size=size) print("[wxpython.py] MainFrame actual size: %s" % self.GetSize()) self.Bind(wx.EVT_CLOSE, self.OnClose) self.SetSize((1000, 500)) self.SetTitle("Mapomatic") self.panel_1 = wx.Panel(self, wx.ID_ANY) self.sizer_1 = wx.BoxSizer(wx.HORIZONTAL) sizer_2 = wx.BoxSizer(wx.VERTICAL) self.sizer_1.Add(sizer_2, 1, wx.EXPAND, 0) self.text_ctrl_search = wx.SearchCtrl(self.panel_1, wx.ID_ANY, "Nigh Center") self.text_ctrl_search.ShowCancelButton(True) sizer_2.Add(self.text_ctrl_search, 0, wx.ALL | wx.EXPAND, 2) self.radio_btn_WCA = wx.RadioButton(self.panel_1, wx.ID_ANY, "Wheel Chair Access") sizer_2.Add(self.radio_btn_WCA, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 1) self.button_Submit = wx.Button(self.panel_1, wx.ID_ANY, "Submit") sizer_2.Add(self.button_Submit, 0, wx.ALIGN_CENTER_HORIZONTAL, 0) self.browser_panel = wx.Panel(self, style=wx.WANTS_CHARS) self.browser_panel.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self.browser_panel.Bind(wx.EVT_SIZE, self.OnSize) self.panel_2 = wx.Panel(self.panel_1, wx.ID_ANY, style=wx.BORDER_SIMPLE) self.panel_2.SetMinSize((1000, 400)) self.sizer_1.Add(self.panel_2, 1, wx.EXPAND, 0) self.sizer_3 = wx.BoxSizer(wx.VERTICAL) self.sizer_3.Add(self.browser_panel, 1) self.panel_2.SetSizer(self.sizer_3) self.panel_1.SetSizer(self.sizer_1) self.embed_browser() self.Show()
def DisplayInfo(): pp = wx.GetDisplayPPI() size_pix = wx.GetDisplaySize() size_mm = wx.DisplaySizeMM() logger.info("---> Display Info: pixel size: {} mm: ~{} ? pp: {}".format( size_pix, size_mm, pp))
def __init__(self): # begin wxGlade: MyFrame.__init__ # startLocation ='' # endLocation='' self.wheelChair = False if WINDOWS: # noinspection PyUnresolvedReferences, PyArgumentList print("[wxpython.py] System DPI settings: %s" % str(cef.DpiAware.GetSystemDpi())) if hasattr(wx, "GetDisplayPPI"): print("[wxpython.py] wx.GetDisplayPPI = %s" % wx.GetDisplayPPI()) print("[wxpython.py] wx.GetDisplaySize = %s" % wx.GetDisplaySize()) print("[wxpython.py] MainFrame declared size: %s" % str( (WIDTH, HEIGHT))) size = scale_window_size_for_high_dpi(WIDTH, HEIGHT) print("[wxpython.py] MainFrame DPI scaled size: %s" % str(size)) wx.Frame.__init__(self, parent=None, id=wx.ID_ANY, size=size) print("[wxpython.py] MainFrame actual size: %s" % self.GetSize()) self.Bind(wx.EVT_CLOSE, self.OnClose) self.SetSize((1000, 500)) self.SetTitle("Mapomatic") self.panel_1 = wx.Panel(self, wx.ID_ANY) sizer_1 = wx.BoxSizer(wx.HORIZONTAL) sizer_2 = wx.BoxSizer(wx.VERTICAL) sizer_1.Add(sizer_2, 1, wx.EXPAND, 0) label_1 = wx.StaticText(self.panel_1, wx.ID_ANY, "Start Location") sizer_2.Add(label_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM | wx.TOP, 10) self.text_ctrl_ = wx.SearchCtrl(self.panel_1, style=wx.TE_PROCESS_ENTER) self.text_ctrl_.ShowCancelButton(True) self.text_ctrl_.AutoComplete(choices) self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.on_enter, self.text_ctrl_) sizer_2.Add(self.text_ctrl_, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM, 10) label_2 = wx.StaticText(self.panel_1, wx.ID_ANY, "End location\n") sizer_2.Add(label_2, 0, wx.ALIGN_CENTER_HORIZONTAL, 0) self.text_ctrl_2 = wx.SearchCtrl(self.panel_1, wx.ID_ANY, "") self.text_ctrl_2.ShowCancelButton(True) self.text_ctrl_2.AutoComplete(choices) self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.on_enter, self.text_ctrl_2) sizer_2.Add(self.text_ctrl_2, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM, 10) self.checkbox_1 = wx.CheckBox(self.panel_1, wx.ID_ANY, "Wheel Chair Access") sizer_2.Add(self.checkbox_1, 0, 0, 0) self.Bind(wx.EVT_CHECKBOX, self.on_checked, self.checkbox_1) self.button_Submit = wx.Button(self.panel_1, wx.ID_ANY, "Submit") self.Bind(wx.EVT_BUTTON, self.on_button_pressed, self.button_Submit) sizer_2.Add(self.button_Submit, 0, wx.ALIGN_CENTER_HORIZONTAL, 0) label_3 = wx.StaticText(self.panel_1, wx.ID_ANY, "Singular Building Search\n") sizer_2.Add(label_3, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.TOP, 11) self.text_ctrl__copy = wx.SearchCtrl(self.panel_1, wx.ID_ANY, "") self.text_ctrl__copy.ShowCancelButton(True) self.text_ctrl__copy.AutoComplete(choices) sizer_2.Add(self.text_ctrl__copy, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM, 10) self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.on_Search_Enter, self.text_ctrl__copy) self.browser_panel = wx.Panel(self.panel_1, wx.ID_ANY, style=wx.BORDER_SIMPLE) self.browser_panel.SetMinSize((1000, 400)) self.browser_panel.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self.browser_panel.Bind(wx.EVT_SIZE, self.OnSize) self.embed2() sizer_1.Add(self.browser_panel, 1, wx.EXPAND, 0) self.panel_1.SetSizer(sizer_1) self.Show() self.Layout()