def __init__(self): self.Text = 'Buttons' self.Size = Size(WIDTH, HEIGHT) ok = Button() PANEL_HEIGHT = ok.Height + PANEL_SPACE panel = Panel() panel.Height = PANEL_HEIGHT panel.Dock = DockStyle.Bottom panel.Parent = self x = ok.Width * 2 + BUTTONS_SPACE y = (PANEL_HEIGHT - ok.Height) / 2 ok.Text = "Ok" ok.Parent = panel ok.Location = Point(WIDTH-x, y) ok.Anchor = AnchorStyles.Right close = Button() x = close.Width close.Text = "Close" close.Parent = panel close.Location = Point(WIDTH-x-CLOSE_SPACE, y) close.Anchor = AnchorStyles.Right self.CenterToScreen()
def __init__(self): self.Text = 'Directories' self.Size = Size(400, 400) self.tv = TreeView() self.SuspendLayout() self.tv.Parent = self self.tv.Location = Point(10,10) self.tv.Size = Size(self.ClientSize.Width - 20, self.Height - 200) self.tv.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right self.tv.FullRowSelect = False self.tv.ShowLines = True self.tv.ShowPlusMinus = True self.tv.Scrollable = True self.tv.AfterSelect += self.AfterSelect expand = Button() expand.Parent = self expand.Location = Point(20, self.tv.Bottom + 20) expand.Text = 'Expand' expand.Anchor = AnchorStyles.Left | AnchorStyles.Top expand.Click += self.OnExpand expandAll = Button() expandAll.Parent = self expandAll.Location = Point(20, expand.Bottom + 5) expandAll.Text = 'Expand All' expandAll.Anchor = AnchorStyles.Left | AnchorStyles.Top expandAll.Click += self.OnExpandAll collapse = Button() collapse.Parent = self collapse.Location = Point(expandAll.Right + 5, expand.Top) collapse.Text = 'Collapse' collapse.Anchor = AnchorStyles.Left | AnchorStyles.Top collapse.Click += self.OnCollapse collapseAll = Button() collapseAll.Parent = self collapseAll.Location = Point(collapse.Left, collapse.Bottom + 5) collapseAll.Text = 'Collapse All' collapseAll.Anchor = AnchorStyles.Left | AnchorStyles.Top collapseAll.Click += self.OnCollapseAll self.sb = StatusBar() self.sb.Parent = self self.ShowDirectories(self.tv.Nodes, HOME_DIR) self.ResumeLayout() self.CenterToScreen()
def showBox(self): ''' set the remaining box controls and launch ''' self.buttonpanel = Panel() self.buttonpanel.Parent = self self.buttonpanel.Location = Point(0, self.panel.Bottom) self.buttonpanel.Size = Size(Fconfig.smwidth, 2 * Fconfig.unitline) self.buttonpanel.Dock = DockStyle.Bottom self.warning = Label() self.warning.Parent = self.buttonpanel self.warning.Location = Point(Fconfig.margin, 0) self.warning.Size = Size(Fconfig.smwidth, Fconfig.unitline) self.warning.Font = Font(Fconfig.basefont, Fconfig.sizefont, FontStyle.Bold) self.warning.ForeColor = Color.Coral self.warning.TextAlign = ContentAlignment.MiddleCenter okay = Button() okay.Parent = self.buttonpanel okay.Text = Fconfig.buttonOK okay.Location = Point(50, Fconfig.unitline) okay.Width = 140 okay.Click += self.onValidate okay.Anchor = AnchorStyles.Right cancel = Button() cancel.Text = Fconfig.buttonCANCEL cancel.Parent = self.buttonpanel cancel.Location = Point(okay.Right, Fconfig.unitline) cancel.Click += self.onCancel cancel.Anchor = AnchorStyles.Right self.Width = Fconfig.width self.Height = self.panel.Bottom + 105 self.CenterToScreen() ModeDBG.say('\npanel top :{0}, bottom :{1}'.format( self.panel.Top, self.panel.Bottom)) ModeDBG.say('\n\nPanel loaded with {0} items\n'.format( len(self.panelparams))) # Display the form try: if Application.MessageLoop: TaskDialog.Show('UserForm', 'Another window is running...') else: Application.Run(self) except: TaskDialog.Show('UserForm', 'Loading failed...')
def showBox(self): ''' set the remaining box controls and launch ''' self.buttonpanel = Panel() self.buttonpanel.Parent = self self.buttonpanel.Location = Point(0,self.panel.Bottom) self.buttonpanel.Size = Size(Fconfig.smwidth, 2* Fconfig.unitline) self.buttonpanel.Dock = DockStyle.Bottom self.warning = Label() self.warning.Parent = self.buttonpanel self.warning.Location = Point(Fconfig.margin, 0) self.warning.Size = Size(Fconfig.smwidth, Fconfig.unitline) self.warning.Font = Font(Fconfig.basefont, Fconfig.sizefont, FontStyle.Bold) self.warning.ForeColor = Color.Coral self.warning.TextAlign = ContentAlignment.MiddleCenter okay = Button() okay.Parent = self.buttonpanel okay.Text = Fconfig.buttonOK okay.Location = Point(50, Fconfig.unitline) okay.Width = 140 okay.Click += self.onValidate okay.Anchor = AnchorStyles.Right cancel = Button() cancel.Text = Fconfig.buttonCANCEL cancel.Parent = self.buttonpanel cancel.Location = Point(okay.Right, Fconfig.unitline) cancel.Click += self.onCancel cancel.Anchor = AnchorStyles.Right self.Width = Fconfig.width self.Height = self.panel.Bottom + 105 self.CenterToScreen() ModeDBG.say('\npanel top :{0}, bottom :{1}'.format( self.panel.Top, self.panel.Bottom)) ModeDBG.say('\n\nPanel loaded with {0} items\n'.format( len(self.panelparams))) # Display the form try: if Application.MessageLoop: TaskDialog.Show('UserForm', 'Another window is running...') else: Application.Run(self) except: TaskDialog.Show('UserForm','Loading failed...')
def __build_cancelbutton(self): ''' Builds and returns the cancel button for this form. ''' button = Button() button.Text="" # gets updated by the 'update' method def cancel(sender, args): button.Enabled = False self.Close() button.Click+=cancel button.Location = Point(78, 572) button.Size = Size(190, 23) button.Anchor = AnchorStyles.Bottom return button
def __init__(self): self.Text = 'Anchor' self.Size = Size(210, 210) btn1 = Button() btn1.Text = "Button" btn1.Parent = self btn1.Location = Point(30, 30) btn2 = Button() btn2.Text = "Button" btn2.Parent = self btn2.Location = Point(30, 80) btn2.Anchor = AnchorStyles.Right self.CenterToScreen()
def __init__(self): FORMheight = 250 FORMwidth = 400 self.Text = 'Whatsapp Import - Whatsapp messages loader' self.Height = FORMheight-50 self.Width = FORMwidth flowPanel = FlowLayoutPanel() flowPanel.AutoSize = True flowPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink self.Controls.Add(flowPanel) labelDir = Label() labelDir.Text = "Exported artifacts directory path:" labelDir.Top = 20 labelDir.Left = 10 labelDir.Width = 300 labelDir.Anchor = AnchorStyles.Top TextboxDir = TextBox() TextboxDir.Name = 'ImportDir' TextboxDir.Text = '\export'#[type directory]' TextboxDir.Top = 45 TextboxDir.Left = 10 TextboxDir.Width = 360 TextboxDir.Anchor = AnchorStyles.Top '''labelRegex = Label() labelRegex.Text = "Chat file's name regex:" labelRegex.Top = 75 labelRegex.Left = 10 labelRegex.Width = 300 labelRegex.Anchor = AnchorStyles.Top fileRegex = TextBox() fileRegex.Name = 'fileNameRegex' fileRegex.Text = '^Conversa\sdo\sWhatsApp\scom\s(.*)\.txt$' fileRegex.Top = 100 fileRegex.Left = 10 fileRegex.Width = 360 fileRegex.Anchor = AnchorStyles.Top''' '''SelectDirBtn = Button() SelectDirBtn.Text = 'Select dir.' SelectDirBtn.Width = 150 SelectDirBtn.Top = 80 SelectDirBtn.Left = 350 SelectDirBtn.UseVisualStyleBackColor = True SelectDirBtn.Anchor = AnchorStyles.Top SelectDirBtn.Click += self.onClick''' button = Button() button.Text = "Import" button.Width = 110 button.Top = 120 button.Left = (FORMwidth / 2) - 50 button.Anchor = AnchorStyles.Top button.Click += self.buttonPressed self.Controls.Add(labelDir) self.Controls.Add(TextboxDir) #self.Controls.Add(labelRegex) #self.Controls.Add(fileRegex) #self.Controls.Add(SelectDirBtn) self.Controls.Add(button)
def __init__(self): #the __init__ method inside a class is its constructor self.Text = "AU London" #text that appears in the GUI titlebar self.Icon = Icon.FromHandle( icon.GetHicon() ) #takes a bitmap image and converts to a file that can be used as a Icon for the titlebar self.BackColor = Color.FromArgb(255, 255, 255) self.WindowState = FormWindowState.Normal # set maximised minimised or normal size GUI self.CenterToScreen() # centres GUI to the middle of your screen self.BringToFront() #brings the GUI to the front of all opens windows. self.Topmost = True # true to display the GUI infront of any other active forms screenSize = Screen.GetWorkingArea( self ) #get the size of the computers main screen, as the form will scale differently to different sized screens self.Width = screenSize.Width / 4 #set the size of the form based on the size of the users screen. this helps to ensure consistant look across different res screens. self.Height = screenSize.Height / 4 uiWidth = self.DisplayRectangle.Width #get the size of the form to use to scale form elements uiHeight = self.DisplayRectangle.Height #self.FormBorderStyle = FormBorderStyle.FixedDialog # fixed dialog stops the user from adjusting the form size. Recomended disabling this when testing to see if elements are in the wrong place. self.userOutput = userOutputDefaultStr #create a container to store the output from the form self.runNextOutput = False #set these default values #############-------------\-------------############# spacing = 10 #spacing size for GUI elements to form a consistent border # creates the text box for a info message userMessage = Label() #label displays texts font = Font("Helvetica ", 10) userMessage.Text = message userMessage.Font = font userMessage.Location = Point( spacing, spacing ) #all location require a point object from system.Drawing to set the location. userMessage.Size = Size( uiWidth - (spacing * 2), (uiHeight / 4) ) #size the control with the width of the GUI to ensure it scales with different screen self.Controls.Add(userMessage) #this adds control element to the GUI #############-------------\-------------############# #logo file logo = PictureBox() logo.Image = logoFile ratio = float(logo.Height) / float( logo.Width ) #needs to be a float as int will round to the nearest whole number logo.Size = Size( uiWidth / 4, (uiHeight / 4) * ratio ) #scale the image by the ratio between the images height & width logo.Location = Point(spacing, (uiHeight - logo.Height) - spacing) logo.SizeMode = PictureBoxSizeMode.Zoom # zooms the image to fit the extent logo.Anchor = ( AnchorStyles.Bottom | AnchorStyles.Left ) #anchor styles lock elements to a given corner of the GUI if you allow users change size self.Controls.Add(logo) #logo.BorderStyle = BorderStyle.Fixed3D #gives a border to the panel to test its location #############-------------\-------------############# #combox drop down cBox = ComboBox() #dropdown control form cBox.Location = Point(spacing, uiHeight / 3) cBox.Width = uiWidth - (spacing * 2) cBox.Items.AddRange( listInput ) # Adds an array of items to the list of items for a ComboBox. cBox.DropDownStyle = ComboBoxStyle.DropDownList #setting to dropdown list prevents users from being able to add aditional text values cBox.SelectedIndexChanged += self.dropDownOutput #.Click+= registers the press of the button to register the event handler and determine what action takes place when button clicked self.Controls.Add(cBox) #############-------------\-------------############# #Create ok button btnOk = Button() #create a button control btnOk.Text = "Next" btnOk.Location = Point(uiWidth - ((btnOk.Width * 2) + spacing), uiHeight - (btnOk.Height + spacing)) btnOk.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right) btnOk.Click += self.okButtonPressed #Register the event on the button bress to trigger the def okButtonPressed self.Controls.Add(btnOk) #Create Cancel Button btnCancel = Button() #btnCancel.Parent = self btnCancel.Text = "Cancel" btnCancel.Location = Point(uiWidth - (btnOk.Width + spacing), uiHeight - (btnOk.Height + spacing)) btnCancel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right) btnCancel.Click += self.CnlButtonPressed self.Controls.Add(btnCancel)
def __init__(self): self.Text = 'Player' self.Size = Size(350, 280) mainMenu = MainMenu() filem = mainMenu.MenuItems.Add("&File") playm = mainMenu.MenuItems.Add("&Play") view = mainMenu.MenuItems.Add("&View") tools = mainMenu.MenuItems.Add("&Tools") favourites = mainMenu.MenuItems.Add("&Favourites") help = mainMenu.MenuItems.Add("&Help") filem.MenuItems.Add(MenuItem("E&xit", self.OnExit, Shortcut.CtrlX)) self.Menu = mainMenu panel = Panel() panel.Parent = self panel.BackColor = Color.Black panel.Dock = DockStyle.Fill buttonPanel = Panel() buttonPanel.Parent = self buttonPanel.Height = 40 buttonPanel.Dock = DockStyle.Bottom pause = Button() pause.FlatStyle = FlatStyle.Popup pause.Parent = buttonPanel pause.Location = Point(5, 10) pause.Size = Size(25, 25) pause.Image = Bitmap("pause.png") play = Button() play.FlatStyle = FlatStyle.Popup play.Parent = buttonPanel play.Location = Point(35, 10) play.Size = Size(25, 25) play.Image = Bitmap("play.png") forward = Button() forward.FlatStyle = FlatStyle.Popup forward.Parent = buttonPanel forward.Location = Point(80, 10) forward.Size = Size(25, 25) forward.Image = Bitmap("forward.png") backward = Button() backward.FlatStyle = FlatStyle.Popup backward.Parent = buttonPanel backward.Location = Point(110, 10) backward.Size = Size(25, 25) backward.Image = Bitmap("backward.png") tb = TrackBar() tb.Parent = buttonPanel tb.TickStyle = TickStyle.None tb.Size = Size(150, 25) tb.Location = Point(200, 10) tb.Anchor = AnchorStyles.Right audio = Button() audio.FlatStyle = FlatStyle.Popup audio.Parent = buttonPanel audio.Size = Size(25, 25) audio.Image = Bitmap("audio.png") audio.Location = Point(170, 10) audio.Anchor = AnchorStyles.Right sb = StatusBar() sb.Parent = self sb.Text = "Ready" self.CenterToScreen()