def __init__(self, vw, color, can_delete): self.vw = vw panel = vw.panel self.chooser = wx.Choice(panel) self.color_ctrl = ColourSelect(panel, colour=color) self.show_check = wx.CheckBox(panel) bitmap = wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_TOOLBAR, (16, 16)) self.remove_button = wx.BitmapButton(panel, bitmap=bitmap) if not can_delete: self.remove_button.Hide() self.chooser.Bind(wx.EVT_CHOICE, self.on_choice) self.color_ctrl.Bind(EVT_COLOURSELECT, self.on_color_change) self.show_check.Bind(wx.EVT_CHECKBOX, self.on_check_change) self.update_chooser(first=True)
def add_row(self, rows, grid_sizer, names, can_delete): row = len(rows) + 1 controls = [] panel = self.panel chooser = wx.Choice(panel, choices = names) grid_sizer.Add(chooser, (row, self.C_CHOOSER), flag = wx.EXPAND) controls.append(chooser) chooser.Bind(wx.EVT_CHOICE, self.redraw) color = ColourSelect( panel, colour = wx.RED if row == 1 else wx.GREEN if row == 2 \ else wx.BLUE if row == 3 else wx.WHITE) color.Bind(EVT_COLOURSELECT, self.redraw) controls.append(color) grid_sizer.Add(color, (row, self.C_COLOR), flag = wx.EXPAND) show_check = wx.CheckBox(panel) show_check.SetValue(True) grid_sizer.Add(show_check, (row, self.C_SHOW), flag = wx.ALIGN_CENTER) show_check.Bind(wx.EVT_CHECKBOX, self.redraw) controls.append(show_check) bitmap = wx.ArtProvider.GetBitmap( wx.ART_DELETE, wx.ART_TOOLBAR, (16, 16)) remove_button = wx.BitmapButton(panel, bitmap = bitmap) grid_sizer.Add(remove_button, (row, self.C_REMOVE), flag = wx.ALIGN_CENTER) remove_button.Bind( wx.EVT_BUTTON, lambda event: self.remove_row(rows, grid_sizer, remove_button)) if not can_delete: remove_button.Hide() controls.append(remove_button) rows.append(controls) self.layout()
def createColorGrid(self, parent, buttonSize):#1 创建颜色网格 self.colorMap = {} self.colorButtons = {} colorGrid = wx.GridSizer(cols=self.NUM_COLS, hgap=2, vgap=2) for eachColor in self.colorList: bmp = ColourSelect(self, colour = eachColor).MakeBitmap() b = buttons.GenBitmapToggleButton(self, -1, bmp, size=buttonSize) b.SetBezelWidth(1) b.SetUseFocusIndicator(False) self.Bind(wx.EVT_BUTTON, self.OnSetColour, b) colorGrid.Add(b, 0) self.colorMap[b.GetId()] = eachColor self.colorButtons[eachColor] = b self.colorButtons[self.colorList[0]].SetToggle(True) return colorGrid
def __init__(self, parent, log): self.log = log wx.Panel.__init__(self, parent, wx.ID_ANY, style=wx.CLIP_CHILDREN) ## self.SetDoubleBuffered(True) self.background = wx.Brush(wx.WHITE) self.SetBackgroundColour(wx.RED) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) self.Bind(wx.EVT_SIZE, self.OnSize) #--Rubberband Overlay self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) self.Bind(wx.EVT_MOTION, self.OnMouseMove) self.dock_handler = DockingRectangleHandler() self.overlayPenWidth = wx.SpinCtrl(self, -1, value='', size=(75, -1), style=wx.SP_ARROW_KEYS, min=1, max=24, initial=1) # self.overlayPenWidth.SetToolTip('Pen Width') from wx.lib.colourselect import ColourSelect self.overlayPenColor = ColourSelect(self, -1, colour=wx.BLUE) # self.overlayPenColor.SetToolTip('Pen Color') sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.overlayPenWidth, 0, wx.ALL, 5) sizer.Add(self.overlayPenColor, 0, wx.ALL, 5) box = wx.BoxSizer(wx.VERTICAL) box.Add(sizer, 0) box.Add((1, 1), 1) self.SetSizer(box) self.OnSize()
def on_choose_font(self, event): with wx.Dialog(self.choice_panel.Parent, title="Measurement appearance") as dlg: labels = [] def add_label(sizer, label): ctrl = wx.StaticText(dlg, label=label) sizer.Add(ctrl, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL) labels.append(ctrl) sizer.AddSpacer(2) dlg.Sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL) dlg.Sizer.Add(sizer, 0, wx.EXPAND | wx.ALL, 5) subsizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(subsizer, 0, wx.EXPAND) sizer.AddSpacer(2) add_label(subsizer, "Font") font_picker = wx.FontPickerCtrl(dlg) font_picker.SetSelectedFont(self.font) font_picker.SetPickerCtrlGrowable(True) font_picker.Bind(wx.EVT_FONTPICKER_CHANGED, lambda event: dlg.Layout()) subsizer.Add(font_picker, 0, wx.ALIGN_LEFT) # # Foreground color # subsizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(subsizer, 0, wx.EXPAND) sizer.AddSpacer(2) add_label(subsizer, "Text color") foreground_color = ColourSelect(dlg, colour=self.foreground_color) subsizer.Add(foreground_color, 0, wx.ALIGN_LEFT) # # Background color and alpha # subsizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(subsizer, 0, wx.EXPAND) sizer.AddSpacer(2) add_label(subsizer, "Background color") background_color = ColourSelect(dlg, colour=self.background_color) subsizer.Add(background_color, 0, wx.ALIGN_LEFT) subsizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(subsizer, 0, wx.EXPAND) sizer.AddSpacer(2) add_label(subsizer, "Alpha") alpha = wx.Slider(dlg, value=self.background_alpha * 100, minValue=0, maxValue=100, style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS) alpha.SetMinSize(wx.Size(200, alpha.GetMinSize()[0])) subsizer.Add(alpha, 0, wx.EXPAND) subsizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(subsizer, 0, wx.EXPAND) sizer.AddSpacer(2) add_label(subsizer, "Box shape") box_style = wx.Choice(dlg, choices=[ "circle", "round", "roundtooth", "sawtooth", "square" ]) box_style.SetStringSelection(self.box_style) subsizer.Add(box_style, 0, wx.ALIGN_LEFT) subsizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(subsizer, 0, wx.EXPAND) sizer.AddSpacer(2) add_label(subsizer, "Precision") precision = wx.SpinCtrl(dlg, value=str(self.precision), min=0) subsizer.AddSpacer(2) subsizer.Add(precision, 0, wx.ALIGN_LEFT) width = 0 for label in labels: width = max(width, label.GetBestSize()[0]) for label in labels: label.SetMinSize(wx.Size(width, label.GetBestSize()[1])) button_sizer = wx.StdDialogButtonSizer() dlg.Sizer.Add(button_sizer, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5) button_sizer.AddButton(wx.Button(dlg, wx.ID_OK)) button_sizer.AddButton(wx.Button(dlg, wx.ID_CANCEL)) button_sizer.Realize() dlg.Fit() if dlg.ShowModal() == wx.ID_OK: self.font = font_picker.GetSelectedFont() self.foreground_color = foreground_color.GetColour() self.background_color = background_color.GetColour() self.background_alpha = float(alpha.Value) / 100 self.box_style = box_style.GetStringSelection() self.precision = precision.Value self.on_change(event)
class VWRow(object): '''A row of controls and a data item''' def __init__(self, vw, color, can_delete): self.vw = vw panel = vw.panel self.chooser = wx.Choice(panel) self.color_ctrl = ColourSelect(panel, colour=color) self.show_check = wx.CheckBox(panel) bitmap = wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_TOOLBAR, (16, 16)) self.remove_button = wx.BitmapButton(panel, bitmap=bitmap) if not can_delete: self.remove_button.Hide() self.chooser.Bind(wx.EVT_CHOICE, self.on_choice) self.color_ctrl.Bind(EVT_COLOURSELECT, self.on_color_change) self.show_check.Bind(wx.EVT_CHECKBOX, self.on_check_change) self.update_chooser(first=True) @property def color(self): '''The color control's current color scaled for matplotlib''' return tuple([float(x) / 255 for x in self.color_ctrl.GetColour()]) def on_choice(self, event): self.data.name = self.chooser.GetStringSelection() self.vw.redraw() def on_color_change(self, event): self.data.color = tuple( [float(c) / 255. for c in self.color_ctrl.GetColour()]) self.vw.redraw() def on_check_change(self, event): self.vw.redraw() def update(self): name = self.chooser.GetStringSelection() names = sorted(self.get_names()) image_set = self.vw.workspace.image_set if self.show_check.IsChecked() and name in names: self.data.name = name self.update_data(name) if self.data.mode == MODE_HIDE: self.data.mode = self.last_mode elif self.data.mode != MODE_HIDE: self.last_mode = self.data.get_raw_mode() self.data.mode = MODE_HIDE self.update_chooser() def update_chooser(self, first=False): '''Update the chooser with the given list of names''' name = self.chooser.GetStringSelection() names = self.get_names() current_names = sorted(self.chooser.GetItems()) if tuple(current_names) != tuple(names): if name not in names: names = sorted(list(names) + [name]) self.chooser.SetItems(names) self.chooser.SetStringSelection(name) if first and len(names) > 0: name = names[0] self.chooser.SetStringSelection(name)
def __init__(self, parent): wx.Panel.__init__(self, parent) self.parent = parent self.panel = self.parent.parent.panel self.canvas = self.panel.canvas self.islabel = self.parent.parent.islabel self.objets = parent.objets self.sizer = wx.BoxSizer(wx.VERTICAL) self.changements = { } # ce dictionnaire contiendra tous les styles modifiés encadre = wx.StaticBoxSizer( wx.StaticBox(self, -1, u"Mode d'affichage"), wx.HORIZONTAL) if not self.islabel: objets = [ objet for objet in self.objets if objet.style("fixe") is not None ] if objets: cb1 = wx.CheckBox(self, -1, u"Objet fixe", style=wx.CHK_3STATE) cb1.Bind(wx.EVT_CHECKBOX, self.EvtFixe) encadre.Add(cb1, 0, wx.ALL, 5) fixe = [objet.style("fixe") is True for objet in objets] if not any(fixe): etat = wx.CHK_UNCHECKED elif all(fixe): etat = wx.CHK_CHECKED else: etat = wx.CHK_UNDETERMINED cb1.Set3StateValue(etat) objets = [ objet for objet in self.objets if objet.style("visible") is not None ] if objets: cb2 = wx.CheckBox(self, -1, u"Objet visible", style=wx.CHK_3STATE) cb2.Bind(wx.EVT_CHECKBOX, self.EvtVisible) encadre.Add(cb2, 0, wx.ALL, 5) visible = [objet.style("visible") is True for objet in objets] if not any(visible): etat = wx.CHK_UNCHECKED elif all(visible): etat = wx.CHK_CHECKED else: etat = wx.CHK_UNDETERMINED cb2.Set3StateValue(etat) objets = [ objet for objet in self.objets if objet.style("trace") is not None ] if objets: cb3 = wx.CheckBox(self, -1, u"Laisser une trace", style=wx.CHK_3STATE) cb3.Bind(wx.EVT_CHECKBOX, self.EvtTrace) encadre.Add(cb3, 0, wx.ALL, 5) trace = [objet.style("trace") is True for objet in objets] if not any(trace): etat = wx.CHK_UNCHECKED elif all(trace): etat = wx.CHK_CHECKED else: etat = wx.CHK_UNDETERMINED cb3.Set3StateValue(etat) encadre1 = wx.StaticBoxSizer(wx.StaticBox(self, -1, u"Etiquette"), wx.VERTICAL) if not self.islabel: ligne = wx.BoxSizer(wx.HORIZONTAL) if len(self.objets) == 1: etiquette = wx.TextCtrl(self, value=self.objets[0].style("label"), size=wx.Size(200, -1)) self.Bind(wx.EVT_TEXT, self.EvtEtiquette, etiquette) ligne.Add(etiquette, 0, wx.ALL, 5) if [objet for objet in self.objets if objet.etiquette is not None]: editer = wx.Button(self, label=u"Style") editer.Bind(wx.EVT_BUTTON, self.EvtLabelStyle) ligne.Add(editer, 0, wx.ALL, 5) encadre1.Add(ligne, 0, wx.ALL, 5) objets = [ objet for objet in self.objets if objet.style("legende") is not None ] if objets: leg = objets[0].style("legende") legende = wx.BoxSizer(wx.HORIZONTAL) self.radio_nom = wx.RadioButton(self, -1, "Nom", style=wx.RB_GROUP) self.radio_nom.SetValue(0) self.radio_etiquette = wx.RadioButton(self, -1, u"Texte") self.radio_etiquette.SetValue(0) self.radio_formule = wx.RadioButton(self, -1, u"Formule") self.radio_formule.SetValue(0) self.radio_aucun = wx.RadioButton(self, -1, u"Aucun") self.radio_aucun.SetValue(0) if all(objet.style("legende") == leg for objet in objets): if leg == NOM: self.radio_nom.SetValue(1) elif leg == TEXTE: self.radio_etiquette.SetValue(1) elif leg == FORMULE: self.radio_formule.SetValue(1) elif leg == RIEN: self.radio_aucun.SetValue(1) self.Bind(wx.EVT_RADIOBUTTON, self.EvtLegende, self.radio_nom) self.Bind(wx.EVT_RADIOBUTTON, self.EvtLegende, self.radio_etiquette) self.Bind(wx.EVT_RADIOBUTTON, self.EvtLegende, self.radio_formule) self.Bind(wx.EVT_RADIOBUTTON, self.EvtLegende, self.radio_aucun) legende.Add(self.radio_nom, 0, wx.ALL, 5) legende.Add(self.radio_etiquette, 0, wx.ALL, 5) legende.Add(self.radio_formule, 0, wx.ALL, 5) legende.Add(self.radio_aucun, 0, wx.ALL, 5) encadre1.Add(wx.StaticText(self, -1, u"Afficher : "), 0, wx.ALL, 5) encadre1.Add(legende, 0, wx.ALL, 5) encadre2 = wx.StaticBoxSizer(wx.StaticBox(self, -1, u"Styles"), wx.VERTICAL) objets = [ objet for objet in self.objets if objet.style("style") is not None ] # on ne peut regler les styles simultanement que pour des objets de meme categorie categorie = objets and objets[0].style("categorie") or None if objets and categorie and all( objet.style("categorie") == categorie for objet in objets): choix = wx.BoxSizer(wx.HORIZONTAL) choix.Add(wx.StaticText(self, -1, u"Style de l'objet : "), 0, wx.ALL, 5) #categorie = objets[0].style("categorie") or "lignes" self.liste_styles = getattr(param, "styles_de_" + categorie, []) self.style = wx.Choice(self, -1, (100, 50), choices=self.liste_styles) self.Bind(wx.EVT_CHOICE, self.EvtStyle, self.style) style = objets[0].style("style") if style in self.liste_styles and all( objet.style("style") == style for objet in objets): self.style.SetSelection(self.liste_styles.index( style)) # on sélectionne le style actuel choix.Add(self.style, 0, wx.ALL, 5) encadre2.Add(choix, 0, wx.ALL, 5) objets = [ objet for objet in self.objets if objet.style("hachures") is not None ] if objets: choix = wx.BoxSizer(wx.HORIZONTAL) choix.Add(wx.StaticText(self, -1, u"Style des hâchures : "), 0, wx.ALL, 5) self.types_de_hachures = getattr(param, "types_de_hachures", []) self.hachures = wx.Choice(self, -1, (100, 50), choices=self.types_de_hachures) self.Bind(wx.EVT_CHOICE, self.EvtHachures, self.hachures) hachures = objets[0].style("hachures") if hachures in self.types_de_hachures and all( objet.style("hachures") == hachures for objet in objets): self.hachures.SetSelection( self.types_de_hachures.index( hachures)) # on sélectionne les hachures actuelles choix.Add(self.hachures, 0, wx.ALL, 5) encadre2.Add(choix, 0, wx.ALL, 5) objets = [ objet for objet in self.objets if objet.style("famille") is not None ] categorie = objets and objets[0].style("categorie") or None if objets and categorie and all( objet.style("categorie") == categorie for objet in objets): choix = wx.BoxSizer(wx.HORIZONTAL) choix.Add(wx.StaticText(self, -1, "Police : "), 0, wx.ALL, 5) #categorie = self.objet.style("categorie") or "lignes" self.liste_familles = getattr(param, "familles_de_" + categorie, []) self.famille = wx.Choice(self, -1, (100, 50), choices=self.liste_familles) self.Bind(wx.EVT_CHOICE, self.EvtFamille, self.famille) famille = objets[0].style("famille") if famille in self.liste_familles and all( objet.style("famille") == famille for objet in objets): self.famille.SetSelection(self.liste_familles.index( famille)) # on sélectionne la famille actuelle choix.Add(self.famille, 0, wx.ALL, 5) encadre2.Add(choix, 0, wx.ALL, 5) objets = [ objet for objet in self.objets if objet.style("couleur") is not None ] if objets: couleur = objets[0].style("couleur") choix = wx.BoxSizer(wx.HORIZONTAL) choix.Add(wx.StaticText(self, -1, u"Couleur de l'objet : "), 0, wx.ALL, 5) if all(objet.style("couleur") == couleur for objet in objets): couleur = colorConverter.to_rgb(couleur) couleur = tuple( int(255 * i) for i in couleur) # conversion du format matplotlib au format wx else: couleur = self.GetBackgroundColour() b = ColourSelect(self, -1, colour=couleur) b.Bind(EVT_COLOURSELECT, self.OnSelectColour) choix.Add(b, 0, wx.ALL, 5) encadre2.Add(choix, 0, wx.ALL, 5) objets = [ objet for objet in self.objets if objet.style("epaisseur") is not None ] if objets: epaiss = objets[0].style("epaisseur") epaisseur = wx.BoxSizer(wx.HORIZONTAL) epaisseur.Add( wx.StaticText(self, -1, u"Epaisseur (en 10e de pixels) : "), 0, wx.ALL, 5) self.epaisseur = wx.SpinCtrl(self, -1, "", (30, 50)) self.epaisseur.SetRange(1, 10000) if all(objet.style("epaisseur") == epaiss for objet in objets): self.epaisseur.SetValue(10 * epaiss) else: self.epaisseur.SetValueString("") self.Bind(wx.EVT_TEXT, self.EvtEpaisseur, self.epaisseur) epaisseur.Add(self.epaisseur, 0, wx.ALL, 5) encadre2.Add(epaisseur, 0, wx.ALL, 5) objets = [ objet for objet in self.objets if objet.style("taille") is not None ] if objets: tail = objets[0].style("taille") taille = wx.BoxSizer(wx.HORIZONTAL) taille.Add( wx.StaticText(self, -1, u"Taille (en 10e de pixels) : "), 0, wx.ALL, 5) self.taille = wx.SpinCtrl(self, -1, "", (30, 50)) self.taille.SetRange(1, 10000) if all(objet.style("taille") == tail for objet in objets): self.taille.SetValue(10 * tail) else: self.taille.SetValueString("") self.Bind(wx.EVT_TEXT, self.EvtTaille, self.taille) taille.Add(self.taille, 0, wx.ALL, 5) encadre2.Add(taille, 0, wx.ALL, 5) objets = [ objet for objet in self.objets if objet.style("position") is not None ] if objets: pos = objets[0].style("position") position = wx.BoxSizer(wx.HORIZONTAL) position.Add(wx.StaticText(self, -1, u"Position de la flêche : "), 0, wx.ALL, 5) self.position = wx.SpinCtrl(self, -1, "", (30, 50)) self.position.SetRange(0, 100) if all(objet.style("position") == pos for objet in objets): self.position.SetValue(100 * pos) else: self.position.SetValueString("") self.Bind(wx.EVT_TEXT, self.EvtPosition, self.position) position.Add(self.position, 0, wx.ALL, 5) encadre2.Add(position, 0, wx.ALL, 5) objets = [ objet for objet in self.objets if objet.style("angle") is not None ] if objets: ang = objets[0].style("angle") angle = wx.BoxSizer(wx.HORIZONTAL) angle.Add(wx.StaticText(self, -1, u"Angle (en degré) : "), 0, wx.ALL, 5) self.angle = wx.SpinCtrl(self, -1, "", (30, 50)) self.angle.SetRange(0, 360) if all(objet.style("angle") == ang for objet in objets): self.angle.SetValue(ang) else: self.angle.SetValueString("") self.Bind(wx.EVT_TEXT, self.EvtAngle, self.angle) angle.Add(self.angle, 0, wx.ALL, 5) encadre2.Add(angle, 0, wx.ALL, 5) objets = [ objet for objet in self.objets if objet.style("double_fleche") is not None ] if objets: cb4 = wx.CheckBox(self, -1, u"Flêche double", style=wx.CHK_3STATE) cb4.Bind(wx.EVT_CHECKBOX, self.EvtFlecheDouble) encadre.Add(cb4, 0, wx.ALL, 5) double = [objet.style("double_fleche") is True for objet in objets] if not any(double): etat = wx.CHK_UNCHECKED elif all(double): etat = wx.CHK_CHECKED else: etat = wx.CHK_UNDETERMINED cb4.Set3StateValue(etat) objets = [ objet for objet in self.objets if objet.style("codage") is not None ] # on ne peut regler les codages simultanement que pour des objets de meme categorie categorie = objets and objets[0].style("categorie") or None if objets and categorie and all( objet.style("categorie") == categorie for objet in objets): choix = wx.BoxSizer(wx.HORIZONTAL) choix.Add(wx.StaticText(self, -1, "Codage : "), 0, wx.ALL, 5) #categorie = objets[0].style("categorie") or "lignes" self.liste_codages = getattr(param, "codage_des_" + categorie, []) self.codage = wx.Choice(self, -1, (100, 50), choices=self.liste_codages) self.Bind(wx.EVT_CHOICE, self.EvtCodage, self.codage) codage = objets[0].style("codage") if codage in self.liste_codages and all( objet.style("codage") == codage for objet in objets): self.codage.SetSelection(self.liste_codages.index( codage)) # on sélectionne le codage actuel choix.Add(self.codage, 0, wx.ALL, 5) encadre2.Add(choix, 0, wx.ALL, 5) boutons = wx.BoxSizer(wx.HORIZONTAL) ok = wx.Button(self, wx.ID_OK) ok.Bind(wx.EVT_BUTTON, self.EvtOk) boutons.Add(ok, 0, wx.ALL, 5) appliquer = wx.Button(self, label=u"Appliquer") appliquer.Bind(wx.EVT_BUTTON, self.EvtAppliquer) boutons.Add(appliquer, 0, wx.ALL, 5) if not self.islabel: supprimer = wx.Button(self, label=u"Supprimer") supprimer.Bind(wx.EVT_BUTTON, self.EvtSupprimer) boutons.Add(supprimer, 0, wx.ALL, 5) annuler = wx.Button(self, label=u"Annuler") annuler.Bind(wx.EVT_BUTTON, self.EvtAnnuler) boutons.Add(annuler, 0, wx.ALL, 5) if encadre.GetChildren(): # ne pas afficher un cadre vide ! self.sizer.Add(encadre, 0, wx.ALL, 5) else: encadre.GetStaticBox().Destroy() if encadre1.GetChildren(): self.sizer.Add(encadre1, 0, wx.ALL, 5) else: encadre1.GetStaticBox().Destroy() if encadre2.GetChildren(): self.sizer.Add(encadre2, 0, wx.ALL, 5) else: encadre2.GetStaticBox().Destroy() self.sizer.Add(boutons, 0, wx.ALL, 5) self.SetSizerAndFit(self.sizer) self.parent.parent.dim1 = self.sizer.CalcMin().Get()
class TestPanel(wx.Panel): def __init__(self, parent, log): self.log = log wx.Panel.__init__(self, parent, wx.ID_ANY, style=wx.CLIP_CHILDREN) ## self.SetDoubleBuffered(True) self.background = wx.Brush(self.GetBackgroundColour()) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) #--Rubberband Overlay self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) self.Bind(wx.EVT_MOTION, self.OnMouseMove) self.startPos = None self.endPos = None self.overlay = wx.Overlay() self.cropbitmap = wx.Bitmap('bitmaps/cropshot24x20.png') self.honeyBitmap = wx.Bitmap('bitmaps/honeycomb300.png') self.wxPenStylesDict = OrderedDict([ ('Solid', wx.PENSTYLE_SOLID), ('Dot', wx.PENSTYLE_DOT), ('Long Dash', wx.PENSTYLE_LONG_DASH), ('Short Dash', wx.PENSTYLE_SHORT_DASH), ('Dot Dash', wx.PENSTYLE_DOT_DASH), ('User Dash', wx.PENSTYLE_USER_DASH), ('Transparent', wx.PENSTYLE_TRANSPARENT), #('Stipple' , wx.PENSTYLE_STIPPLE), ('BDiagonal Hatch', wx.PENSTYLE_BDIAGONAL_HATCH), ('CrossDiag Hatch', wx.PENSTYLE_CROSSDIAG_HATCH), ('FDiagonal Hatch', wx.PENSTYLE_FDIAGONAL_HATCH), ('Cross Hatch', wx.PENSTYLE_CROSS_HATCH), ('Horizontal Hatch', wx.PENSTYLE_HORIZONTAL_HATCH), ('Vertical Hatch', wx.PENSTYLE_VERTICAL_HATCH), ]) list = [] for key, value in self.wxPenStylesDict.items(): list.append(key) self.penstylesCombo = wx.ComboBox(self, -1, choices=list, size=(150, -1), style=wx.CB_READONLY) self.penstylesCombo.SetSelection(0) self.penstylesCombo.SetToolTip('Pen Style') self.overlayPenWidth = wx.SpinCtrl(self, -1, value='', size=(75, -1), style=wx.SP_ARROW_KEYS, min=1, max=24, initial=1) self.overlayPenWidth.SetToolTip('Pen Width') from wx.lib.colourselect import ColourSelect self.overlayPenColor = ColourSelect(self, -1, colour=wx.BLUE) self.overlayPenColor.SetToolTip('Pen Color') sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.penstylesCombo, 0, wx.ALL, 5) sizer.Add(self.overlayPenWidth, 0, wx.ALL, 5) sizer.Add(self.overlayPenColor, 0, wx.ALL, 5) box = wx.BoxSizer(wx.VERTICAL) box.Add(sizer, 0) box.Add((1, 1), 1) self.SetSizer(box) self.OnSize() def OnLeftDown(self, event): # Capture the mouse and save the starting posiiton for the rubber-band self.CaptureMouse() self.startPos = event.GetPosition() ## print('self.startPos:', self.startPos) self.SetFocus() ## print('OnLeftDown') def OnMouseMove(self, event): if event.Dragging() and event.LeftIsDown(): evtPos = event.GetPosition() try: rect = wx.Rect(topLeft=self.startPos, bottomRight=evtPos) except TypeError as exc: # topLeft = NoneType. Attempting to double click image or something return except Exception as exc: raise exc # Draw the rubber-band rectangle using an overlay so it # will manage keeping the rectangle and the former window # contents separate. dc = wx.ClientDC(self) odc = wx.DCOverlay(self.overlay, dc) odc.Clear() # Mac's DC is already the same as a GCDC, and it causes # problems with the overlay if we try to use an actual # wx.GCDC so don't try it. If you do not need to use a # semi-transparent background then you can leave this out. if 'wxMac' not in wx.PlatformInfo: dc = wx.GCDC(dc) # Set the pen, for the box's border dc.SetPen( wx.Pen( colour=self.overlayPenColor.GetColour(), width=self.overlayPenWidth.GetValue(), style=self.wxPenStylesDict[self.penstylesCombo.GetString( self.penstylesCombo.GetSelection())])) # Create a brush (for the box's interior) with the same colour, # but 50% transparency. bc = self.overlayPenColor.GetColour() bc = wx.Colour(bc.red, bc.green, bc.blue, 0x80) dc.SetBrush(wx.Brush(bc)) # Draw the rectangle dc.DrawRectangle(rect) if evtPos[0] < self.startPos[ 0]: # draw on left side of rect, not inside it dc.DrawBitmap(self.cropbitmap, evtPos[0] - 25 - self.overlayPenWidth.GetValue(), evtPos[1] - 17) else: dc.DrawBitmap(self.cropbitmap, evtPos[0] + 2 + self.overlayPenWidth.GetValue(), evtPos[1] - 17) del odc # Make sure the odc is destroyed before the dc is. ## print('OnMouseMove') def OnLeftUp(self, event): if self.HasCapture(): self.ReleaseMouse() self.endPos = event.GetPosition() ## print('StartPos: %s' %self.startPos) ## print('EndPos: %s' %self.endPos) self.startPos = None self.endPos = None # When the mouse is released we reset the overlay and it # restores the former content to the window. dc = wx.ClientDC(self) odc = wx.DCOverlay(self.overlay, dc) odc.Clear() del odc self.overlay.Reset() ## print('OnLeftUp') def OnSize(self, event=None): if event: event.Skip() x, y = self.GetSize() if x <= 0 or y <= 0: return self.buffer = wx.Bitmap(x, y) dc = wx.MemoryDC() dc.SelectObject(self.buffer) dc.SetBackground(self.background) dc.Clear() dc.DrawBitmap(self.honeyBitmap, 40, 40) dc.SetFont(wx.Font(wx.FontInfo(18))) dc.DrawText('Drag the mouse on this window.', 325, 100) del dc self.Refresh() #self.Update() def OnPaint(self, event): dc = wx.BufferedPaintDC(self, self.buffer)
def __init__(self, parent, log): self.log = log wx.Panel.__init__(self, parent, wx.ID_ANY, style=wx.CLIP_CHILDREN) ## self.SetDoubleBuffered(True) self.background = wx.Brush(self.GetBackgroundColour()) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) #--Rubberband Overlay self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) self.Bind(wx.EVT_MOTION, self.OnMouseMove) self.startPos = None self.endPos = None self.overlay = wx.Overlay() self.cropbitmap = wx.Bitmap('bitmaps/cropshot24x20.png') self.honeyBitmap = wx.Bitmap('bitmaps/honeycomb300.png') self.wxPenStylesDict = OrderedDict([ ('Solid', wx.PENSTYLE_SOLID), ('Dot', wx.PENSTYLE_DOT), ('Long Dash', wx.PENSTYLE_LONG_DASH), ('Short Dash', wx.PENSTYLE_SHORT_DASH), ('Dot Dash', wx.PENSTYLE_DOT_DASH), ('User Dash', wx.PENSTYLE_USER_DASH), ('Transparent', wx.PENSTYLE_TRANSPARENT), #('Stipple' , wx.PENSTYLE_STIPPLE), ('BDiagonal Hatch', wx.PENSTYLE_BDIAGONAL_HATCH), ('CrossDiag Hatch', wx.PENSTYLE_CROSSDIAG_HATCH), ('FDiagonal Hatch', wx.PENSTYLE_FDIAGONAL_HATCH), ('Cross Hatch', wx.PENSTYLE_CROSS_HATCH), ('Horizontal Hatch', wx.PENSTYLE_HORIZONTAL_HATCH), ('Vertical Hatch', wx.PENSTYLE_VERTICAL_HATCH), ]) list = [] for key, value in self.wxPenStylesDict.items(): list.append(key) self.penstylesCombo = wx.ComboBox(self, -1, choices=list, size=(150, -1), style=wx.CB_READONLY) self.penstylesCombo.SetSelection(0) self.penstylesCombo.SetToolTip('Pen Style') self.overlayPenWidth = wx.SpinCtrl(self, -1, value='', size=(75, -1), style=wx.SP_ARROW_KEYS, min=1, max=24, initial=1) self.overlayPenWidth.SetToolTip('Pen Width') from wx.lib.colourselect import ColourSelect self.overlayPenColor = ColourSelect(self, -1, colour=wx.BLUE) self.overlayPenColor.SetToolTip('Pen Color') sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.penstylesCombo, 0, wx.ALL, 5) sizer.Add(self.overlayPenWidth, 0, wx.ALL, 5) sizer.Add(self.overlayPenColor, 0, wx.ALL, 5) box = wx.BoxSizer(wx.VERTICAL) box.Add(sizer, 0) box.Add((1, 1), 1) self.SetSizer(box) self.OnSize()
def __init__(self, place, **args): self = ColourSelect(place[0], -1, size=(100, 10)) Widget.__init__(self, place, **args)