def __init__(self, parent, **traits): """ Creates a new widget. """ # Base class constructors. super(ImageWidget, self).__init__(**traits) # Add some padding around the image. size = (self.bitmap.GetWidth() + 10, self.bitmap.GetHeight() + 10) # Create the toolkit-specific control. self.control = wx.Window(parent, -1, size=size) self.control.__tag__ = 'hack' self._mouse_over = False self._button_down = False # Set up mouse event handlers: wx.EVT_ENTER_WINDOW(self.control, self._on_enter_window) wx.EVT_LEAVE_WINDOW(self.control, self._on_leave_window) wx.EVT_LEFT_DCLICK(self.control, self._on_left_dclick) wx.EVT_LEFT_DOWN(self.control, self._on_left_down) wx.EVT_LEFT_UP(self.control, self._on_left_up) wx.EVT_PAINT(self.control, self._on_paint) # Pens used to draw the 'selection' marker: # ZZZ: Make these class instances when moved to the wx toolkit code. self._selectedPenDark = wx.Pen( wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DSHADOW), 1, wx.SOLID) self._selectedPenLight = wx.Pen( wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DHIGHLIGHT), 1, wx.SOLID) return
def __init__(self, parent, ID, label, url): wx.Panel.__init__(self, parent, ID) self.url = url self.text_bg = wx.Panel(self) self.text = wx.StaticText(self.text_bg, label=label) self.clicked = False self.FONT_DEFAULT = self.text.GetFont() self.FONT_HIGHLIGHT = self.text.GetFont() self.FONT_HIGHLIGHT.SetUnderlined(True) wx.EVT_LEFT_DOWN(self.text, self.OnLeftClick) wx.EVT_ENTER_WINDOW(self.text_bg, self.OnMouseOver) wx.EVT_LEAVE_WINDOW(self.text_bg, self.OnMouseOut) self.text.SetForegroundColour(wx.Colour(0, 0, 255)) layout_V1 = BoxSizer(wx.VERTICAL) layout_V1.AddSpacer(1, wx.EXPAND) layout_V1.Add(self.text_bg, 0, wx.ALIGN_CENTER) layout_V1.AddSpacer(1, wx.EXPAND) self.SetAutoLayout(True) self.SetSizer(layout_V1) self.Layout()
def __init__(self, parent, id, attr=DefaultCalendarCellAttributes, style=wx.SIMPLE_BORDER): wx.PyWindow.__init__(self, parent, id, style=style | wx.WANTS_CHARS | wx.FULL_REPAINT_ON_RESIZE) self.attr = GetCalendarCellAttributes(attr) self.day = 33 self.year = 2033 self.month = 3 self.buffer = None self.needsupdate = True self.entries = () self._tipwindow = None wx.EVT_PAINT(self, self.OnPaint) wx.EVT_SIZE(self, self.OnSize) wx.EVT_ENTER_WINDOW(self, self.OnEnterWindow) wx.EVT_LEAVE_WINDOW(self, self.OnLeaveWindow) self._timer = wx.Timer(self) wx.EVT_TIMER(self, self._timer.GetId(), self.OnTimer) self.OnSize(None)
def SetTreeCtrl(self, tree): self.SetControl(tree) wx.EVT_TREE_SEL_CHANGED(self.GetControl(), self.GetControl().GetId(), self.DoSelection) wx.EVT_ENTER_WINDOW(self.GetControl(), treeCtrl.CallDoLoadOutlineCallback) wx.EVT_RIGHT_DOWN(self.GetControl(), self.OnRightClick)
def __init__(self, parent, bitmap, selected=None, handler=None, padding=10): """ Initializes the object. """ wx.Window.__init__(self, parent, -1, size=wx.Size(bitmap.GetWidth() + padding, bitmap.GetHeight() + padding)) self._bitmap = bitmap self._selected = selected self._handler = handler self._mouse_over = False self._button_down = False # Set up the 'paint' event handler: wx.EVT_PAINT(self, self._on_paint) # Set up mouse event handlers: wx.EVT_LEFT_DOWN(self, self._on_left_down) wx.EVT_LEFT_UP(self, self._on_left_up) wx.EVT_ENTER_WINDOW(self, self._on_enter) wx.EVT_LEAVE_WINDOW(self, self._on_leave)
def __init__(self, wxWidget): """Constructor. @param wxWidget The wxWidget this Widget manages. """ self.wxWidget = wxWidget self.menuItems = None self.focusId = '' self.menuId = None # Callback functions for listening directly to changes. self.reactors = [] self.setNormalStyle() # Listen for right mouse clicks in case a popup menu should be # displayed. wx.EVT_RIGHT_DOWN(wxWidget, self.onRightClick) wx.EVT_RIGHT_UP(wxWidget, self.onRightClick) # A notification is sent when the widget is entered. wx.EVT_ENTER_WINDOW(wxWidget, self.onEnterWidget) # Listen for focus changes. wx.EVT_SET_FOCUS(wxWidget, self.onFocus) # Register a notification listener. These notifications are expected # to be handled by all widgets. events.addNotifyListener(self.onNotify, ['language-changed', 'focus-request'])
def _on_close(self, event): # Might be scrollbars or other native components under # us that are generating this event if event.GetWindow() == self.control: self._gc = None wx.EVT_ERASE_BACKGROUND(self.control, None) wx.EVT_PAINT(self.control, None) wx.EVT_SIZE(self.control, None) wx.EVT_LEFT_DOWN(self.control, None) wx.EVT_LEFT_UP(self.control, None) wx.EVT_LEFT_DCLICK(self.control, None) wx.EVT_MIDDLE_DOWN(self.control, None) wx.EVT_MIDDLE_UP(self.control, None) wx.EVT_MIDDLE_DCLICK(self.control, None) wx.EVT_RIGHT_DOWN(self.control, None) wx.EVT_RIGHT_UP(self.control, None) wx.EVT_RIGHT_DCLICK(self.control, None) wx.EVT_MOTION(self.control, None) wx.EVT_ENTER_WINDOW(self.control, None) wx.EVT_LEAVE_WINDOW(self.control, None) wx.EVT_MOUSEWHEEL(self.control, None) wx.EVT_KEY_DOWN(self.control, None) wx.EVT_KEY_UP(self.control, None) wx.EVT_CHAR(self.control, None) wx.EVT_WINDOW_DESTROY(self.control, None) self.control.SetDropTarget(None) self.control = None self.component.cleanup(self) self.component.parent = None self.component.window = None self.component = None return
def _CreateControl(self, parent, id): treeCtrl = OutlineTreeCtrl(parent, id) wx.EVT_TREE_SEL_CHANGED(treeCtrl, treeCtrl.GetId(), self.DoSelection) wx.EVT_SET_FOCUS(treeCtrl, self.DoSelection) wx.EVT_ENTER_WINDOW(treeCtrl, treeCtrl.CallDoLoadOutlineCallback) wx.EVT_RIGHT_DOWN(treeCtrl, self.OnRightClick) return treeCtrl
def show(self): """ Shows the feature bar. """ # Make sure all prerequisites are met: dock_control, parent = self.dock_control, self.parent if (dock_control is None) or (parent is None): return # Create the actual control (if needed): control = self.control if control is None: self.control = control = wx.Frame(None, -1, '', style=wx.BORDER_NONE) # Set up the 'erase background' event handler: wx.EVT_ERASE_BACKGROUND(control, self._erase_background) # Set up the 'paint' event handler: wx.EVT_PAINT(control, self._paint) # Set up mouse event handlers: wx.EVT_LEFT_DOWN(control, self._left_down) wx.EVT_LEFT_UP(control, self._left_up) wx.EVT_RIGHT_DOWN(control, self._right_down) wx.EVT_RIGHT_UP(control, self._right_up) wx.EVT_MOTION(control, self._mouse_move) wx.EVT_ENTER_WINDOW(control, self._mouse_enter) control.SetDropTarget(PythonDropTarget(self)) # Calculate the best size and position for the feature bar: size = wx.Size(32, 32) width = height = 0 horizontal = self.horizontal for feature in dock_control.active_features: bitmap = feature.bitmap if bitmap is not None: if horizontal: width += (bitmap.GetWidth() + 3) height = max(height, bitmap.GetHeight()) else: width = max(width, bitmap.GetWidth()) height += (bitmap.GetHeight() + 3) if width > 0: if horizontal: size = wx.Size(width + 5, height + 8) else: size = wx.Size(width + 8, height + 5) control.SetSize(size) px, py = parent.GetScreenPosition() fx, fy = dock_control.feature_popup_position control.SetPosition(wx.Point(px + fx, py + fy)) control.Show()
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ factory = self.factory # Establish the range of the slider: low, high = factory.low, factory.high if high <= low: low = high = None range = self.object.trait(self.name).handler if isinstance(range, Range): low, high = range._low, range._high if low is None: if high is None: high = 1.0 low = high - 1.0 elif high is None: high = low + 1.0 # Establish the slider increment: increment = factory.increment if increment <= 0.0: if isinstance(low, int): increment = 1.0 else: increment = pow(10, int(log10((high - low) / 1000.0))) # Save the values we calculated: self.set(low=low, high=high, increment=increment) # Create the control: self.control = control = wx.Window(parent, -1, size=wx.Size(70, 20), style=wx.FULL_REPAINT_ON_RESIZE | wx.TAB_TRAVERSAL) # Set up the painting event handlers: wx.EVT_ERASE_BACKGROUND(control, self._erase_background) wx.EVT_PAINT(control, self._on_paint) wx.EVT_SET_FOCUS(control, self._set_focus) # Set up mouse event handlers: wx.EVT_LEFT_DOWN(control, self._left_down) wx.EVT_LEFT_UP(control, self._left_up) wx.EVT_MOTION(control, self._motion) wx.EVT_MOUSEWHEEL(control, self._mouse_wheel) wx.EVT_ENTER_WINDOW(control, self._enter_window) wx.EVT_LEAVE_WINDOW(control, self._leave_window) # Set up the control resize handler: wx.EVT_SIZE(control, self._resize) # Set the tooltip: if not self.set_tooltip(): control.SetToolTipString('[%g..%g]' % (low, high))
def __init__(self, parent, label, whotocall, whotonotify, msg, style): """Expects reference to 'ButtonColumn', list of labels for buttons and list of functions to be called for OnClick events""" id = wx.NewId() wx.TextCtrl.__init__(self, parent, id, style=style) self.whotocall = whotocall self.whotonotify = whotonotify self.msg = msg wx.EVT_BUTTON(self, id, self.OnClick) wx.EVT_ENTER_WINDOW(self, self.OnEnter) wx.EVT_LEAVE_WINDOW(self, self.OnLeave)
def _create_control(self, parent): """ Create the toolkit-specific control that represents the widget. """ collapsed_carat = self.collapsed_carat_image.create_image() self._collapsed_bmp = collapsed_carat.ConvertToBitmap() self._carat_w = self._collapsed_bmp.GetWidth() expanded_carat = self.expanded_carat_image.create_image() self._expanded_bmp = expanded_carat.ConvertToBitmap() header_bar = self.header_bar_image.create_image() self._header_bmp = header_bar.ConvertToBitmap() header_bar_over = self.header_mouseover_image.create_image() self._header_mouseover_bmp = header_bar_over.ConvertToBitmap() self._background_bmp = self._header_bmp close_image = self.remove_image.create_image() self._remove_bmp = close_image.ConvertToBitmap() # create our panel and initialize it appropriately sizer = wx.BoxSizer(wx.VERTICAL) panel = wx.Panel(parent, -1, style=wx.CLIP_CHILDREN) panel.SetSizer(sizer) panel.SetAutoLayout(True) # needed on GTK systems for EVT_ERASE_BACKGROUND to work panel.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) # create the remove button remove = wx.BitmapButton(panel, -1, self._remove_bmp, style=0, pos=(-1, 3)) sizer.Add(remove, 0, wx.ALIGN_RIGHT, 5) # Create a suitable font. self._font = new_font_like(wx.NORMAL_FONT, point_size=wx.NORMAL_FONT.GetPointSize() - 1) height = self._get_preferred_height(parent, self.title, self._font) panel.SetSize((-1, height)) wx.EVT_ERASE_BACKGROUND(panel, self._on_erase_background) wx.EVT_ENTER_WINDOW(panel, self._on_enter_leave) wx.EVT_LEAVE_WINDOW(panel, self._on_enter_leave) wx.EVT_LEFT_DOWN(panel, self._on_down) wx.EVT_RIGHT_DOWN(panel, self._on_down) wx.EVT_BUTTON(panel, remove.GetId(), self._on_remove) return panel
def dispose(self): """ Disposes of the contents of an editor. """ if self.factory.view is not None: control = self.control wx.EVT_ENTER_WINDOW(control, None) wx.EVT_LEAVE_WINDOW(control, None) wx.EVT_LEFT_DOWN(control, None) wx.EVT_LEFT_UP(control, None) super(ReadonlyEditor, self).dispose()
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ super(ReadonlyEditor, self).init(parent) if self.factory.view is not None: control = self.control wx.EVT_ENTER_WINDOW(control, self._enter_window) wx.EVT_LEAVE_WINDOW(control, self._leave_window) wx.EVT_LEFT_DOWN(control, self._left_down) wx.EVT_LEFT_UP(control, self._left_up)
def init_keys(self, parent=None): """ Sets events and variables for parent. If no parent is defined then self is assumed to be parent. """ if parent == None: parent = self self.key_pressed = '' # string code of currently pressed key wx.EVT_ENTER_WINDOW(self, self.on_enter_window) wx.EVT_KEY_DOWN(self, self.on_key_down) wx.EVT_KEY_UP(self, self.on_key_up)
def create_widget(self): self.widget = wx.ScrolledWindow(self.parent.widget, self.id, style=0) wx.EVT_ENTER_WINDOW(self.widget, self.on_enter) self.widget.GetBestSize = self.get_widget_best_size if self.sizer.is_virtual(): def GetBestSize(): if self.widget and self.widget.GetSizer(): return self.widget.GetSizer().GetMinSize() #return wx.Panel.GetBestSize(self.widget) return wx.ScrolledWindow.GetBestSize(self.widget) self.widget.GetBestSize = GetBestSize
def __init__(self, parent, **traits): """ Creates a new image control. """ self._image = None super(ImageButton, self).__init__(**traits) # Calculate the size of the button: idx = idy = tdx = tdy = 0 if self._image is not None: idx = self._image.GetWidth() idy = self._image.GetHeight() if self.label != '': dc = wx.ScreenDC() dc.SetFont(wx.NORMAL_FONT) tdx, tdy = dc.GetTextExtent(self.label) wp2 = self.width_padding + 2 hp2 = self.height_padding + 2 if self.orientation == 'horizontal': self._ix = wp2 spacing = (idx > 0) * (tdx > 0) * 4 self._tx = self._ix + idx + spacing dx = idx + tdx + spacing dy = max(idy, tdy) self._iy = hp2 + ((dy - idy) / 2) self._ty = hp2 + ((dy - tdy) / 2) else: self._iy = hp2 spacing = (idy > 0) * (tdy > 0) * 2 self._ty = self._iy + idy + spacing dx = max(idx, tdx) dy = idy + tdy + spacing self._ix = wp2 + ((dx - idx) / 2) self._tx = wp2 + ((dx - tdx) / 2) # Create the toolkit-specific control: self._dx = dx + wp2 + wp2 self._dy = dy + hp2 + hp2 self.control = wx.Window(parent, -1, size=wx.Size(self._dx, self._dy)) self.control._owner = self self._mouse_over = self._button_down = False # Set up mouse event handlers: wx.EVT_ENTER_WINDOW(self.control, self._on_enter_window) wx.EVT_LEAVE_WINDOW(self.control, self._on_leave_window) wx.EVT_LEFT_DOWN(self.control, self._on_left_down) wx.EVT_LEFT_UP(self.control, self._on_left_up) wx.EVT_PAINT(self.control, self._on_paint)
def finish_widget_creation(self, *args, **kwds): WindowBase.finish_widget_creation(self) self.widget.SetMinSize = self.widget.SetSize if self.has_title: self.widget.SetTitle(misc.design_title(self.title)) elif hasattr(self.widget, 'SetTitle'): self.widget.SetTitle(misc.design_title(self.name)) wx.EVT_LEFT_DOWN(self.widget, self.drop_sizer) wx.EVT_ENTER_WINDOW(self.widget, self.on_enter) wx.EVT_CLOSE(self.widget, self.hide_widget) if wx.Platform == '__WXMSW__': # MSW isn't smart enough to avoid overlapping windows, so at least move it away from the 3 wxGlade frames self.widget.Center() # ALB 2004-10-15 self.widget.SetAcceleratorTable(common.palette.accel_table)
def __init__(self, parent, label, whotocall, whotonotify, msg, image1): """Expects reference to 'ButtonColumn', list of labels for buttons and list of functions to be called for OnClick events""" id = wx.NewId() wx.BitmapButton.__init__(self, parent, id, bitmap=image1, size=(image1.GetWidth() + 6, image1.GetHeight() + 6)) self.whotocall = whotocall self.whotonotify = whotonotify self.msg = msg wx.EVT_BUTTON(self, id, self.OnClick) wx.EVT_ENTER_WINDOW(self, self.OnEnter) wx.EVT_LEAVE_WINDOW(self, self.OnLeave)
def __init__(self,parent): x,y,w,h = self.CalcSizePos(parent) wx.Window.__init__(self,id = -1,parent = parent, pos = wxPoint(x,y), size = wx.Size(w,h), style = wx.CLIP_CHILDREN) self.down = False self.entered = False wx.EVT_LEFT_DOWN(self,self.OnPress) wx.EVT_LEFT_UP(self,self.OnRelease) wx.EVT_PAINT(self,self.OnPaint) wx.EVT_LEAVE_WINDOW(self,self.OnLeave) wx.EVT_ENTER_WINDOW(self,self.OnEnter)
def _pop_up_text(self): control = self.control self._text = text = wx.TextCtrl( control, -1, str(self.value), size=control.GetSize(), style=self.text_styles[self.factory.alignment] | wx.TE_PROCESS_ENTER) text.SetSelection(-1, -1) text.SetFocus() wx.EVT_TEXT_ENTER(control, text.GetId(), self._text_completed) wx.EVT_KILL_FOCUS(text, self._text_completed) wx.EVT_ENTER_WINDOW(text, self._enter_text) wx.EVT_LEAVE_WINDOW(text, self._leave_text) wx.EVT_CHAR(text, self._key_entered)
def _pop_up_text(self): """ Pop-up a text control to allow the user to enter a value using the keyboard. """ control = self.control self._text = text = wx.TextCtrl(control, -1, self.text, size=control.GetSize(), style=self.text_styles[self.factory.alignment] | wx.TE_PROCESS_ENTER) text.SetSelection(-1, -1) text.SetFocus() wx.EVT_TEXT_ENTER(control, text.GetId(), self._text_completed) wx.EVT_KILL_FOCUS(text, self._text_completed) wx.EVT_ENTER_WINDOW(text, self._enter_text) wx.EVT_LEAVE_WINDOW(text, self._leave_text) wx.EVT_CHAR(text, self._key_entered)
def create_widget(self): win = wx.Frame(common.palette, -1, misc.design_title(self.name), size=(400, 300)) import os icon = wx.EmptyIcon() xpm = os.path.join(common.wxglade_path, 'icons', 'panel.xpm') icon.CopyFromBitmap(misc.get_xpm_bitmap(xpm)) win.SetIcon(icon) #self.widget = wx.Panel(win, self.id, style=0) self.widget = wx.ScrolledWindow(win, self.id, style=0) wx.EVT_ENTER_WINDOW(self.widget, self.on_enter) self.widget.GetBestSize = self.get_widget_best_size #self.widget.SetSize = win.SetSize wx.EVT_CLOSE(win, self.hide_widget) if wx.Platform == '__WXMSW__': win.CentreOnScreen()
def __init__(self,parent,side): self.side = side x,y,w,h = self.CalcSizePos(parent) wx.Window.__init__(self,id = -1,parent = parent, pos = wxPoint(x,y), size = wx.Size(w,h), style = wx.CLIP_CHILDREN) self.px = None # Previous X self.py = None # Previous Y self.isDrag = False # In Dragging wx.EVT_LEAVE_WINDOW(self,self.OnLeave) wx.EVT_ENTER_WINDOW(self,self.OnEnter) wx.EVT_MOTION(self,self.OnMouseMove) wx.EVT_LEFT_DOWN(self,self.OnPress) wx.EVT_LEFT_UP(self,self.OnRelease) wx.EVT_PAINT(self,self.OnPaint)
def __init__(self, config, calls): self.config = config self.calls = calls self.cancelflag = threading.Event() self.switchlock = threading.Lock() self.working = False self.queue = [] wx.InitAllImageHandlers() self.thostselection = self.calls['getCurrentTHost']() self.thostselectnum = 0 self.choices = None self.choices1 = None self.announce = '' self.announce_list = None self.windowStyle = wx.SYSTEM_MENU | wx.CAPTION | wx.MINIMIZE_BOX if self.config['stayontop']: self.windowStyle |= wx.STAY_ON_TOP frame = wx.Frame(None, -1, 'T-Make', size=wx.Size(-1, -1), style=self.windowStyle) self.frame = frame panel = wx.Panel(frame, -1) mainSizer = wx.BoxSizer(wx.VERTICAL) groupSizer = wx.FlexGridSizer(cols=1, vgap=0, hgap=0) # self.dropTarget = self.calls['newDropTarget']((200, 200)) self.dropTarget = self.calls['newDropTarget']() self.dropTargetPtr = wx.StaticBitmap(panel, -1, self.dropTarget) self.calls['setDropTargetRefresh'](self.dropTargetPtr.Refresh) self.dropTargetWidth = self.dropTarget.GetWidth() wx.EVT_LEFT_DOWN(self.dropTargetPtr, self.dropTargetClick) wx.EVT_ENTER_WINDOW(self.dropTargetPtr, self.calls['dropTargetHovered']) wx.EVT_LEAVE_WINDOW(self.dropTargetPtr, self.calls['dropTargetUnhovered']) groupSizer.Add(self.dropTargetPtr, 0, wx.ALIGN_CENTER) lowerSizer1 = wx.GridSizer(cols=6) dirlink = wx.StaticText(panel, -1, 'dir') dirlink.SetFont(wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.NORMAL, True)) dirlink.SetForegroundColour('blue') wx.EVT_LEFT_UP(dirlink, self.selectdir) lowerSizer1.Add(dirlink, -1, wx.ALIGN_LEFT) lowerSizer1.Add(wx.StaticText(panel, -1, ''), -1, wx.ALIGN_CENTER) lowerSizer1.Add(wx.StaticText(panel, -1, ''), -1, wx.ALIGN_CENTER) lowerSizer1.Add(wx.StaticText(panel, -1, ''), -1, wx.ALIGN_CENTER) lowerSizer1.Add(wx.StaticText(panel, -1, ''), -1, wx.ALIGN_CENTER) filelink = wx.StaticText(panel, -1, 'file') filelink.SetFont(wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.NORMAL, True)) filelink.SetForegroundColour('blue') wx.EVT_LEFT_UP(filelink, self.selectfile) lowerSizer1.Add(filelink, -1, wx.ALIGN_RIGHT) groupSizer.Add(lowerSizer1, -1, wx.ALIGN_CENTER) self.gauge = wx.Gauge(panel, -1, range=1000, style=wx.GA_HORIZONTAL, size=(-1, 15)) groupSizer.Add(self.gauge, 0, wx.EXPAND) self.statustext = wx.StaticText(panel, -1, 'ready', style=wx.ALIGN_CENTER | wx.ST_NO_AUTORESIZE) self.statustext.SetFont( wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.BOLD, False)) groupSizer.Add(self.statustext, -1, wx.EXPAND) self.choices = wx.Choice(panel, -1, (-1, -1), (self.dropTargetWidth, -1), choices=[]) self.choices.SetFont( wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False)) wx.EVT_CHOICE(self.choices, -1, self.set_thost) groupSizer.Add(self.choices, 0, wx.EXPAND) cancellink = wx.StaticText(panel, -1, 'cancel') cancellink.SetFont(wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.NORMAL, True)) cancellink.SetForegroundColour('red') wx.EVT_LEFT_UP(cancellink, self.cancel) groupSizer.Add(cancellink, -1, wx.ALIGN_CENTER) advlink = wx.StaticText(panel, -1, 'advanced') advlink.SetFont(wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.NORMAL, True)) advlink.SetForegroundColour('blue') wx.EVT_LEFT_UP(advlink, self.calls['switchToAdvanced']) groupSizer.Add(advlink, -1, wx.ALIGN_CENTER) mainSizer.Add(groupSizer, 0, wx.ALIGN_CENTER) self.refresh_thostlist() self._set_thost() if sys.platform == 'win32': self.dropTargetPtr.DragAcceptFiles(True) wx.EVT_DROP_FILES(self.dropTargetPtr, self.selectdrop) # border = wxBoxSizer(wxHORIZONTAL) # border.Add(mainSizer, 1, wxEXPAND | wxALL, 0) panel.SetSizer(mainSizer) panel.SetAutoLayout(True) # border.Fit(panel) mainSizer.Fit(panel) frame.Fit() frame.Show(True) super(BasicDownloadInfo, self).__init__(frame) wx.EVT_CLOSE(frame, self._close)
def __init__(self, parent, wid=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, **traits): AbstractWindow.__init__(self, **traits) self._timer = None self._mouse_captured = False # Due to wx wonkiness, we don't reliably get cursor position from # a wx KeyEvent. Thus, we manually keep track of when we last saw # the mouse and use that information instead. These coordinates are # in the wx coordinate space, i.e. pre-self._flip_y(). self._last_mouse_pos = (0, 0) # Create the delegate: self.control = control = self._create_control(parent, wid, pos, size) # Set up the 'erase background' event handler: wx.EVT_ERASE_BACKGROUND(control, self._on_erase_background) # Set up the 'paint' event handler: wx.EVT_PAINT(control, self._paint) wx.EVT_SIZE(control, self._on_size) # Set up mouse event handlers: wx.EVT_LEFT_DOWN(control, self._on_left_down) wx.EVT_LEFT_UP(control, self._on_left_up) wx.EVT_LEFT_DCLICK(control, self._on_left_dclick) wx.EVT_MIDDLE_DOWN(control, self._on_middle_down) wx.EVT_MIDDLE_UP(control, self._on_middle_up) wx.EVT_MIDDLE_DCLICK(control, self._on_middle_dclick) wx.EVT_RIGHT_DOWN(control, self._on_right_down) wx.EVT_RIGHT_UP(control, self._on_right_up) wx.EVT_RIGHT_DCLICK(control, self._on_right_dclick) wx.EVT_MOTION(control, self._on_mouse_move) wx.EVT_ENTER_WINDOW(control, self._on_window_enter) wx.EVT_LEAVE_WINDOW(control, self._on_window_leave) wx.EVT_MOUSEWHEEL(control, self._on_mouse_wheel) # Handle key up/down events: wx.EVT_KEY_DOWN(control, self._on_key_pressed) wx.EVT_KEY_UP(control, self._on_key_released) wx.EVT_CHAR(control, self._on_character) # Attempt to allow wxPython drag and drop events to be mapped to # Enable drag events: # Handle window close and cleanup wx.EVT_WINDOW_DESTROY(control, self._on_close) if PythonDropTarget is not None: control.SetDropTarget(LessSuckyDropTarget(self)) self._drag_over = [] # In some cases, on the Mac at least, we never get an initial EVT_SIZE # since the initial size is correct. Because of this we call _on_size # here to initialize our bounds. self._on_size(None) return
def __init__(self, config, calls): self.config = config self.calls = calls self.cancelflag = threading.Event() self.switchlock = threading.Lock() self.working = False self.queue = [] wx.InitAllImageHandlers() self.thostselection = self.calls['getCurrentTHost']() self.thostselectnum = 0 self.choices = None self.choices1 = None self.windowStyle = wx.SYSTEM_MENU | wx.CAPTION | wx.MINIMIZE_BOX if self.config['stayontop']: self.windowStyle |= wx.STAY_ON_TOP frame = wx.Frame(None, -1, 'T-Make', size=wx.Size(-1, -1), style=self.windowStyle) self.frame = frame panel = wx.Panel(frame, -1) fullSizer = wx.FlexGridSizer(cols=1, vgap=0, hgap=8) colSizer = wx.FlexGridSizer(cols=2, vgap=0, hgap=8) leftSizer = wx.FlexGridSizer(cols=1, vgap=3) self.stayontop_checkbox = wx.CheckBox(panel, -1, "stay on top") self.stayontop_checkbox.SetValue(self.config['stayontop']) wx.EVT_CHECKBOX(frame, self.stayontop_checkbox.GetId(), self.setstayontop) leftSizer.Add(self.stayontop_checkbox, -1, wx.ALIGN_CENTER) leftSizer.Add(wx.StaticText(panel, -1, '')) button = wx.Button(panel, -1, 'use image...') wx.EVT_BUTTON(frame, button.GetId(), self.selectDropTarget) leftSizer.Add(button, -1, wx.ALIGN_CENTER) self.groupSizer1Box = wx.StaticBox(panel, -1, '') groupSizer1 = wx.StaticBoxSizer(self.groupSizer1Box, wx.HORIZONTAL) groupSizer = wx.FlexGridSizer(cols=1, vgap=0) self.dropTarget = self.calls['newDropTarget']((200, 200)) # self.dropTarget = self.calls['newDropTarget']() self.dropTargetPtr = wx.StaticBitmap(panel, -1, self.dropTarget) self.calls['setDropTargetRefresh'](self.dropTargetPtr.Refresh) self.dropTargetWidth = self.dropTarget.GetWidth() wx.EVT_LEFT_DOWN(self.dropTargetPtr, self.dropTargetClick) wx.EVT_ENTER_WINDOW(self.dropTargetPtr, self.calls['dropTargetHovered']) wx.EVT_LEAVE_WINDOW(self.dropTargetPtr, self.calls['dropTargetUnhovered']) groupSizer.Add(self.dropTargetPtr, 0, wx.ALIGN_CENTER) lowerSizer1 = wx.GridSizer(cols=3) dirlink = wx.StaticText(panel, -1, 'dir') dirlink.SetFont(wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.NORMAL, True)) dirlink.SetForegroundColour('blue') wx.EVT_LEFT_UP(dirlink, self.selectdir) lowerSizer1.Add(dirlink, -1, wx.ALIGN_LEFT) lowerSizer1.Add(wx.StaticText(panel, -1, ''), -1, wx.ALIGN_CENTER) filelink = wx.StaticText(panel, -1, 'file') filelink.SetFont(wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.NORMAL, True)) filelink.SetForegroundColour('blue') wx.EVT_LEFT_UP(filelink, self.selectfile) lowerSizer1.Add(filelink, -1, wx.ALIGN_RIGHT) groupSizer.Add(lowerSizer1, -1, wx.ALIGN_CENTER) self.gauge = wx.Gauge(panel, -1, range=1000, style=wx.GA_HORIZONTAL, size=(-1, 15)) groupSizer.Add(self.gauge, 0, wx.EXPAND) self.statustext = wx.StaticText(panel, -1, 'ready', style=wx.ALIGN_CENTER | wx.ST_NO_AUTORESIZE) self.statustext.SetFont( wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.BOLD, False)) groupSizer.Add(self.statustext, -1, wx.EXPAND) self.choices = wx.Choice(panel, -1, (-1, -1), (self.dropTargetWidth, -1), choices=[]) self.choices.SetFont( wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False)) wx.EVT_CHOICE(self.choices, -1, self.set_thost) groupSizer.Add(self.choices, 0, wx.EXPAND) cancellink = wx.StaticText(panel, -1, 'cancel') cancellink.SetFont(wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.NORMAL, True)) cancellink.SetForegroundColour('red') wx.EVT_LEFT_UP(cancellink, self.cancel) groupSizer.Add(cancellink, -1, wx.ALIGN_CENTER) dummyadvlink = wx.StaticText(panel, -1, 'advanced') dummyadvlink.SetFont( wx.Font(7, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False)) dummyadvlink.SetForegroundColour('blue') wx.EVT_LEFT_UP(dirlink, self.selectdir) groupSizer.Add(dummyadvlink, -1, wx.ALIGN_CENTER) groupSizer1.Add(groupSizer) leftSizer.Add(groupSizer1, -1, wx.ALIGN_CENTER) leftSizer.Add(wx.StaticText(panel, -1, 'make torrent of:'), 0, wx.ALIGN_CENTER) self.dirCtl = wx.TextCtrl(panel, -1, '', size=(250, -1)) leftSizer.Add(self.dirCtl, 1, wx.EXPAND) b = wx.BoxSizer(wx.HORIZONTAL) button = wx.Button(panel, -1, 'dir') wx.EVT_BUTTON(frame, button.GetId(), self.selectdir) b.Add(button, 0) button2 = wx.Button(panel, -1, 'file') wx.EVT_BUTTON(frame, button2.GetId(), self.selectfile) b.Add(button2, 0) leftSizer.Add(b, 0, wx.ALIGN_CENTER) leftSizer.Add(wx.StaticText(panel, -1, '')) simple_link = wx.StaticText(panel, -1, 'back to basic mode') simple_link.SetFont(wx.Font(-1, wx.DEFAULT, wx.NORMAL, wx.NORMAL, True)) simple_link.SetForegroundColour('blue') wx.EVT_LEFT_UP(simple_link, self.calls['switchToBasic']) leftSizer.Add(simple_link, -1, wx.ALIGN_CENTER) colSizer.Add(leftSizer, -1, wx.ALIGN_CENTER_VERTICAL) gridSizer = wx.FlexGridSizer(cols=2, vgap=6, hgap=8) gridSizer.Add(wx.StaticText(panel, -1, 'Torrent host:'), -1, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) self.choices1 = wx.Choice(panel, -1, (-1, -1), (-1, -1), choices=[]) wx.EVT_CHOICE(self.choices1, -1, self.set_thost1) gridSizer.Add(self.choices1, 0, wx.EXPAND) b = wx.BoxSizer(wx.HORIZONTAL) button1 = wx.Button(panel, -1, 'set default') wx.EVT_BUTTON(frame, button1.GetId(), self.set_default_thost) b.Add(button1, 0) b.Add(wx.StaticText(panel, -1, ' ')) button2 = wx.Button(panel, -1, 'delete') wx.EVT_BUTTON(frame, button2.GetId(), self.delete_thost) b.Add(button2, 0) b.Add(wx.StaticText(panel, -1, ' ')) button3 = wx.Button(panel, -1, 'save as...') wx.EVT_BUTTON(frame, button3.GetId(), self.save_thost) b.Add(button3, 0) gridSizer.Add(wx.StaticText(panel, -1, '')) gridSizer.Add(b, 0, wx.ALIGN_CENTER) gridSizer.Add(wx.StaticText(panel, -1, '')) gridSizer.Add(wx.StaticText(panel, -1, '')) gridSizer.Add(wx.StaticText(panel, -1, 'single tracker url:'), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) self.annCtl = wx.TextCtrl(panel, -1, 'http://my.tracker:6969/announce') gridSizer.Add(self.annCtl, 0, wx.EXPAND) a = wx.FlexGridSizer(cols=1, vgap=3) a.Add(wx.StaticText(panel, -1, 'tracker list:'), 0, wx.ALIGN_RIGHT) a.Add(wx.StaticText(panel, -1, '')) abutton = wx.Button(panel, -1, 'copy\nannounces\nfrom\ntorrent', size=(70, 70)) wx.EVT_BUTTON(frame, abutton.GetId(), self.announcecopy) a.Add(abutton, -1, wx.ALIGN_CENTER) a.Add(wx.StaticText(panel, -1, DROP_HERE), -1, wx.ALIGN_CENTER) gridSizer.Add(a, -1, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) self.annListCtl = wx.TextCtrl( panel, -1, '\n', wx.Point(-1, -1), (300, 120), wx.TE_MULTILINE | wx.HSCROLL | wx.TE_DONTWRAP) gridSizer.Add(self.annListCtl, -1, wx.EXPAND) gridSizer.Add(wx.StaticText(panel, -1, '')) exptext = wx.StaticText( panel, -1, 'a list of tracker urls separated ' 'by commas or whitespace\nand on several ' 'lines -trackers on the same line will be\n' 'tried randomly, and all the trackers on one ' 'line\nwill be tried before the trackers on ' 'the next line.') exptext.SetFont(wx.Font(6, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False)) gridSizer.Add(exptext, -1, wx.ALIGN_CENTER) self.refresh_thostlist() self._set_thost() if sys.platform == 'win32': self.dropTargetPtr.DragAcceptFiles(True) wx.EVT_DROP_FILES(self.dropTargetPtr, self.selectdrop) self.groupSizer1Box.DragAcceptFiles(True) wx.EVT_DROP_FILES(self.groupSizer1Box, self.selectdrop) abutton.DragAcceptFiles(True) wx.EVT_DROP_FILES(abutton, self.announcedrop) self.annCtl.DragAcceptFiles(True) wx.EVT_DROP_FILES(self.annCtl, self.announcedrop) self.annListCtl.DragAcceptFiles(True) wx.EVT_DROP_FILES(self.annListCtl, self.announcedrop) gridSizer.Add(wx.StaticText(panel, -1, '')) gridSizer.Add(wx.StaticText(panel, -1, '')) gridSizer.Add(wx.StaticText(panel, -1, 'piece size:'), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) self.piece_length = wx.Choice(panel, -1, choices=[ 'automatic', '2MiB', '1MiB', '512KiB', '256KiB', '128KiB', '64KiB', '32KiB' ]) self.piece_length_list = [0, 21, 20, 19, 18, 17, 16, 15] self.piece_length.SetSelection(0) gridSizer.Add(self.piece_length) gridSizer.Add(wx.StaticText(panel, -1, 'comment:'), 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL) self.commentCtl = wx.TextCtrl(panel, -1, '') gridSizer.Add(self.commentCtl, 0, wx.EXPAND) gridSizer.Add(wx.StaticText(panel, -1, '')) gridSizer.Add(wx.StaticText(panel, -1, '')) b1 = wx.Button(panel, -1, 'Cancel', size=(-1, 30)) wx.EVT_BUTTON(frame, b1.GetId(), self.cancel) gridSizer.Add(b1, 0, wx.EXPAND) b2 = wx.Button(panel, -1, 'MAKE TORRENT', size=(-1, 30)) wx.EVT_BUTTON(frame, b2.GetId(), self.complete) gridSizer.Add(b2, 0, wx.EXPAND) gridSizer.AddGrowableCol(1) colSizer.Add(gridSizer, -1, wx.ALIGN_CENTER_VERTICAL) fullSizer.Add(colSizer) border = wx.BoxSizer(wx.HORIZONTAL) border.Add(fullSizer, 1, wx.EXPAND | wx.ALL, 15) panel.SetSizer(border) panel.SetAutoLayout(True) border.Fit(panel) frame.Fit() frame.Show(True) super(AdvancedDownloadInfo, self).__init__(frame) wx.EVT_CLOSE(frame, self._close)
def __init__(self, parent, ID, *args, **kw): # miscellaneous protected variables self._CurrentRenderer = None self._CurrentCamera = None self._CurrentZoom = 1.0 self._CurrentLight = None self._ViewportCenterX = 0 self._ViewportCenterY = 0 self._Picker = vtkCellPicker() self._PickedActor = None self._PickedProperty = vtkProperty() self._PickedProperty.SetColor(1, 0, 0) self._PrePickedProperty = None # these record the previous mouse position self._LastX = 0 self._LastY = 0 # the current interaction mode (Rotate, Pan, Zoom, etc) self._Mode = None self._ActiveButton = None # private attributes self.__OldFocus = None # used by the LOD actors self._DesiredUpdateRate = 15 self._StillUpdateRate = 0.0001 # First do special handling of some keywords: # stereo, position, size, width, height, style stereo = 0 if 'stereo' in kw: if kw['stereo']: stereo = 1 del kw['stereo'] position = wx.DefaultPosition if 'position' in kw: position = kw['position'] del kw['position'] size = wx.DefaultSize if 'size' in kw: size = kw['size'] del kw['size'] if 'width' in kw and 'height' in kw: size = (kw['width'], kw['height']) del kw['width'] del kw['height'] # wxWANTS_CHARS says to give us e.g. TAB # wxNO_FULL_REPAINT_ON_RESIZE cuts down resize flicker under GTK style = wx.WANTS_CHARS | wx.NO_FULL_REPAINT_ON_RESIZE if 'style' in kw: style = style | kw['style'] del kw['style'] # the enclosing frame must be shown under GTK or the windows # don't connect together properly l = [] p = parent while p: # make a list of all parents l.append(p) p = p.GetParent() l.reverse() # sort list into descending order for p in l: p.Show() # initialize the wxWindow baseClass.__init__(self, parent, ID, position, size, style) # create the RenderWindow and initialize it self._RenderWindow = vtkRenderWindow() try: self._RenderWindow.SetSize(size.width, size.height) except AttributeError: self._RenderWindow.SetSize(size[0], size[1]) if stereo: self._RenderWindow.StereoCapableWindowOn() self._RenderWindow.SetStereoTypeToCrystalEyes() self.__Created = 0 # Tell the RenderWindow to render inside the wxWindow. if self.GetHandle(): self.__Created = 1 self._RenderWindow.SetWindowInfo(str(self.GetHandle())) # refresh window by doing a Render wx.EVT_PAINT(self, self.OnPaint) # turn off background erase to reduce flicker wx.EVT_ERASE_BACKGROUND(self, lambda e: None) # Bind the events to the event converters wx.EVT_RIGHT_DOWN(self, self._OnButtonDown) wx.EVT_LEFT_DOWN(self, self._OnButtonDown) wx.EVT_MIDDLE_DOWN(self, self._OnButtonDown) wx.EVT_RIGHT_UP(self, self._OnButtonUp) wx.EVT_LEFT_UP(self, self._OnButtonUp) wx.EVT_MIDDLE_UP(self, self._OnButtonUp) wx.EVT_MOTION(self, self.OnMotion) wx.EVT_ENTER_WINDOW(self, self._OnEnterWindow) wx.EVT_LEAVE_WINDOW(self, self._OnLeaveWindow) wx.EVT_CHAR(self, self.OnChar) wx.EVT_KEY_DOWN(self, self.OnKeyDown) wx.EVT_KEY_UP(self, self.OnKeyUp) wx.EVT_SIZE(self, self._OnSize) wx.EVT_MOVE(self, self.OnMove) wx.EVT_SET_FOCUS(self, self.OnSetFocus) wx.EVT_KILL_FOCUS(self, self.OnKillFocus)
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ factory = self.factory # Establish the range of the slider: low_name = high_name = '' low, high = factory.low, factory.high if high <= low: low = high = None handler = self.object.trait(self.name).handler if isinstance(handler, BaseRange): low_name, high_name = handler._low_name, handler._high_name if low_name == '': low = handler._low if high_name == '': high = handler._high elif isinstance(handler, BaseEnum): if handler.name == '': self.mapping = handler.values else: self.sync_value(handler.name, 'mapping', 'from') low, high = 0, self.high # Create the control: self.control = control = wx.Window(parent, -1, size=wx.Size(50, 18), style=wx.FULL_REPAINT_ON_RESIZE | wx.TAB_TRAVERSAL) # Set up the painting event handlers: wx.EVT_ERASE_BACKGROUND(control, self._erase_background) wx.EVT_PAINT(control, self._on_paint) wx.EVT_SET_FOCUS(control, self._set_focus) # Set up mouse event handlers: wx.EVT_LEAVE_WINDOW(control, self._leave_window) wx.EVT_ENTER_WINDOW(control, self._enter_window) wx.EVT_LEFT_DOWN(control, self._left_down) wx.EVT_LEFT_UP(control, self._left_up) wx.EVT_MOTION(control, self._motion) wx.EVT_MOUSEWHEEL(control, self._mouse_wheel) # Set up the control resize handler: wx.EVT_SIZE(control, self._resize) # Set the tooltip: self._can_set_tooltip = (not self.set_tooltip()) # Save the values we calculated: self.set(low=low, high=high) self.sync_value(low_name, 'low', 'from') self.sync_value(high_name, 'high', 'from') # Force a reset (in case low = high = None, which won't cause a # notification to fire): self._reset_scrubber()