def get_points(self, p): ''' Find up,down,left and right of point p,get the adjacent empty points, form a single list,and return it. ''' p_list = [] for i in range(p.y + 1, self.col + 1): if i < self.col and self.data[p.x][i] > 0: break else: p_list.append(Point(p.x, i)) for i in range(p.y - 1, -2, -1): if i > -1 and self.data[p.x][i] > 0: break else: p_list.append(Point(p.x, i)) for i in range(p.x + 1, self.row + 1): if i < self.row and self.data[i][p.y] > 0: break else: p_list.append(Point(i, p.y)) for i in range(p.x - 1, -2, -1): if i > -1 and self.data[i][p.y] > 0: break else: p_list.append(Point(i, p.y)) return p_list
def OnDrawItem(self,dc,rect,n): 'Draws the foreground of each item.' curser = Point(rect.x, rect.y) + (self.padding.x, 0) if self.items[n].id==-1: return self.DrawSeparator(dc, rect, n) if self.items[n].font: font = self.items[n].font else: font = self.Font dc.Font=font dc.TextForeground=(self.selfc if self.Selection==n else self.normalfc) if self.items[n].menu: dc.Brush=wx.BLACK_BRUSH dc.Pen=wx.TRANSPARENT_PEN smi=self.submenuiconhot if self.Selection==n else self.submenuicon # if isinstance(smi,wx.Mask): # acolor = self.selfc if self.Selection==n else self.normalfc # arrow = wx.EmptyBitmap(10,10) # arrow.SetMask(smi) # mdc2 = wx.MemoryDC() # mdc2.SelectObject(arrow) # mdc2.Brush = wx.Brush(acolor) # mdc2.FloodFill(0,0,wx.BLACK) # mdc2.SelectObject(wx.NullBitmap) # dc.DrawBitmap(arrow,rect.Width-self.padding.x-arrow.Width,rect.Y+(rect.Height/2)-arrow.Height/2,True) # endcap=arrow.Width+self.padding.x # else: dc.DrawBitmap(smi,rect.Width-self.padding.x-smi.Width,rect.Y+(rect.Height/2)-smi.Height/2,True) endcap=smi.Width+self.padding.x else: endcap=0 padx = self.padding.x txtext = dc.Font.Height txtext_pad = Point(txtext + padx, 0) for i in self.items[n].content: if type(i) is Bitmap: curser.y = rect.Y + (rect.height / 2 - i.Height / 2) imgpad = (self.bitmapwidth - i.Width)//2 if self.bitmapwidth else 0 try: dc.DrawBitmapPoint(i, (curser.x + imgpad, curser.y), True) except Exception: traceback.print_exc_once() try: log.error("Failed drawing bitmap: %r", getattr(i, 'path', None)) except Exception: pass curser += Point(max(self.bitmapwidth, i.Width) + padx, 0) elif isinstance(i, basestring): curser.y = rect.Y + (rect.height / 2 - txtext / 2) text_rect = RectPS(curser, Size(rect.width - curser.x - padx - endcap, txtext)) dc.DrawTruncatedText(i, text_rect, alignment = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL) curser += txtext_pad
def _build_passthru_objects(self, graph_edges_dict): """Add any passthrus as they are needed. These are vertice names in the graph dictionary which are not covered by inst or port names. """ passthru_id = 0 for node in graph_edges_dict.keys(): if not self.drawing_object_dict.get(node, None): if node == '_iport': continue if DEBUG: print "Found a new thang..", node drawobj = Drawing_Object( name=node + '_' + str(passthru_id), parent=None, label=node, obj_type='passthru', ) drawobj.lhs_ports.append('_i') drawobj.rhs_ports.append('_o') drawobj.startpt = Point(0, 0) drawobj.endpt = Point(20, 0) self.drawing_object_dict[node] = drawobj passthru_id += 1
def game_no_solution(self): ''' test if the current game situation have solution. return value: 0: yes,have solution. 1: no,need to shuffle the cards. 2: the cards are all deleted,this level is clear. ''' cards_num = 0 for i in range(0, self.row): for j in range(0, self.col): if self.data[i][j] > 0: cards_num += 1 for k in range(i, self.row): for l in range(0, self.col): if k == i and l == j: #exclude the situation of link to itself continue if self.data[k][l] > 0: p1 = Point(i, j) p2 = Point(k, l) if self.can_link(p1, p2, None): return 0 if cards_num > 0: return 1 else: return 2
def __init__(self, parent): super(About, self).__init__(parent, size=(360, 120)) self.info = wx.StaticText(self, pos=Point(80, 20)) self.info.SetLabel("Tracer by Ran Shuai, MIT license") self.mail = wx.StaticText(self, pos=Point(90, 40)) self.mail.SetLabel("*****@*****.**") self.Center() self.Show()
def paint_bitmap(self, dc, pickerPos=None): ''' If dc is None, returns a PIL image ''' bw, bh = self.bitmap.Width, self.bitmap.Height # get the 0,0 point of the image if centered imagecenter = Point(self.Rect.Width / 2, self.Rect.Height / 2) - Point( bw / 2, bh / 2) # adjust away from center xy = imagecenter + (self.adjustment[0] * bw, self.adjustment[1] * bh) # adjust the offset by how far into the picture the selection is # if pickerPos: # xy[0] += pickerPos[0]; xy[1] += pickerPos[1] if dc is not None: # dc.SetBrush(wx.TRANSPARENT_BRUSH) #@UndefinedVariable # dc.SetPen(wx.RED_PEN) #@UndefinedVariable dc.DrawBitmap(self.bitmap, *xy) # dc.DrawRectangleRect(cropRect) else: pickWidth = int(self.picksize[0]) pickHeight = int(self.picksize[1]) pickRect = wx.RectPS( pickerPos or ((self.Rect.width // 2 - self.picksize[0] // 2), (self.Rect.height // 2 - self.picksize[1] // 2)), (pickWidth, pickHeight)) pickRect.Position -= xy imageRect = wx.RectPS((0, 0), (bw, bh)) cropRect = imageRect.Intersect(pickRect) crop_box = (cropRect.left, cropRect.top, cropRect.right, cropRect.bottom) croppedImage = self.bitmap.PIL.crop(crop_box) # croppedImage.Show("croppedImage") offsetX = max(-(pickRect.x - cropRect.x), 0) offsetY = max(-(pickRect.y - cropRect.y), 0) if (offsetX or offsetY): paddedImage = Image.new('RGBA', (pickRect.width, pickRect.height), (0, 0, 0, 0)) paddedImage.paste(croppedImage, (offsetX, offsetY)) return paddedImage return croppedImage
def DrawSeparator(self, dc, rect, n): sepwidth = rect.width - self.padding.x * 2 if self.separator: sepheight = self.separator.Size.height seppos = (self.padding.x, rect.y + rect.height // 2 - sepheight // 2) self.separator.Draw(dc, RectPS(seppos, (sepwidth, sepheight))) else: dc.Pen = Pen(self.normalfc, 1) seppos = Point(self.padding.x, rect.y + rect.height // 2) endpos = seppos + Point(sepwidth, 0) dc.DrawLinePoint(seppos, endpos)
def UpdateSkin(self): Renderer.UpdateSkin(self) s = self.skin s.margins = skin.get('BuddiesPanel.GroupMargins') s.padding = skin.get('BuddiesPanel.GroupPadding', lambda: Point(4,4)) # Expanded/Collapsed icons next to group names g = lambda k, default = sentinel: skin.get('BuddiesPanel.GroupIcons.' + k, default) s.expanded = g('Expanded', lambda: None) s.expandedhover = g('ExpandedHover', lambda: s.expanded) s.expandedselected = g('ExpandedSelected', lambda: s.expanded) s.collapsed = g('Collapsed', lambda: None) s.collapsedhover = g('CollapsedHover', s.collapsed) s.collapsedselected = g('CollapsedSelected', s.collapsed) # Group backgrounds (default to Buddy backgrounds if not specified) g = lambda k, default: skin.get('BuddiesPanel.Backgrounds.' + k, default) s.bg = g('Group', lambda: g('Buddy')) s.hoverbg = g('GroupHover', lambda: g('BuddyHover')) s.selectedbg = g('GroupSelected', lambda: g('BuddySelected')) # Group font colors (default to Buddy font colors if not specified) f = s.fontcolors g = lambda k, default: skin.get('BuddiesPanel.FontColors.' + k, default) f.group = g('Group', lambda: g('Buddy', lambda: syscol(wx.SYS_COLOUR_WINDOWTEXT))) f.grouphover = g('GroupHover', lambda: g('BuddyHover', lambda: syscol(wx.SYS_COLOUR_WINDOWTEXT))) f.groupselected = g('GroupSelected', lambda: g('BuddySelected', lambda: syscol(wx.SYS_COLOUR_HIGHLIGHTTEXT))) self.calcsizes()
def on_paint_thumb(self, _): '''paint thumbnail''' dc = wx.PaintDC(self.thumbnail) dc.Clear() self.thumb_dc = dc points = [] input_points = [] output_points = [] for v in self.graph['vertices']: if 'rect' in self.graph['vertices'][v]: rect = self.graph['vertices'][v]['rect'] if self.graph['vertices'][v]['is_input']: input_points.append((int(rect[0]/self.thumb_ratio_x), int(rect[1]/self.thumb_ratio_y))) elif self.graph['vertices'][v]['is_output']: output_points.append((int(rect[0]/self.thumb_ratio_x), int(rect[1]/self.thumb_ratio_y))) points.append((int(rect[0]/self.thumb_ratio_x), int(rect[1]/self.thumb_ratio_y))) dc.DrawPointList(points, wx.Pen(self.background_color, 20)) dc.SetPen(wx.Pen(style['input_color'], 1)) dc.SetBrush(wx.Brush(style['input_color'], wx.BRUSHSTYLE_TRANSPARENT)) for p in input_points: dc.DrawCircle(p, 2) dc.SetPen(wx.Pen(style['output_color'], 1)) dc.SetBrush(wx.Brush(style['output_color'], wx.BRUSHSTYLE_TRANSPARENT)) for p in output_points: dc.DrawCircle(p, 2) target_rect = self.get_canvas_view() thumb_rect = (math.floor(float(target_rect[0])/self.thumb_ratio_x), math.floor(float(target_rect[1])/self.thumb_ratio_y), math.floor(float(target_rect[2])/self.thumb_ratio_x), math.floor(float(target_rect[3])/self.thumb_ratio_y)) dc.SetPen(wx.Pen('red', 1)) dc.SetBrush(wx.Brush('red', wx.BRUSHSTYLE_TRANSPARENT)) dc.DrawRectangle(thumb_rect) rect = self.graph['vertices'][self.graph['selected']]['rect'] dc.DrawCircle(Point((int(rect[0]/self.thumb_ratio_x), int(rect[1]/self.thumb_ratio_y))), 2)
def save(self, project): """ Aave diagram in XML file. @param project @author Deve Roux @modified Laurent Burgbacher <*****@*****.**> : add version support @modified C.Dutoit 20021122 : added document container tag """ dlg: Dialog = Dialog(None, -1, "Saving...", style=STAY_ON_TOP | ICON_INFORMATION | RESIZE_BORDER, size=Size(207, 70)) xmlDoc: Document = Document() try: # xmlDoc: Document = Document() top = xmlDoc.createElement("PyutProject") top.setAttribute('version', str(self._this_version)) top.setAttribute('CodePath', project.getCodePath()) xmlDoc.appendChild(top) # dlg = Dialog(None, -1, "Saving...", style=STAY_ON_TOP | ICON_INFORMATION | RESIZE_BORDER, size=Size(207, 70)) gauge = Gauge(dlg, -1, 100, pos=Point(2, 5), size=Size(200, 30)) dlg.Show(True) # Save all documents in the project for document in project.getDocuments(): documentNode = xmlDoc.createElement("PyutDocument") documentNode.setAttribute('type', PyutConstants.diagramTypeAsString(document.getType())) top.appendChild(documentNode) oglObjects = document.getFrame().getUmlObjects() for i in range(len(oglObjects)): gauge.SetValue(i * 100 / len(oglObjects)) oglObject = oglObjects[i] if isinstance(oglObject, OglClass): documentNode.appendChild(self._OglClass2xml(oglObject, xmlDoc)) elif isinstance(oglObject, OglNote): documentNode.appendChild(self._OglNote2xml(oglObject, xmlDoc)) elif isinstance(oglObject, OglActor): documentNode.appendChild(self._OglActor2xml(oglObject, xmlDoc)) elif isinstance(oglObject, OglUseCase): documentNode.appendChild(self._OglUseCase2xml(oglObject, xmlDoc)) elif isinstance(oglObject, OglLink): documentNode.appendChild(self._OglLink2xml(oglObject, xmlDoc)) elif isinstance(oglObject, OglSDInstance): documentNode.appendChild(self._OglSDInstance2xml(oglObject, xmlDoc)) elif isinstance(oglObject, OglSDMessage): documentNode.appendChild(self._OglSDMessage2xml(oglObject, xmlDoc)) except (ValueError, Exception) as e: try: dlg.Destroy() self.logger.error(f'{e}') except (ValueError, Exception) as e: self.logger.error(f'{e}') PyutUtils.displayError(_("Can't save file")) return xmlDoc dlg.Destroy() return xmlDoc
def calcdraw(self, w, h, Rect = Rect): if self._lastcalc == (w, h): return self._lastseq s = self.skin rect = Rect(0, 0, w, h).AddMargins(wx.Rect(*s.margins)) icons = sorted(((icon, getattr(self, icon + '_pos')) for icon in self.icons), key = lambda o: {'f': -1, 'b': 1}.get(o[1][0], 0)) seq = [] last = Rect() badge_size = min(self.badge_max_size, max(self.badge_min_size, int(self.buddy_icon_size * self.badge_ratio))) frame_size = s.icon_frame_size padding = self.padding hpadding = 4 for icon, pos in icons: if getattr(self, 'show_' + icon): pos = pos.lower() size = getattr(self, icon + '_size') left = pos.endswith('left') iconpos = Point(-size * int(not left), 0) if icon == 'buddy_icon': # special case for buddy icon, which can optionally have a frame around it. iconw = size + frame_size.left + frame_size.right frameRect = Rect(0, 0, iconw, size + frame_size.top + frame_size.bottom) frameRect.x, frameRect.y = rect.Pos(wx.Point(-frameRect.width * int(not left), 0))[0], rect.VCenterH(frameRect.height) last = Rect(frameRect.x + frame_size.left, frameRect.y + frame_size.top, size, size) seq += [(getattr(self, 'get_buddy_icon'), last, 0)] seq += [(getattr(self, 'get_frame_icon'), frameRect, 0)] rect = rect.Subtract(**{'left' if left else 'right': iconw + hpadding}) bitmap = getattr(self, 'get_' + icon) else: if not pos.startswith('b'): # non badge r = Rect(rect.Pos(iconpos)[0], rect.VCenterH(size), size, size) rect = rect.Subtract(**{'left' if left else 'right': size + hpadding}) last = r alignment = ALIGN_CENTER bitmap = getattr(self, 'get_' + icon) else: # badge bp = badge_size alignment = LBOTTOM if left else RBOTTOM badgepos = last.Pos(wx.Point(0 if left else -bp, -bp)) r = Rect(badgepos[0], badgepos[1], badge_size, badge_size) bitmap = lambda obj, icon=icon: getattr(self, 'get_' + icon)(obj).ResizedSmaller(badge_size) seq.append((bitmap, r, alignment)) self.inforect = rect self._lastcalc = (w, h) self._lastseq = seq return seq
def __init__(self, monitor, position, padding=None, border=None): self.monitor = monitor self.corner = position assert position in valid_corners, position if padding is None: padding = (0, 10) if border is None: border = (10, 10) self.padding = Point(*padding) self.border = Point(*border) self.NextRect = self.Down if TOP & self.corner else self.Up self.OppositeRect = self.Up if TOP & self.corner else self.Down
def recursivelyToLineSegments(bezier, level, result): if level == 0: return x12 = (bezier[0][0] + bezier[1][0]) / 2 y12 = (bezier[0][1] + bezier[1][1]) / 2 x23 = (bezier[1][0] + bezier[2][0]) / 2 y23 = (bezier[1][1] + bezier[2][1]) / 2 x34 = (bezier[2][0] + bezier[3][0]) / 2 y34 = (bezier[2][1] + bezier[3][1]) / 2 x123 = (x12 + x23) / 2 y123 = (y12 + y23) / 2 x234 = (x23 + x34) / 2 y234 = (y23 + y34) / 2 x1234 = (x123 + x234) / 2 y1234 = (y123 + y234) / 2 dx = bezier[3][0] - bezier[0][0] dy = bezier[3][1] - bezier[0][1] d2 = abs((bezier[1][0] - bezier[3][0]) * dy - (bezier[1][1] - bezier[3][1]) * dx) d3 = abs((bezier[2][0] - bezier[3][0]) * dy - (bezier[2][1] - bezier[3][1]) * dx) if (d2 + d3) * (d2 + d3) < BISECT_TOLERANCE * (dx * dx + dy * dy): result += [Point(x1234, y1234)] else: recursivelyToLineSegments([bezier[0], Point(x12, y12), Point(x123, y123), Point(x1234, y1234)], \ level-1, result) recursivelyToLineSegments([Point(x1234, y1234), Point(x234, y234), Point(x34, y34), bezier[3]], \ level-1, result)
def __init__(self, parent, ID, pyutModel: Union[PyutClass, PyutInterface]): """ Args: parent: ID: pyutModel: """ super().__init__(parent, ID, _("Description Edit")) # Associated PyutLink self._pyutModel: Union[PyutClass, PyutInterface] = pyutModel self.SetSize(Size(416, 200)) # init members vars self._text = self._pyutModel.description self._returnAction = OK # describe how the user exited the dialog box # labels StaticText(self, ID_ANY, _("Class description"), Point(8, 8)) # text self._txtCtrl: TextCtrl = TextCtrl(self, TXT_COMMENT, self._text, Point(8, 24), Size(392, 100), TE_MULTILINE) # Set the focus self._txtCtrl.SetFocus() # text events self.Bind(EVT_TEXT, self._onTxtNoteChange, id=TXT_COMMENT) # Ok/Cancel Button(self, OK, _("&Ok"), Point(120, 140)) Button(self, CANCEL, _("&Cancel"), Point(208, 140)) # button events self.Bind(EVT_BUTTON, self._onCmdOk, id=OK) self.Bind(EVT_BUTTON, self._onCmdCancel, id=CANCEL) self.Centre() self.ShowModal()
def wxbitmap_in_square(bmp, squaresize, scaleup=True): # print 'wxbitmap_insquare', bmp, squaresize, scaleup w, h = bmp.Width, bmp.Height if w > squaresize or h > squaresize or scaleup: img = ImageFromBitmap(bmp) if w > h: new_height = int(h / float(w) * squaresize) img = img.Scale(squaresize, new_height, IMAGE_QUALITY_HIGH) offset = Point(0, (squaresize - new_height) / 2) else: new_width = int(w / float(h) * squaresize) img = img.Scale(new_width, squaresize, IMAGE_QUALITY_HIGH) offset = Point((squaresize - new_width) / 2, 0) return BitmapFromImage(img) return bmp
def InitDefaults(self): self.IconSize = 32 self.margins = Margins((3, 3)) self.padding = Point(5, 5) self.CheckBoxSize = 16 self.SetNotificationInfo({}) self.SetUserNotifications({}) self.UpdateSkin()
def Up(self, prevRect, newSize, user_action): border, padding = self.border, self.padding if prevRect is None: if LEFT & self.corner: pt = self.ScreenRect.BottomLeft + (border.x + padding.x + self.offset[0], -border.y - self.offset[1]) else: pt = self.ScreenRect.BottomRight - (newSize.width + border.x + padding.x + self.offset[0], border.y + self.offset[1]) else: pt = prevRect.TopLeft - Point(0, border.y + padding.y) r = RectPS(pt - Point(0, newSize.height), newSize) if AVOID_MOUSE and not user_action and r.Contains(GetMousePosition()): r.y -= r.Bottom - GetMousePosition().y + AVOID_MOUSE_PIXELS return r
def data_change_9(self, p1, p2): ''' Disperse from Center first,left and right seperate,and then up and down seperate ''' p3 = Point() p4 = Point() self.data_change_4(p1, p2) #1.left and right seperate #find p1,p2 's position after 'left and right seperate',then do 'up and down seperate' on p1,p2 's new position p3.x = p1.x if p1.y < self.col/2: p3.y = 0 sign = 1 else: p3.y = self.col - 1 sign = -1 while self.data[p3.x][p3.y] != 0: p3.y += sign p4.x = p2.x if p2.y < self.col/2: p4.y = 0 sign = 1 else: p4.y = self.col - 1 sign = -1 while self.data[p4.x][p4.y] != 0: p4.y += sign #modify in case of special situation if p1.x == p2.x: if p1.y < self.col/2 and p2.y < self.col/2: p4.y = p3.y + 1 elif p1.y >= self.col/2 and p2.y >= self.col/2: p4.y = p3.y - 1 #p3,p4 are the new position of p1,p2 after 'left and right seperate', #do 'up and down seperate' on them self.data_change_3(p3, p4)
def on_motion(self, e=None, forcednewpos=None): if self.dragging is not False: newpos = forcednewpos or GetMousePosition() delta = newpos - Point(*self.dragging) diff = (float(delta.x) / self.bitmap.Width, float(delta.y) / self.bitmap.Height) self.adjustment = (self.adjustment[0] + diff[0], self.adjustment[1] + diff[1]) self.dragging = newpos self.Refresh() self._image_changed = True self._image_bytes = None
def data_change_10(self, p1, p2): ''' Centralize first do 'Left Right Converge' and then 'Up Down Converge' ''' p3 = Point() p4 = Point() self.data_change_6(p1, p2) #first do 'Left Right Converge' #find the new position of p1,p2 after 'Left Right Converge',then do 'Up Down Converge' on new position p3.x = p1.x if p1.y < self.col/2: p3.y = self.col/2 - 1 sign = -1 else: p3.y = self.col/2 sign = 1 while self.data[p3.x][p3.y] != 0: p3.y += sign p4.x = p2.x if p2.y < self.col/2: p4.y = self.col/2 -1 sign = -1 else: p4.y = self.col/2 sign = 1 while self.data[p4.x][p4.y] != 0: p4.y += sign #modify in case of special situation if p1.x == p2.x: if p1.y < self.col/2 and p2.y < self.col/2: p4.y = p3.y - 1 elif p1.y >= self.col/2 and p2.y >= self.col/2: p4.y = p3.y + 1 #p3,p4 are the new position of p1,p2 after 'Left Right Converge', #do 'Up Down Converge' on them self.data_change_5(p3, p4)
def get_field(self, position): position = self._get_fixed_position(position) position = Point(*position) if self.__po_fields: fields_sorted_by_dimensions = sorted(self.__po_fields, key=lambda f: f.dimensions) for field in fields_sorted_by_dimensions: field_x, field_y = field.location w, h = field.dimensions if Rect(field_x, field_y, w, h).Contains(position): return field return None else: return None
def __setupProgressDialog(self): self._dlgGauge = Dialog(None, ID_ANY, "Loading...", style=STAY_ON_TOP | ICON_INFORMATION | RESIZE_BORDER, size=Size(250, 70)) self._gauge: Gauge = Gauge(self._dlgGauge, ID_ANY, 5, pos=Point(2, 5), size=Size(200, 30)) self._dlgGauge.Show(True) wxYield()
def test_duckduckgo_search_results_area(self): folder = tempfile.gettempdir() name = 'DuckDuckGo' area = (50, 156, 615, 244) po_class = self.generator.get_po_class_for_url( u'https://duckduckgo.com/?q=selenium&ia=about', name, folder, area) for f in po_class.fields: x, y = f.location w, d = f.dimensions p = Point(x + w / 2, y + d / 2) self.assertTrue(Rect(*area).Contains(p), f) selectors = [f.selector for f in po_class.fields] bys = [f.by for f in po_class.fields] self.assertIn('link text', bys) self.assertIn(u'Selenium - Web Browser Automation', selectors)
def _scroll(self, e, name): e.Skip() clientRect = self.ClientRect virtual = self.VirtualSize scrollType = e.EventType orientation = e.Orientation o_idx = 0 if orientation == HORIZONTAL else 1 x, y = self.GetScrollPos(HORIZONTAL), self.GetScrollPos(VERTICAL) newPos = Point(x, y) setScrollbars = True # THUMBTRACK: dragging the scroll thumb if scrollType == wx.wxEVT_SCROLLWIN_THUMBTRACK: newPos[o_idx] = e.Position #setScrollbars = False # THUMBRELEASE: mouse up on the thumb elif scrollType == wx.wxEVT_SCROLLWIN_THUMBRELEASE: newPos[o_idx] = e.Position # LINEDOWN: clicking the down arrow elif scrollType == wx.wxEVT_SCROLLWIN_LINEDOWN: newPos[o_idx] = newPos[o_idx] + lineSize[o_idx] # LINEUP: clicking the up arrow elif scrollType == wx.wxEVT_SCROLLWIN_LINEUP: newPos[o_idx] = newPos[o_idx] - lineSize[o_idx] # PAGEDOWN: clicking below the scroll thumb elif scrollType == wx.wxEVT_SCROLLWIN_PAGEDOWN: newPos[o_idx] = newPos[o_idx] + clientRect[2 + o_idx] # PAGEUP: clicking above the scroll thumb elif scrollType == wx.wxEVT_SCROLLWIN_PAGEUP: newPos[o_idx] = newPos[o_idx] - clientRect[2 + o_idx] # keep scroll position within bounds newPos[0] = max(min(newPos[0], virtual.width - clientRect.width), 0) newPos[1] = max(min(newPos[1], virtual.height - clientRect.height), 0) self.ScrollWindow(-(newPos.x - x), -(newPos.y - y)) if setScrollbars: self.AdjustScrollbars(*newPos)
def _createMethodVisibilityContainer( self, methodInfoContainer: Sizer) -> BoxSizer: szr2: BoxSizer = BoxSizer(HORIZONTAL) if self._editInterface is False: self._rdbVisibility = RadioBox(self, ID_ANY, "", Point(35, 30), DefaultSize, ["+", "-", "#"], style=RA_SPECIFY_ROWS) szr2.Add(self._rdbVisibility, 0, ALL, 5) szr2.Add(methodInfoContainer, 0, ALIGN_CENTER_VERTICAL | ALL, 5) return szr2
def run(self): next_x = 100 # allow some LHS space for port names layers = self.G.vertices.keys() layers.sort() for i_layer in layers: layer = self.G.vertices[i_layer] next_y = 10 x_hist = [] for block in layer: obj = self.obj_dict[block.get_name()] obj.SetPosition( Point(next_x, next_y) ) (x,y) = obj.getSize() next_y += y + Y_DELTA x_hist.append(x) next_x += max(x_hist) + X_DELTA
def resize_passthrus(self): """ Resize each of the passthrus in each layer. Should match the widest block in that layer """ layers = self.G.vertices.keys() layers.sort() for i_layer in layers: layer = self.G.vertices[i_layer] # find widest object in the layer names = [ block.get_name() for block in layer ] widths = [ self._get_width(name) for name in names ] max_width = max(widths) # set all passthru objects to match widest object dummies = [ name for name in names if block.type == 'dummy' ] for dummy in dummies: obj = self.obj_dict[dummy] obj.endpt = Point(max_width,0)
def __init__(self, dpi=(1, 1)): width = 300 * dpi[0] height = 80 * dpi[1] screenSize = DisplaySize() x = screenSize[0] - width - 10 * dpi[0], y = screenSize[1] - height - 100 * dpi[1] Frame.__init__(self, parent=None, id=ID_ANY, pos=Point(x[0], y), size=Size(width, height), style=SIMPLE_BORDER | TRANSPARENT_WINDOW | STAY_ON_TOP | FRAME_NO_TASKBAR, name=EmptyString) bSizer4 = BoxSizer(VERTICAL) self.msgTitle = StaticText(self, ID_ANY, u"MyLabel", DefaultPosition, DefaultSize, 0) self.msgTitle.Wrap(-1) self.msgTitle.SetFont( Font(13, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_BOLD, False, EmptyString)) bSizer4.Add(self.msgTitle, 0, ALL, 5) self.msgContent = StaticText(self, ID_ANY, u"MyLabel", DefaultPosition, DefaultSize, 0) self.msgContent.Wrap(-1) self.msgContent.SetFont( Font(12, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL, False, EmptyString)) bSizer4.Add(self.msgContent, 0, EXPAND, 5) self.SetSizer(bSizer4) self.Layout() # colorWhite = Colour(255, 255, 255) self.SetBackgroundColour(Colour(240, 240, 240))
def OnScreenshotTimer(self): oldpos = self.Parent.Position try: top = self.Top top.Move((-top.Size.width - 50, -top.Size.height - 50)) wx.BeginBusyCursor() wx.WakeUpIdle() wx.MilliSleep(500) global num_screenshots num_screenshots += 1 log.info('taking screenshot %d', num_screenshots) screen_full, screen = app_windows_image() diag = ScreenshotDialog(self, screen_full, screen, pos=oldpos + Point(40, 40)) except: print_exc() screen = None finally: wx.EndBusyCursor() self.Top.Move(oldpos) if screen is None: return try: if diag.ShowModal() == wx.ID_OK: self.screenshot = diag.SelectedScreenshot self.screenshot_link.Label = _("Remove Screenshot") else: self.screenshot_link.Label = _('Take Screenshot') finally: diag.Destroy() self.Layout() self.Refresh()
def __is_correct_element(self, element, area, location_offset): bad_element_tags = ['option', 'script'] if area: if type(area) not in (tuple, list) or len(area) != 4: raise Exception(u"Bad area data '%s'" % str(area)) area = Rect(*area) x, y = self.browser.get_location(element) if location_offset: # fixing location because it is located inside frame x += location_offset[0] y += location_offset[1] w, h = self.browser.get_dimensions(element) element_center = Point(x + w / 2, y + h / 2) is_element_inside = area.Contains(element_center) else: is_element_inside = True return (self.browser.is_visible(element) and not element.tag_name in bad_element_tags and is_element_inside)
def OnPaint(self, event): dc = AutoBufferedPaintDC(self) rect = RectS(self.Size) self.bg.Draw(dc, rect) # Draw service icon icon = self.licon if self.account.is_connected else self.licon.Greyed dc.DrawBitmapPoint(icon, self.liconpos, True) #The right icon can either be the close icon, the state icon, or nothing #Shows the state icon if the list is in ShowAll or nothing if state is CONNECTING, AUTHENTICATING,INITIALIZING, or LOADING_CONTACT_LIST # Otherwise it shows the close button ricon = self.stateicon if self.Parent.ShowAll else ( self.closeicon[self.buttonstate] if self.account.state not in ShowNothingStates else None) if ricon: rconpos = self.riconpos + Point(8 - ricon.Width // 2, 8 - ricon.Height // 2) dc.DrawBitmapPoint(ricon, rconpos, True) self.buttonshown = bool(ricon) # Draw the account name dc.Font = self.majorfont dc.TextForeground = self.majorfc dc.DrawTruncatedText(self.title, self.titlerect) # Draws the offline reason or state dc.Font = self.minorfont dc.TextForeground = self.statefc if callable(self.reason): self.wrappedreason = Wrap(self.reason(), self.reasonrect.Width, self.minorfont, dc) dc.DrawLabel(self.wrappedreason, self.reasonrect) # Draw the link dc.Font = self.linkfont dc.TextForeground = self.linkfc dc.DrawLabel(self.link, self.linkrect)
def UpdateSkin(self, first=False): s = skin.get('filetransfers') self.normalbg = s.get('backgrounds.normal', [ SkinColor(wx.Color(238, 238, 238)), SkinColor(wx.Color(255, 255, 255)) ]) self.selectedbg = s.get('backgrounds.selected', SkinColor(wx.Color(180, 180, 180))) self.hoveredbg = s.get('backgrounds.hovered', SkinColor(wx.Color(220, 220, 220))) self.padding = s.get('padding', lambda: Point(5, 5)) self.margins = s.get('margins', lambda: skin.ZeroMargins) if not first: with traceguard: self.details.SetFont( skin.get('filetransfers.fonts.other', default_font)) linkfont = skin.get('filetransfers.fonts.link', default_font) for link in self.links.values(): link.SetFont(linkfont) self.layout() self.Refresh(False)
def get_infobox_tray_position(self): #TODO: find taskbar position from the correct HWND. this code assumes the mouse # is on the same display as the tray, and that the tray is on the bottom of the # "client area" rectangle returned by wxDisplay try: import cgui r = cgui.GetTrayRect() pt = Point(r.Right - r.Width / 2, r.Bottom - r.Height / 2) display = Monitor.GetFromPoint(pt, find_near=True) rect = display.GetClientArea() distances = [] for p in ('TopLeft', 'TopRight', 'BottomLeft', 'BottomRight'): corner = getattr(rect, p) distances.append((corner, corner.DistanceTo(pt), p)) distances.sort(key=itemgetter(1)) corner, distance, name = distances[0] return corner except Exception: print_exc() return Monitor.GetFromPointer().ClientArea.BottomRight
def Display(self, caller = None, funnle = True,funnlefullscreen=False): """ Display the menu """ self.BeforeDisplay() if not self.IsShown() and len(self): self.spine.CalcSize() if caller and isinstance(caller, SimpleMenuSpine): self.caller = None rect = caller.GetSelectionRect() position = Point(rect.x+rect.width,rect.y - self.spine.framesize.top) newrect = RectPS(position, self.ScreenRect.Size) screenrect = Monitor.GetFromRect(newrect).Geometry if newrect.bottom > screenrect.bottom: position.y=rect.y+rect.height-self.Size.height if newrect.right > screenrect.right: position.x=rect.x-self.Size.width elif caller: self.caller = caller caller_rect = caller.ScreenRect position = caller_rect.BottomLeft newrect = RectPS(position, self.ScreenRect.Size) screenrect = Monitor.GetFromWindow(caller).Geometry if newrect.bottom > screenrect.bottom: position.y -= caller_rect.Height + self.spine.Size.height if newrect.right > screenrect.right: position.x += caller_rect.Width - self.spine.Size.width else: self.caller = None position = wx.GetMousePosition() newrect = RectPS(position, self.ScreenRect.Size) screenrect = Monitor.GetFromPoint(position).Geometry if newrect.bottom > screenrect.bottom: position.y -= self.spine.Size.height if newrect.right > screenrect.right and pref('menus.shift_mode', False): position.x -= self.spine.Size.width newrect = wx.RectPS(position,self.Size) screenrect = Monitor.GetFromRect(newrect).Geometry pos = screenrect.Clamp(newrect).Position if funnle else position self.SetRect(RectPS(pos, self.Size)) self.spine.SetSelection(-1) fadein(self, 'xfast') self.spine.RefreshAll() if not self.spine.HasCapture(): self.spine.CaptureMouse() wx.CallLater(10, self.Refresh) if not isinstance(caller, SimpleMenuSpine): self.TopConnect()