def Calcumalate(self): 'Tab layout calculations, sets cursor positions for the label, the icon, and the button.' #Create a DC for use as calculation reference dc = ClientDC(self) dc.Font=self.font[self.mode] #curent Horizantal placement position xpad = self.padding[self.mode].x xcurser = xpad + self.margins[self.mode].left ypad = self.padding[self.mode].y flip = pref('tabs.flip', False) style = pref('tabs.style', 2) icon = self.Icon iconsize = self.iconsize[self.mode] #determine tab height label1 = self.label1 if isinstance(label1, str): label1 = label1.decode('fuzzy utf8') txtwh = dc.GetTextExtent(label1)[0] ycurser = self.txtht = dc.Font.Height#sum([txtexts[1],txtexts[2],txtexts[3]]) if (icon or style) and ycurser < iconsize: ycurser=iconsize ycurser += 2 * ypad + self.margins[self.mode].y #Icon and button placement if on the left if not flip: self.iconcurser=Point(xcurser, (ycurser-self.margins[self.mode].y)/2+self.margins[self.mode].top-iconsize/2) #icon and #else: self.iconcurser = 0 if (style == 2 and not flip) or (style==1 and flip): self.closebutton.Size = Size(iconsize,iconsize) self.buttoncurser=self.iconcurser or Point(xcurser, (ycurser-self.margins[self.mode].y)/2+self.margins[self.mode].top-iconsize/2) if (icon and not flip) or (style==2 and not flip) or (style==1 and flip): xcurser +=iconsize + xpad #Label placement self.label1curser=Point(xcurser, (ycurser-self.margins[self.mode].y)/2+self.margins[self.mode].top-self.txtht/2) xcurser += txtwh + xpad #adding space for right hand elements to be placed during painting if (icon and flip) or (style==1 and not flip) or (style==2 and flip): xcurser+=iconsize + xpad xcurser+=self.margins[self.mode].right #setting tabs to just fit contents maxwidth = self.maxtabwidth if maxwidth and maxwidth < xcurser: xcurser=maxwidth self.gensize = (xcurser, ycurser) self.SetMinSize(self.gensize) #self.Parent.Generate() #print 'hey look, the close button is shown is a',(style==1),'statement' self.closebutton.Show(style==1 or (style==2 and self.Rect.Contains(self.Parent.ScreenToClient(GetMousePosition()))))
def __normalizeTip(self, tip: str) -> str: dc: ClientDC = ClientDC(self) ls: LineSplitter = LineSplitter() lines: List[str] = ls.split(text=tip, dc=dc, textWidth=int(DEFAULT_WIDTH * 0.8)) splitTip: str = '' for line in lines: splitTip = f'{splitTip}{line}{osLineSep}' return splitTip
def autoResize(self): """ Auto-resize the class @author C.Dutoit WARNING : Every change here must be reported in DRAW pyutMethod """ # Init pyutObject: PyutClass = cast(PyutClass, self.pyutObject) dc = ClientDC(self.GetDiagram().GetPanel()) # Get header size (headerX, headerY, headerW, headerH) = self.calculateClassHeader(dc, False, calcWidth=True) y = headerY + headerH # Get fields size if pyutObject.showFields is True: (fieldsX, fieldsY, fieldsW, fieldsH) = self.calculateClassFields(dc, False, initialY=y, calcWidth=True) y = fieldsY + fieldsH else: fieldsW, fieldsH = 0, 0 # Get methods size if pyutObject.showMethods is True: (methodX, methodY, methodW, methodH) = self.calculateClassMethods(dc, True, initialY=y, calcWidth=True) y = methodY + methodH else: methodW, methodH = 0, 0 w = max(headerW, fieldsW, methodW) h = y - headerY w += 2.0 * MARGIN self.SetSize(w, h) # to automatically replace the sizers at a correct place if self.IsSelected(): self.SetSelected(False) self.SetSelected(True)
def onDrawMe(self, event: CommandEvent): extension: str = 'png' imageType: BitmapType = BITMAP_TYPE_PNG window: ScrolledWindow = self._diagramFrame context: ClientDC = ClientDC(window) memory: MemoryDC = MemoryDC() x, y = window.ClientSize emptyBitmap: Bitmap = Bitmap(x, y, -1) memory.SelectObject(emptyBitmap) memory.Blit(source=context, xsrc=0, height=y, xdest=0, ydest=0, ysrc=0, width=x) memory.SelectObject(NullBitmap) img: Image = emptyBitmap.ConvertToImage() filename: str = f'DiagramDump.{extension}' status: bool = img.SaveFile(filename, imageType)
def onPaste(self, event: CommandEvent): """ Args: event: """ if len(self._clipboard) == 0: return self.logger.info(f'Pasting {len(self._clipboard)} objects') frame = self._mediator.getUmlFrame() if frame == -1: PyutUtils.displayError(_("No frame to paste into")) return # put the objects in the clipboard and remove them from the diagram x, y = 100, 100 for clipboardObject in self._clipboard: obj: PyutObject = copy(clipboardObject) if isinstance(obj, PyutClass): po: OglObject = OglClass(obj) elif isinstance(obj, PyutNote): po = OglNote(obj) elif isinstance(obj, PyutActor): po = OglActor(obj) elif isinstance(obj, PyutUseCase): po = OglUseCase(obj) else: self.logger.error(f'Error when try to paste object: {obj}') return self.logger.info(f'Pasting: {po=}') self._mediator.getUmlFrame().addShape(po, x, y) x += 20 y += 20 canvas = po.GetDiagram().GetPanel() # the frame that contains the shape # specify the canvas on which we will paint dc: ClientDC = ClientDC(canvas) canvas.PrepareDC(dc) self._treeNotebookHandler.setModified(True) self._mediator.updateTitle() canvas.Refresh()
def _OnMnuEditPaste(self, event: CommandEvent): """ Args: event: """ if len(self._clipboard) == 0: return frame = self._ctrl.getUmlFrame() if frame == -1: PyutUtils.displayError(_("No frame to paste into")) return # put the objects in the clipboard and remove them from the diagram x, y = 100, 100 for obj in self._clipboard: obj = copy(obj) # this is a PyutObject if isinstance(obj, PyutClass): po = OglClass(obj) elif isinstance(obj, PyutNote): po = OglNote(obj) elif isinstance(obj, PyutActor): po = OglActor(obj) elif isinstance(obj, PyutUseCase): po = OglUseCase(obj) else: self.logger.error("Error when try to paste object") return self._ctrl.getUmlFrame().addShape(po, x, y) x += 20 y += 20 canvas = po.GetDiagram().GetPanel() # the canvas that contain the shape # specify the canvas on which we will paint dc = ClientDC(canvas) canvas.PrepareDC(dc) self._mainFileHandlingUI.setModified(True) self._ctrl.updateTitle() canvas.Refresh()
def evtLeftDown(self, event): """ Handle left mouse button down """ # Get the clicked tool x, y = event.GetPosition() (x1, y1, x2, y2, tool) = self._getClickedButton(x, y) self._clickedButton = (x1, y1, x2, y2, tool) # Get dc dc = ClientDC(self) oldPen = dc.GetPen() # Clicked illusion dc.SetPen(GREY_PEN) dc.DrawLine(x2 - 1, y2 - 1, x2 - 1, y1) dc.DrawLine(x2 - 1, y2 - 1, x1, y2 - 1) dc.SetPen(BLACK_PEN) dc.DrawLine(x1, y1, x2 - 1, y1) dc.DrawLine(x1, y1, x1, y2 - 1) # Set old pen dc.SetPen(oldPen)
def Redraw(self, dc: DC = None, full: bool = True, saveBackground: bool = False, useBackground: bool = False): """ Refresh the diagram. If a DC is given, use it. Otherwise, use a double buffered DC. Args: dc: If None, a default dc is created full: If False, only draw the shape borders. saveBackground: If True, save the background useBackground: If True, use the background """ needBlit = False w, h = self.GetSize() if dc is None: dc = self.CreateDC(useBackground, w, h) needBlit = True dc.SetFont(self._defaultFont) shapes = self._diagram.GetShapes() if full: # first time, need to create the background if saveBackground: # first, draw every non-moving shapes for shape in shapes: if not shape.IsMoving(): shape.Draw(dc) # save the background self.SaveBackground(dc) # draw every moving shape for shape in shapes: if shape.IsMoving(): shape.Draw(dc) # x, y = self.CalcUnScrolledPosition(0, 0) if useBackground: # draw every moving shapes for shape in shapes: if shape.IsMoving(): shape.Draw(dc) # TODO: This code belongs in OnPaint # if self._prefs.backgroundGridEnabled is True: # self._drawGrid(memDC=dc, width=w, height=h, startX=x, startY=y) else: # don't use background # draw all shapes for shape in shapes: shape.Draw(dc) # TODO: This code belongs in OnPaint # if self._prefs.backgroundGridEnabled is True: # self._drawGrid(memDC=dc, width=w, height=h, startX=x, startY=y) else: # not full for shape in shapes: shape.DrawBorder(dc) shape.DrawAnchors(dc) if needBlit: client = ClientDC(self) x, y = self.CalcUnscrolledPosition(0, 0) client.Blit(0, 0, w, h, dc, x, y)
def OnRefresh(self, event): """ Refresh dialog box """ (w, h) = self.GetSize() nbButtonsW = (w - MARGIN * 2) / BUTTON_SIZE dc = ClientDC(self) oldPen = dc.GetPen() # Draw i = 0 j = 0 for tool in self._tools: tool: Tool = cast(Tool, tool) # Calculate position x = MARGIN + i * BUTTON_SIZE y = MARGIN + j * BUTTON_SIZE + MARGIN_TOP # Draw dc.SetPen(BLACK_PEN) categoryStr: str = f'[{tool.initialCategory}]' dc.DrawText(categoryStr, MARGIN, MARGIN) dc.SetPen(WHITE_PEN) dc.DrawLine(x, y, x + BUTTON_SIZE - 1, y) dc.DrawLine(x, y, x, y + BUTTON_SIZE - 1) dc.SetPen(BLACK_PEN) dc.DrawLine(x, y + BUTTON_SIZE - 1, x + BUTTON_SIZE - 1, y + BUTTON_SIZE - 1) dc.DrawLine(x + BUTTON_SIZE - 1, y, x + BUTTON_SIZE - 1, y + BUTTON_SIZE - 1) dc.DrawBitmap(tool.img, x + 1, y + 1) i += 1 # Find next position if i > nbButtonsW - 1: i = 0 j += 1 # Set old pen dc.SetPen(oldPen)
def Redraw(self, dc=None, full=True, saveBackground=False, useBackground=False): """ Refresh the diagram graphically. If a dc is given, use it. Otherwise, a double buffered dc is used. @param DC dc : if None, a default dc will be created @param bool full : if 0, only draws the borders of shapes @param bool saveBackground : if True, the background will be saved @param bool useBackground : if True, the background will be used """ needBlit = False w, h = self.GetSize() if dc is None: dc = self.CreateDC(useBackground, w, h) needBlit = True dc.SetFont(self._defaultFont) shapes = self._diagram.GetShapes() if full: # first time, need to create the background if saveBackground: # first, draw every non moving shapes for shape in shapes: if not shape.IsMoving(): shape.Draw(dc) # save the background self.SaveBackground(dc) # draw every moving shapes for shape in shapes: if shape.IsMoving(): shape.Draw(dc) if useBackground: # draw every moving shapes for shape in shapes: if shape.IsMoving(): shape.Draw(dc) else: # don't use background # draw all shapes for shape in shapes: shape.Draw(dc) else: # not full for shape in shapes: shape.DrawBorder(dc) shape.DrawAnchors(dc) if needBlit: # MODIFIED BY C.DUTOIT : Added Python test client = ClientDC(self) if __version__ > "2.3.2": x, y = self.CalcUnscrolledPosition(0, 0) client.Blit(0, 0, w, h, dc, x, y) else: client.Blit(0, 0, w, h, dc, 0, 0)
def __init__(self, parent): """ """ # Check import sys if sys.platform == "win32": return # Initialize the dialog box super().__init__( parent, -1, _("Tips"), DefaultPosition, Size(DEFAULT_WIDTH, DEFAULT_HEIGHT), RESIZE_BORDER | SYSTEM_MENU | CAPTION | FRAME_FLOAT_ON_PARENT | STAY_ON_TOP) # Normalize tips from org.pyut.general.LineSplitter import LineSplitter ls = LineSplitter() dc = ClientDC(self) for i in range(len(Tips)): tip = ls.split(Tips[i], dc, int(DEFAULT_WIDTH * 0.8)) Tips[i] = "" for line in tip: Tips[i] += line + "\n" # tip = "" # for line in Tips[i].split("\n"): # newLine = "" # for word in line.split(" "): # if len(newLine) + len(word) > 59: # tip += newLine + "\n" # newLine = "" # newLine += word + " " # tip += newLine # Tips[i] = tip # Set current tips self._prefs = PyutPreferences() self._currentTip = self._prefs[PyutPreferences.CURRENT_TIP] if self._currentTip is None: self._currentTip = 0 else: self._currentTip = int(self._currentTip) # Add icon # fileName = resource_filename(IMG_PKG, 'TipsLogo.bmp') # icon = Icon(fileName, BITMAP_TYPE_BMP) # self.SetIcon(icon) # self.Center(BOTH) # Center on the screen self.Center(dir=VERTICAL) self.AcceptsFocus() # Create controls # bmp: Bitmap = org.pyut.resources.img.ImgTipsFrameTipsLogo.embeddedImage.GetBitmap() bmp: Bitmap = TipsLogo.GetBitmap() self._picture = StaticBitmap(self, -1, bmp) tip = Tips[self._currentTip] self._label = StaticText(self, -1, tip, size=Size(DEFAULT_WIDTH * 0.8, DEFAULT_HEIGHT * 0.8), style=ST_NO_AUTORESIZE) nextTipButton = Button(self, ID_SET_NEXT_TIP, _("&Next tip")) previousTipButton = Button(self, ID_SET_PREVIOUS_TIP, _("&Previous tip")) self._chkShowTips = CheckBox(self, ID_CHK_SHOW_TIPS, _("&Show tips at startup")) showTips: bool = self._prefs.showTipsOnStartup() self._chkShowTips.SetValue(showTips) # Upper sizer upSizer = BoxSizer(HORIZONTAL) upSizer.Add(self._picture, 0, ALL | ALIGN_CENTER, 5) upSizer.Add(self._label, 1, ALL | ALIGN_CENTER, 5) # Lower sizer loSizer = BoxSizer(HORIZONTAL) loSizer.Add(previousTipButton, 0, ALL | ALIGN_CENTER, 5) loSizer.Add(nextTipButton, 0, ALL | ALIGN_CENTER, 5) loSizer.Add(Button(self, ID_OK, "&Ok"), 0, ALL | ALIGN_CENTER, 5) # Main sizer self.SetAutoLayout(True) mainSizer = BoxSizer(VERTICAL) mainSizer.Add(upSizer, 0, ALL | ALIGN_CENTER, 5) mainSizer.Add(self._chkShowTips, 0, ALL | ALIGN_CENTER, 5) mainSizer.Add(loSizer, 0, ALL | ALIGN_CENTER, 5) self.SetSizer(mainSizer) mainSizer.Fit(self) # Events self.Bind(EVT_BUTTON, self._onOk, id=ID_OK) self.Bind(EVT_CLOSE, self._onClose) self.Bind(EVT_BUTTON, self._onNextTip, id=ID_SET_NEXT_TIP) self.Bind(EVT_BUTTON, self._onPreviousTip, id=ID_SET_PREVIOUS_TIP)