Help needed drawing in toolbar
Hi, i am trying to draw inside the toolbar dc but nothing happens i moved drawing code at the begining, at the end but in both cases nothing happens, i must have missed something, i need help !
I even tried to draw inside my side_panel, but even there, impossible
I am new to wxPython (and python), if someone could help me it would be much appreciated!
here is my noob code :
I am trying to achieve this :
import wx
class MyFrame(wx.Frame):
def __init__(self):
super().__init__(None, title="My App", size=(800, 600))
# Create the toolbar
toolbar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER)
# Create the side menu panel on the left
side_panel = wx.Panel(self)
side_panel.SetBackgroundColour(toolbar.GetBackgroundColour()) # Set background color
# Create the preview pane on the right
preview_panel = wx.Panel(self)
preview_panel.SetBackgroundColour(wx.Colour(200, 200, 200)) # Set background color
# Create the main sizer for the frame
main_sizer = wx.BoxSizer(wx.HORIZONTAL)
# Add the side menu and preview panels to the main sizer
main_sizer.Add(side_panel, 1, wx.EXPAND)
main_sizer.Add(preview_panel, 2, wx.EXPAND)
new_icon = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR)
open_icon = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR)
toolbar.CreateSeparator()
toolbar.AddTool(wx.ID_NEW, "New", new_icon, "Create new file")
toolbar.AddTool(wx.ID_OPEN, "Open", open_icon, "Open existing file")
toolbar.AddControl(wx.StaticText(toolbar, label="Search: "))
search_field = wx.TextCtrl(toolbar)
toolbar.AddControl(search_field)
toolbar.Realize()
# Draw a custom separator line in the toolbar with corrected coordinates
dc = wx.ClientDC(toolbar)
dc.SetPen(wx.Pen(wx.Colour(255, 0, 0, 128), 5, wx.SOLID)) # Red color separator with thickness 5
# Draw a custom separator line aligned with the window control buttons and left side panel border
side_panel_width = side_panel.GetSize()[0] # Obtain the width of the side panel
toolbar_button_height = toolbar.GetToolBitmapSize().GetHeight() # Get the height of the toolbar buttons
# Calculate the separator line position to align with the extended border of the side panel
separator_x = side_panel_width
separator_y_start = toolbar_button_height # Start the separator line from the top of the toolbar buttons
separator_y_end = toolbar.GetSize()[1] # Draw the line up to the bottom of the toolbar
# Draw the separator line with corrected coordinates
dc.DrawLine((separator_x, separator_y_start), (separator_x, separator_y_end))
# Add the toolbar to the frame
self.SetToolBar(toolbar)
self.SetSizer(main_sizer)
app = wx.App()
frame = MyFrame()
frame.Show()
app.MainLoop()