def __init__(self, gui): wx.Dialog.__init__(self, gui, title=_("History Player"), size=(225, 140)) self.gui = gui self.looping = False self.paused = False self.playButton = bitmap_button(self, get_image_path(u"icons", u"play"), self.play, True, True) self.pauseButton = bitmap_button(self, get_image_path(u"icons", u"pause"), self.pause, True, True) self.stopButton = bitmap_button(self, get_image_path(u"icons", u"stop"), self.stop, True, True) closeButton = button(self, wx.ID_CANCEL, _("&Close"), self.on_close) closeButton.SetDefault() sizer = wx.BoxSizer(wx.VERTICAL) historySizer = wx.BoxSizer(wx.HORIZONTAL) historySizer.Add(self.playButton, 0, wx.ALL, 2) historySizer.Add(self.pauseButton, 0, wx.ALL, 2) historySizer.Add(self.stopButton, 0, wx.ALL, 2) sizer.Add(historySizer, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 13) sizer.Add((10, 5)) sizer.Add(closeButton, 0, wx.ALIGN_CENTRE | wx.BOTTOM, 13) self.SetSizer(sizer) self.SetEscapeId(closeButton.GetId()) self.SetFocus() self.toggle_buttons() self.Bind(wx.EVT_CLOSE, self.on_close)
def __init__(self, parent, pos, tool): wx.Panel.__init__(self, parent, pos=pos, style=wx.CLIP_CHILDREN) self.gui = parent.gui self.tool = tool self.offset = (0, 0) self.directory = None self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER) self.total_time = u"" self.timer = wx.Timer(self) # updates the slider as the file plays self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) self.SetDropTarget(MediaDropTarget(self)) self.open = wx.BitmapButton(self, bitmap=wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR)) self.play = wx.BitmapButton(self, bitmap=wx.Bitmap(get_image_path(u"icons", u"play"))) self.pause = wx.BitmapButton(self, bitmap=wx.Bitmap(get_image_path(u"icons", u"pause"))) self.stop = wx.BitmapButton(self, bitmap=wx.Bitmap(get_image_path(u"icons", u"stop"))) self.play.Disable() self.pause.Disable() self.stop.Disable() self.file = wx.StaticText(self) self.elapsed = wx.StaticText(self) timesizer = wx.BoxSizer(wx.HORIZONTAL) timesizer.Add(self.file, 1, wx.LEFT | wx.RIGHT, 5) timesizer.Add(self.elapsed, 0, wx.ALIGN_RIGHT | wx.RIGHT, 5) self.slider = wx.Slider(self) self.slider.SetToolTipString(_("Skip to a position")) self.volume = wx.Slider(self, value=100, style=wx.SL_VERTICAL | wx.SL_INVERSE) self.volume.SetToolTipString(_("Set the volume")) self.slider.SetMinSize((150, -1)) self.volume.SetMinSize((-1, 75)) sizer = wx.GridBagSizer(6, 5) sizer.Add(self.mc, (1, 1), span=(5, 1)) sizer.Add(self.open, (1, 3), flag=wx.RIGHT, border=10) sizer.Add(self.play, (2, 3), flag=wx.RIGHT, border=10) sizer.Add(self.pause, (3, 3), flag=wx.RIGHT, border=10) sizer.Add(self.stop, (4, 3), flag=wx.RIGHT, border=10) sizer.Add(self.volume, (5, 3), flag=wx.RIGHT, border=10) sizer.Add(self.slider, (6, 1), flag=wx.EXPAND) sizer.Add(timesizer, (7, 1), flag=wx.EXPAND | wx.BOTTOM, border=10) self.SetSizerAndFit(sizer) self.Bind(wx.media.EVT_MEDIA_LOADED, self.media_loaded) self.Bind(wx.media.EVT_MEDIA_STOP, self.media_stopped) self.Bind(wx.EVT_BUTTON, self.load_file, self.open) self.Bind(wx.EVT_BUTTON, self.on_play, self.play) self.Bind(wx.EVT_BUTTON, self.on_pause, self.pause) self.Bind(wx.EVT_BUTTON, self.on_stop, self.stop) self.Bind(wx.EVT_SLIDER, self.on_seek, self.slider) self.Bind(wx.EVT_SLIDER, self.on_volume, self.volume) self.Bind(wx.EVT_LEFT_UP, self.left_up) self.Bind(wx.EVT_LEFT_DOWN, self.left_down) self.slider.Bind(wx.EVT_LEFT_DOWN, self.slider_click) self.Bind(wx.EVT_MOTION, self.left_motion) self.Bind(wx.EVT_TIMER, self.on_timer) self.timer.Start(650)
def __init__(self, tab, gui, area): """ Initalise the window, class variables and bind mouse/paint events """ wx.ScrolledWindow.__init__(self, tab, style=wx.NO_FULL_REPAINT_ON_RESIZE | wx.CLIP_CHILDREN) self.setup_gui() self.area = area self.gui = gui self.scale = (1.0, 1.0) self.shapes = [] # list of shapes for re-drawing/saving self.shape = None # currently selected shape *to draw with* self.medias = [] # list of Media panels self.selected = None # selected shape *with Select tool* self.text = None # current Text object for redraw all self.copy = None # BitmapSelect instance self.resizing = False self.cursor_control = False # toggle resize canvas cursor on/off self.resize_direction = None self.undo_list = [] self.redo_list = [] self.drawing = False self.prev_drag = (0, 0) self.scroller = DragScroller(self) self.overlay = wx.Overlay() self.buffer = wx.EmptyBitmap(*self.area) img = wx.Image(get_image_path(u"cursors", u"rotate")) self.rotate_cursor = wx.CursorFromImage(img) self.gui.change_tool(canvas=self) self.redraw_all()
def colour_buttons(self): panel = wx.Panel(self.pane) self.colour = csel.ColourSelect(panel, pos=(0, 0), size=(60, 60)) parent = panel if os.name == "nt": parent = self.colour # segfaults otherwise sizer = wx.BoxSizer() swap_sizer = wx.BoxSizer(wx.HORIZONTAL) self.background = csel.ColourSelect(parent, pos=(0, 30), size=(30, 30)) self.background.SetValue("White") bmp = wx.Bitmap(get_image_path(u"icons", u"swap_colours")) swap = wx.BitmapButton(panel, bitmap=bmp, pos=(70, 0), style=wx.NO_BORDER) self.transparent = wx.CheckBox(panel, label=_("Transparent"), pos=(0, 69)) self.transparent.SetValue(True) self.colour.Bind(csel.EVT_COLOURSELECT, self.change_colour) self.background.Bind(csel.EVT_COLOURSELECT, self.change_background) self.transparent.Bind(wx.EVT_CHECKBOX, self.on_transparency) swap.Bind(wx.EVT_BUTTON, self.on_swap) self.colour.SetToolTipString(_("Set the foreground color")) self.background.SetToolTipString(_("Set the background color")) self.transparent.SetToolTipString(_("Ignores the background color")) swap.SetToolTipString(_("Swaps the foreground and background colors")) sizer.AddMany([(self.background), (self.colour), (self.transparent)]) swap_sizer.Add(sizer) swap_sizer.Add(swap, flag=wx.ALIGN_RIGHT) return panel
def __init__(self, gui, cache): wx.Dialog.__init__(self, gui, title=_("PDF Cache Viewer"), size=(650, 300), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) self.cache = cache self.files = cache.entries() self.original_files = dict(cache.entries()) self.list = WhyteboardList(self) self.SetSizeHints(450, 300) label = wx.StaticText(self, label=_("Whyteboard will load these files from its cache instead of re-converting them")) sizer = wx.BoxSizer(wx.VERTICAL) bsizer = wx.BoxSizer(wx.HORIZONTAL) self.deleteBtn = bitmap_button(self, get_image_path(u"icons", u"delete"), self.on_remove, False) self.deleteBtn.SetToolTipString(_("Remove cached item")) bsizer.Add(self.deleteBtn, 0, wx.RIGHT, 5) okButton = button(self, wx.ID_OK, _("&OK"), self.ok) cancelButton = button(self, wx.ID_CANCEL, _("&Cancel"), lambda x: self.Close()) cancelButton.SetDefault() btnSizer = wx.StdDialogButtonSizer() btnSizer.AddButton(okButton) btnSizer.AddButton(cancelButton) btnSizer.Realize() sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(label, 0, wx.ALL, 15) sizer.Add((10, 5)) sizer.Add(bsizer, 0, wx.LEFT | wx.EXPAND, 10) sizer.Add((10, 5)) sizer.Add(self.list, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 10) sizer.Add((10, 5)) sizer.Add(btnSizer, 0, wx.TOP | wx.BOTTOM | wx.ALIGN_CENTRE, 15) self.SetSizer(sizer) self.populate() self.check_buttons() self.SetEscapeId(cancelButton.GetId()) self.SetFocus() self.Bind(wx.EVT_LIST_ITEM_SELECTED, lambda x: self.check_buttons()) self.Bind(wx.EVT_LIST_ITEM_DESELECTED, lambda x: self.check_buttons()) ac = [(wx.ACCEL_NORMAL, wx.WXK_DELETE, self.deleteBtn.GetId())] tbl = wx.AcceleratorTable(ac) self.list.SetAcceleratorTable(tbl) self.Bind(wx.EVT_CHAR_HOOK, self.delete_key)
def configure(toolbar, can_paste): """ Configures the GUI's toolbar. Move to top/up/down/bottom are created with a custom bitmap. """ logger.debug("Creating the tool bar") _move = [ID_MOVE_TO_TOP, ID_MOVE_UP, ID_MOVE_DOWN, ID_MOVE_TO_BOTTOM] ids = [wx.ID_NEW, wx.ID_OPEN, wx.ID_SAVE, wx.ID_COPY, wx.ID_PASTE, wx.ID_UNDO, wx.ID_REDO, wx.ID_DELETE] arts = [wx.ART_NEW, wx.ART_FILE_OPEN, wx.ART_FILE_SAVE, wx.ART_COPY, wx.ART_PASTE, wx.ART_UNDO, wx.ART_REDO, wx.ART_DELETE] tips = [_("New Sheet"), _("Open a File"), _("Save Drawing"), _("Copy a Bitmap Selection"), _("Paste an Image/Text"), _("Undo the Last Action"), _("Redo the Last Undone Action"), _("Delete the currently selected shape"), _("Move Shape To Top"), ("Move Shape Up"), ("Move Shape Down"), ("Move Shape To Bottom")] ids.extend(_move) arts.extend(_move) icons = [u"top", u"up", u"down", u"top"] bmps = {} for icon, event_id in zip(icons, _move): bmps[event_id] = wx.Bitmap(get_image_path(u"icons", u"move-%s-small" % icon)) # add tools, add a separator and bind paste/undo/redo for UI updating for x, (_id, art_id, tip) in enumerate(zip(ids, arts, tips)): if _id in _move: art = bmps[_id] else: art = wx.ArtProvider.GetBitmap(art_id, wx.ART_TOOLBAR) toolbar.AddSimpleTool(_id, art, tip) # after save and redo if x in [2, 6]: toolbar.AddSeparator() toolbar.EnableTool(wx.ID_PASTE, can_paste) toolbar.Realize()
def make_toolbox(self): """Creates a toolbox made from toggleable bitmap buttons""" items = [_(i.icon) for i in self.gui.util.items] for x, val in enumerate(items): path = get_image_path(u"tools", val) logger.debug("Creating toolbox item from [%s]", path) item = self.gui.util.items[x] b = GenBitmapToggleButton(self.pane, x + 1, wx.Bitmap(path), style=wx.NO_BORDER) b.SetToolTipString(u"%s\n%s %s" % (_(item.tooltip), _("Shortcut Key:"), item.hotkey.upper())) b.Bind(wx.EVT_BUTTON, self.change_tool, id=x + 1) self.tools[x + 1] = b if self.media_is_supported(item): self.toolsizer.Add(b, 0, wx.EXPAND | wx.RIGHT, 2) else: b.Hide()
def make_button(self, filename, tooltip, event_handler): btn = bitmap_button(self, get_image_path(u"icons", filename), event_handler, False) btn.SetToolTipString(tooltip) return btn