def __do_layout(self): """ Arranges EMR browser layout """ # splitter window self.__tree_narr_splitter = wx.wxSplitterWindow(self, -1) # emr tree self.__emr_tree = wx.wxTreeCtrl(self.__tree_narr_splitter, -1, style=wx.wxTR_HAS_BUTTONS | wx.wxNO_BORDER) # narrative details text control self.__narr_TextCtrl = wx.wxTextCtrl( self.__tree_narr_splitter, -1, style=wx.wxTE_MULTILINE | wx.wxTE_READONLY | wx.wxTE_DONTWRAP) # set up splitter # FIXME: read/save value from/into backend self.__tree_narr_splitter.SetMinimumPaneSize(20) self.__tree_narr_splitter.SplitVertically(self.__emr_tree, self.__narr_TextCtrl) self.__szr_main = wx.wxBoxSizer(wx.wxVERTICAL) self.__szr_main.Add(self.__tree_narr_splitter, 1, wx.wxEXPAND, 0) self.SetAutoLayout(1) self.SetSizer(self.__szr_main) self.__szr_main.Fit(self) self.__szr_main.SetSizeHints(self)
def __do_layout(self): """ Arranges EMR browser layout """ # splitter window self.__tree_narr_splitter = wx.wxSplitterWindow(self, -1) # emr tree self.__emr_tree = wx.wxTreeCtrl ( self.__tree_narr_splitter, -1, style=wx.wxTR_HAS_BUTTONS | wx.wxNO_BORDER ) # narrative details text control self.__narr_TextCtrl = wx.wxTextCtrl ( self.__tree_narr_splitter, -1, style=wx.wxTE_MULTILINE | wx.wxTE_READONLY | wx.wxTE_DONTWRAP ) # set up splitter # FIXME: read/save value from/into backend self.__tree_narr_splitter.SetMinimumPaneSize(20) self.__tree_narr_splitter.SplitVertically(self.__emr_tree, self.__narr_TextCtrl) self.__szr_main = wx.wxBoxSizer(wx.wxVERTICAL) self.__szr_main.Add(self.__tree_narr_splitter, 1, wx.wxEXPAND, 0) self.SetAutoLayout(1) self.SetSizer(self.__szr_main) self.__szr_main.Fit(self) self.__szr_main.SetSizeHints(self)
def __init__(self, parent, items, prfx): self.items = items style = wxCAPTION | wxSYSTEM_MENU | wxRESIZE_BORDER wxDialog.__init__(self, parent, wxNewId(), "Properties " + prfx, size=wxSize(750,400), style=style) sizer = RowColSizer() self.sizer = sizer self.SetSizer(sizer) self.SetAutoLayout(true) btn = wxButton(self, wxNewId(), "OK") EVT_BUTTON(self, btn.GetId(), lambda e, self=self: self.Destroy()) bsizer = wxBoxSizer(wxVERTICAL) for t in ("Show MD5 sums", "Same units"): b = wxButton(self, wxNewId(), t) b.Enable(false) bsizer.Add(b, 0, wxEXPAND, 0) self.PopulateList() flags = wxEXPAND | wxALL bb = 10 sizer.Add(self.list, row=1, col=1, flag=flags) sizer.Add(btn, row=3, col=1, flag=wxALIGN_CENTRE, colspan=2) sizer.Add(bsizer, row=1, col=2) sizer.AddGrowableCol(1) sizer.AddGrowableRow(1) sizer.AddSpacer(10,10, pos=(2,1))
def __init__(self, d, a, params): self.d = d self.a = a self.params = params self.flag = threading.Event() self.separatetorrents = False if os.path.isdir(d): self.choicemade = threading.Event() frame = wx.wxFrame(None, -1, 'BitTorrent make torrent', size=(1, 1)) self.frame = frame panel = wx.wxPanel(frame, -1) gridSizer = wx.wxFlexGridSizer(cols=1, vgap=8, hgap=8) gridSizer.AddGrowableRow(1) gridSizer.Add(wx.wxStaticText( panel, -1, 'Do you want to make a separate .torrent'), 0, wx.wxALIGN_CENTER) gridSizer.Add(wx.wxStaticText( panel, -1, 'for every item in this directory?'), 0, wx.wxALIGN_CENTER) gridSizer.Add(wx.wxStaticText(panel, -1, '')) b = wx.wxFlexGridSizer(cols=3, hgap=10) yesbut = wx.wxButton(panel, -1, 'Yes') def saidyes(e, self=self): self.frame.Destroy() self.separatetorrents = True self.begin() wx.EVT_BUTTON(frame, yesbut.GetId(), saidyes) b.Add(yesbut, 0) nobut = wx.wxButton(panel, -1, 'No') def saidno(e, self=self): self.frame.Destroy() self.begin() wx.EVT_BUTTON(frame, nobut.GetId(), saidno) b.Add(nobut, 0) cancelbut = wx.wxButton(panel, -1, 'Cancel') def canceled(e, self=self): self.frame.Destroy() wx.EVT_BUTTON(frame, cancelbut.GetId(), canceled) b.Add(cancelbut, 0) gridSizer.Add(b, 0, wx.wxALIGN_CENTER) border = wx.wxBoxSizer(wx.wxHORIZONTAL) border.Add(gridSizer, 1, wx.wxEXPAND | wx.wxALL, 4) panel.SetSizer(border) panel.SetAutoLayout(True) frame.Show() border.Fit(panel) frame.Fit() else: self.begin()
def __init__(self): frame = wx.wxFrame(None, -1, 'BitTorrent complete dir 1.0.1', size=wx.wxSize(550, 250)) self.frame = frame panel = wx.wxPanel(frame, -1) gridSizer = wx.wxFlexGridSizer(cols=2, rows=2, vgap=15, hgap=8) gridSizer.Add(wx.wxStaticText(panel, -1, 'directory to build:')) self.dirCtl = wx.wxTextCtrl(panel, -1, '') b = wx.wxBoxSizer(wx.wxHORIZONTAL) b.Add(self.dirCtl, 1, wx.wxEXPAND) # b.Add(10, 10, 0, wxEXPAND) button = wx.wxButton(panel, -1, 'select') b.Add(button, 0, wx.wxEXPAND) wx.EVT_BUTTON(frame, button.GetId(), self.select) gridSizer.Add(b, 0, wx.wxEXPAND) gridSizer.Add(wx.wxStaticText(panel, -1, 'announce url:')) self.annCtl = wx.wxTextCtrl(panel, -1, 'http://my.tracker:6969/announce') gridSizer.Add(self.annCtl, 0, wx.wxEXPAND) gridSizer.Add(wx.wxStaticText(panel, -1, 'piece size:')) self.piece_length = wx.wxChoice( panel, -1, choices=['2 ** 21', '2 ** 20', '2 ** 19', '2 ** 18', '2 ** 17', '2 ** 16', '2 ** 15']) self.piece_length.SetSelection(3) gridSizer.Add(self.piece_length) gridSizer.AddGrowableCol(1) border = wx.wxBoxSizer(wx.wxVERTICAL) border.Add(gridSizer, 0, wx.wxEXPAND | wx.wxNORTH | wx.wxEAST | wx.wxWEST, 25) b2 = wx.wxButton(panel, -1, 'make') # border.Add(10, 10, 1, wxEXPAND) border.Add(b2, 0, wx.wxALIGN_CENTER | wx.wxSOUTH, 20) wx.EVT_BUTTON(frame, b2.GetId(), self.complete) panel.SetSizer(border) panel.SetAutoLayout(True)
def moveCopy(self, event): print "Moving" destPath = self.path frame = wxFrame(self.ilist, wxNewId(), "Move/Copy Items?") mSizer = wxBoxSizer(wxVERTICAL) frame.SetAutoLayout(true) frame.SetSizer(mSizer) count = self.ilist.GetSelectedItemCount() # number of selected items mSizer.Add(30, 10, 0, wxEXPAND) mSizer.Add( wxStaticText(frame, wxNewId(), "Move/Copy %d item(s)?" % count), 0, 0) mSizer.Add(30, 10, 0, wxEXPAND) bSizer = wxBoxSizer(wxHORIZONTAL) mSizer.Add(bSizer, 0, 0) mSizer.Add(30, 10, 0, wxEXPAND) btnMv = wxButton(frame, self.btnMv, "Move") btnCp = wxButton(frame, self.btnCp, "Copy") btnCancel = wxButton(frame, self.btnCancel, "Cancel") for b in (btnMv, btnCp, btnCancel): EVT_BUTTON(b, b.GetId(), self.OnButtonPress) bSizer.Add(btnMv, 1, 0) bSizer.Add(30, 10, 0, wxEXPAND) bSizer.Add(btnCp, 1, 0) bSizer.Add(30, 10, 0, wxEXPAND) bSizer.Add(btnCancel, 1, 0) frame.MakeModal(true) frame.Show(true) self.frame = frame EVT_CLOSE(frame, self.OnCloseWindow)
def ButtonBox(self): panel = wx.wxPanel(self, -1) panel.SetAutoLayout(wx.true) sizer = wx.wxBoxSizer(wx.wxHORIZONTAL) panel.SetSizer(sizer) self.ok = wx.wxButton(panel, wx.wxID_OK, "Ok") cancel = wx.wxButton(panel, wx.wxID_CANCEL, "Cancel") sizer.AddMany([ (self.ok, 0, wx.wxALIGN_TOP | wx.wxEAST | wx.wxSOUTH, 10), (cancel, 0, wx.wxALIGN_TOP | wx.wxWEST | wx.wxSOUTH, 10), ]) panel.Layout() panel.Fit() return panel
def moveCopy(self, event): print "Moving" destPath = self.path frame = wxFrame(self.ilist, wxNewId(), "Move/Copy Items?") mSizer = wxBoxSizer(wxVERTICAL) frame.SetAutoLayout(true) frame.SetSizer(mSizer) count = self.ilist.GetSelectedItemCount() # number of selected items mSizer.Add(30, 10, 0, wxEXPAND) mSizer.Add(wxStaticText(frame, wxNewId(), "Move/Copy %d item(s)?" % count), 0, 0) mSizer.Add(30, 10, 0, wxEXPAND) bSizer = wxBoxSizer(wxHORIZONTAL) mSizer.Add(bSizer, 0, 0) mSizer.Add(30, 10, 0, wxEXPAND) btnMv = wxButton(frame, self.btnMv, "Move") btnCp = wxButton(frame, self.btnCp, "Copy") btnCancel = wxButton(frame, self.btnCancel, "Cancel") for b in (btnMv, btnCp, btnCancel): EVT_BUTTON(b, b.GetId(), self.OnButtonPress) bSizer.Add(btnMv, 1, 0) bSizer.Add(30, 10, 0, wxEXPAND) bSizer.Add(btnCp, 1, 0) bSizer.Add(30, 10, 0, wxEXPAND) bSizer.Add(btnCancel, 1, 0) frame.MakeModal(true) frame.Show(true) self.frame = frame EVT_CLOSE(frame, self.OnCloseWindow)
def __init__(self, op, fsoList, destPath): self.stopped = false self.InTransfer = false self.op = op if self.COPY == op: txt = "Copy" else: txt = "Move" self.fsoList = fsoList self.destPath = os.path.normpath(destPath) wxDialog.__init__(self, None, wxNewId(), txt + " operation") sizer = wxBoxSizer(wxVERTICAL) self.SetAutoLayout(true) self.SetSizer(sizer) self.sizer = sizer btn = wxButton(self, wxNewId(), "Stop") EVT_BUTTON(self, btn.GetId(), self.OnClick) self.txt1 = wxStaticText(self, wxNewId(), "Destination directory: ") self.txt2 = wxStaticText(self, wxNewId(), destPath) #self.txt = wxStaticText(self, wxNewId(), "Single object progress:") #self.gauge = wxGauge(self, wxNewId(), 100) self.txtAll = wxStaticText(self, wxNewId(), "Overall progress:") self.gaugeAll = wxGauge(self, wxNewId(), len(fsoList)) flags = wxEXPAND | wxALL border = 0 bb = 10 sizer.Add(2 * bb, 2 * bb) # separator sizer.Add(self.txt1, 0, wxLEFT, border) sizer.Add(self.txt2, 0, wxLEFT, border) sizer.Add(bb, bb) # separator #sizer.Add(self.txt, 0, wxLEFT, border) #sizer.Add(bb, bb) # separator #sizer.Add(self.gauge, 0, flags, border) #sizer.Add(bb, bb) # separator sizer.Add(self.txtAll, 0, wxLEFT, border) sizer.Add(bb, bb) # separator sizer.Add(self.gaugeAll, 0, flags, border) sizer.Add(bb, bb) # separator sizer.Add(btn, 0, wxALIGN_CENTRE, border) sizer.Add(2 * bb, 2 * bb) # separator sizer.Layout() self.Refresh() EVT_IDLE(self, self.OnIdle)
def __init__(self, parent, items, prfx): self.items = items style = wxCAPTION | wxSYSTEM_MENU | wxRESIZE_BORDER wxDialog.__init__(self, parent, wxNewId(), "Properties " + prfx, size=wxSize(750, 400), style=style) sizer = RowColSizer() self.sizer = sizer self.SetSizer(sizer) self.SetAutoLayout(true) btn = wxButton(self, wxNewId(), "OK") EVT_BUTTON(self, btn.GetId(), lambda e, self=self: self.Destroy()) bsizer = wxBoxSizer(wxVERTICAL) for t in ("Show MD5 sums", "Same units"): b = wxButton(self, wxNewId(), t) b.Enable(false) bsizer.Add(b, 0, wxEXPAND, 0) self.PopulateList() flags = wxEXPAND | wxALL bb = 10 sizer.Add(self.list, row=1, col=1, flag=flags) sizer.Add(btn, row=3, col=1, flag=wxALIGN_CENTRE, colspan=2) sizer.Add(bsizer, row=1, col=2) sizer.AddGrowableCol(1) sizer.AddGrowableRow(1) sizer.AddSpacer(10, 10, pos=(2, 1))
def __init__(self, parent, id, title, file, pos = wx.wxDefaultPosition, size = wx.wxDefaultSize, style = wx.wxDEFAULT_DIALOG_STYLE, name = "ImportWizardDialog"): wx.wxDialog.__init__(self, parent, id, title, pos, size, style, name) self.SetAutoLayout(wx.true) self.file = file f = open(file, 'r') self.data = f.read() f.close() sizer = wx.wxBoxSizer(wx.wxVERTICAL) self.delimPanel = ImportWizardPanel_Delimiters(self, -1, file, self.data, self.ValidState) buttonBox = self.ButtonBox() sizer.AddMany([ (self.delimPanel, 0, wx.wxALL, 5), (buttonBox, 0, wx.wxSOUTH | wx.wxALIGN_CENTER_HORIZONTAL | wx.wxALIGN_TOP, 0), ]) self.SetSizer(sizer) self.Layout() sizer.Fit(self.delimPanel) self.Fit() self.Centre()
def __init__(self, config, calls): self.config = config self.calls = calls self.uiflag = threading.Event() self.cancelflag = threading.Event() self.switchlock = threading.Lock() self.working = False self.queue = [] wx.wxInitAllImageHandlers() self.thostselection = self.calls["getCurrentTHost"]() self.thostselectnum = 0 self.choices = None self.choices1 = None self.windowStyle = wx.wxSYSTEM_MENU | wx.wxCAPTION | wx.wxMINIMIZE_BOX if self.config["stayontop"]: self.windowStyle |= wx.wxSTAY_ON_TOP frame = wx.wxFrame(None, -1, "T-Make", size=wx.wxSize(-1, -1), style=self.windowStyle) self.frame = frame panel = wx.wxPanel(frame, -1) fullSizer = wx.wxFlexGridSizer(cols=1, vgap=0, hgap=8) colSizer = wx.wxFlexGridSizer(cols=2, vgap=0, hgap=8) leftSizer = wx.wxFlexGridSizer(cols=1, vgap=3) self.stayontop_checkbox = wx.wxCheckBox(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.wxALIGN_CENTER) leftSizer.Add(wx.wxStaticText(panel, -1, "")) button = wx.wxButton(panel, -1, "use image...") wx.EVT_BUTTON(frame, button.GetId(), self.selectDropTarget) leftSizer.Add(button, -1, wx.wxALIGN_CENTER) self.groupSizer1Box = wx.wxStaticBox(panel, -1, "") groupSizer1 = wx.wxStaticBoxSizer(self.groupSizer1Box, wx.wxHORIZONTAL) groupSizer = wx.wxFlexGridSizer(cols=1, vgap=0) self.dropTarget = self.calls["newDropTarget"]((200, 200)) # self.dropTarget = self.calls['newDropTarget']() self.dropTargetPtr = wx.wxStaticBitmap(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.wxALIGN_CENTER) lowerSizer1 = wx.wxGridSizer(cols=3) dirlink = wx.wxStaticText(panel, -1, "dir") dirlink.SetFont(wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) dirlink.SetForegroundColour("blue") wx.EVT_LEFT_UP(dirlink, self.selectdir) lowerSizer1.Add(dirlink, -1, wx.wxALIGN_LEFT) lowerSizer1.Add(wx.wxStaticText(panel, -1, ""), -1, wx.wxALIGN_CENTER) filelink = wx.wxStaticText(panel, -1, "file") filelink.SetFont(wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) filelink.SetForegroundColour("blue") wx.EVT_LEFT_UP(filelink, self.selectfile) lowerSizer1.Add(filelink, -1, wx.wxALIGN_RIGHT) groupSizer.Add(lowerSizer1, -1, wx.wxALIGN_CENTER) self.gauge = wx.wxGauge(panel, -1, range=1000, style=wx.wxGA_HORIZONTAL, size=(-1, 15)) groupSizer.Add(self.gauge, 0, wx.wxEXPAND) self.statustext = wx.wxStaticText(panel, -1, "ready", style=wx.wxALIGN_CENTER | wx.wxST_NO_AUTORESIZE) self.statustext.SetFont(wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxBOLD, False)) groupSizer.Add(self.statustext, -1, wx.wxEXPAND) self.choices = wx.wxChoice(panel, -1, (-1, -1), (self.dropTargetWidth, -1), choices=[]) self.choices.SetFont(wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, False)) wx.EVT_CHOICE(self.choices, -1, self.set_thost) groupSizer.Add(self.choices, 0, wx.wxEXPAND) cancellink = wx.wxStaticText(panel, -1, "cancel") cancellink.SetFont(wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) cancellink.SetForegroundColour("red") wx.EVT_LEFT_UP(cancellink, self.cancel) groupSizer.Add(cancellink, -1, wx.wxALIGN_CENTER) dummyadvlink = wx.wxStaticText(panel, -1, "advanced") dummyadvlink.SetFont(wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, False)) dummyadvlink.SetForegroundColour("blue") wx.EVT_LEFT_UP(dirlink, self.selectdir) groupSizer.Add(dummyadvlink, -1, wx.wxALIGN_CENTER) groupSizer1.Add(groupSizer) leftSizer.Add(groupSizer1, -1, wx.wxALIGN_CENTER) leftSizer.Add(wx.wxStaticText(panel, -1, "make torrent of:"), 0, wx.wxALIGN_CENTER) self.dirCtl = wx.wxTextCtrl(panel, -1, "", size=(250, -1)) leftSizer.Add(self.dirCtl, 1, wx.wxEXPAND) b = wx.wxBoxSizer(wx.wxHORIZONTAL) button = wx.wxButton(panel, -1, "dir") wx.EVT_BUTTON(frame, button.GetId(), self.selectdir) b.Add(button, 0) button2 = wx.wxButton(panel, -1, "file") wx.EVT_BUTTON(frame, button2.GetId(), self.selectfile) b.Add(button2, 0) leftSizer.Add(b, 0, wx.wxALIGN_CENTER) leftSizer.Add(wx.wxStaticText(panel, -1, "")) simple_link = wx.wxStaticText(panel, -1, "back to basic mode") simple_link.SetFont(wx.wxFont(-1, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) simple_link.SetForegroundColour("blue") wx.EVT_LEFT_UP(simple_link, self.calls["switchToBasic"]) leftSizer.Add(simple_link, -1, wx.wxALIGN_CENTER) colSizer.Add(leftSizer, -1, wx.wxALIGN_CENTER_VERTICAL) gridSizer = wx.wxFlexGridSizer(cols=2, vgap=6, hgap=8) gridSizer.Add(wx.wxStaticText(panel, -1, "Torrent host:"), -1, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL) self.choices1 = wx.wxChoice(panel, -1, (-1, -1), (-1, -1), choices=[]) wx.EVT_CHOICE(self.choices1, -1, self.set_thost1) gridSizer.Add(self.choices1, 0, wx.wxEXPAND) b = wx.wxBoxSizer(wx.wxHORIZONTAL) button1 = wx.wxButton(panel, -1, "set default") wx.EVT_BUTTON(frame, button1.GetId(), self.set_default_thost) b.Add(button1, 0) b.Add(wx.wxStaticText(panel, -1, " ")) button2 = wx.wxButton(panel, -1, "delete") wx.EVT_BUTTON(frame, button2.GetId(), self.delete_thost) b.Add(button2, 0) b.Add(wx.wxStaticText(panel, -1, " ")) button3 = wx.wxButton(panel, -1, "save as...") wx.EVT_BUTTON(frame, button3.GetId(), self.save_thost) b.Add(button3, 0) gridSizer.Add(wx.wxStaticText(panel, -1, "")) gridSizer.Add(b, 0, wx.wxALIGN_CENTER) gridSizer.Add(wx.wxStaticText(panel, -1, "")) gridSizer.Add(wx.wxStaticText(panel, -1, "")) gridSizer.Add( wx.wxStaticText(panel, -1, "single tracker url:"), 0, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL ) self.annCtl = wx.wxTextCtrl(panel, -1, "http://my.tracker:6969/announce") gridSizer.Add(self.annCtl, 0, wx.wxEXPAND) a = wx.wxFlexGridSizer(cols=1, vgap=3) a.Add(wx.wxStaticText(panel, -1, "tracker list:"), 0, wx.wxALIGN_RIGHT) a.Add(wx.wxStaticText(panel, -1, "")) abutton = wx.wxButton(panel, -1, "copy\nannounces\nfrom\ntorrent", size=(70, 70)) wx.EVT_BUTTON(frame, abutton.GetId(), self.announcecopy) a.Add(abutton, -1, wx.wxALIGN_CENTER) a.Add(wx.wxStaticText(panel, -1, DROP_HERE), -1, wx.wxALIGN_CENTER) gridSizer.Add(a, -1, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL) self.annListCtl = wx.wxTextCtrl( panel, -1, "\n\n\n\n\n", wx.wxPoint(-1, -1), (300, 120), wx.wxTE_MULTILINE | wx.wxHSCROLL | wx.wxTE_DONTWRAP ) gridSizer.Add(self.annListCtl, -1, wx.wxEXPAND) gridSizer.Add(wx.wxStaticText(panel, -1, "")) exptext = wx.wxStaticText( panel, -1, "a list of tracker urls separated by commas or " "whitespace\nand on several lines -trackers on the same line will " "be\ntried randomly, and all the trackers on one line\nwill be " "tried before the trackers on the next line.", ) exptext.SetFont(wx.wxFont(6, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, False)) gridSizer.Add(exptext, -1, wx.wxALIGN_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.wxStaticText(panel, -1, "")) gridSizer.Add(wx.wxStaticText(panel, -1, "")) gridSizer.Add(wx.wxStaticText(panel, -1, "piece size:"), 0, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL) self.piece_length = wx.wxChoice( 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.wxStaticText(panel, -1, "comment:"), 0, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL) self.commentCtl = wx.wxTextCtrl(panel, -1, "") gridSizer.Add(self.commentCtl, 0, wx.wxEXPAND) gridSizer.Add(wx.wxStaticText(panel, -1, "")) gridSizer.Add(wx.wxStaticText(panel, -1, "")) b1 = wx.wxButton(panel, -1, "Cancel", size=(-1, 30)) wx.EVT_BUTTON(frame, b1.GetId(), self.cancel) gridSizer.Add(b1, 0, wx.wxEXPAND) b2 = wx.wxButton(panel, -1, "MAKE TORRENT", size=(-1, 30)) wx.EVT_BUTTON(frame, b2.GetId(), self.complete) gridSizer.Add(b2, 0, wx.wxEXPAND) gridSizer.AddGrowableCol(1) colSizer.Add(gridSizer, -1, wx.wxALIGN_CENTER_VERTICAL) fullSizer.Add(colSizer) border = wx.wxBoxSizer(wx.wxHORIZONTAL) border.Add(fullSizer, 1, wx.wxEXPAND | wx.wxALL, 15) panel.SetSizer(border) panel.SetAutoLayout(True) border.Fit(panel) frame.Fit() frame.Show(True) EVT_INVOKE(frame, self.onInvoke) wx.EVT_CLOSE(frame, self._close)
def __init__(self): frame = wx.wxFrame(None, -1, 'BitTorrent Torrent File Maker', size=wx.wxSize(550, 410)) self.frame = frame panel = wx.wxPanel(frame, -1) gridSizer = wx.wxFlexGridSizer(cols=2, rows=2, vgap=0, hgap=8) gridSizer.Add(wx.wxStaticText(panel, -1, 'make torrent of:')) b = wx.wxBoxSizer(wx.wxHORIZONTAL) self.dirCtl = wx.wxTextCtrl(panel, -1, '') b.Add(self.dirCtl, 1, wx.wxEXPAND) # b.Add(10, 10, 0, wxEXPAND) button = wx.wxButton(panel, -1, 'dir', size=(30, 20)) wx.EVT_BUTTON(frame, button.GetId(), self.selectdir) b.Add(button, 0) button2 = wx.wxButton(panel, -1, 'file', size=(30, 20)) wx.EVT_BUTTON(frame, button2.GetId(), self.selectfile) b.Add(button2, 0) gridSizer.Add(b, 0, wx.wxEXPAND) gridSizer.Add(wx.wxStaticText(panel, -1, '')) gridSizer.Add(wx.wxStaticText(panel, -1, '')) gridSizer.Add(wx.wxStaticText(panel, -1, 'announce url:')) self.annCtl = wx.wxTextCtrl(panel, -1, 'http://my.tracker:6969/announce') gridSizer.Add(self.annCtl, 0, wx.wxEXPAND) gridSizer.Add(wx.wxStaticText(panel, -1, '')) gridSizer.Add(wx.wxStaticText(panel, -1, '')) a = wx.wxFlexGridSizer(cols=1) a.Add(wx.wxStaticText(panel, -1, 'announce list:')) a.Add(wx.wxStaticText(panel, -1, '')) abutton = wx.wxButton(panel, -1, 'copy\nannounces\nfrom\ntorrent', size=(50, 70)) wx.EVT_BUTTON(frame, abutton.GetId(), self.announcecopy) a.Add(abutton, 0, wx.wxEXPAND) gridSizer.Add(a, 0, wx.wxEXPAND) self.annListCtl = wx.wxTextCtrl( panel, -1, '\n\n\n\n\n', wx.wxPoint(-1, -1), (400, 120), wx.wxTE_MULTILINE | wx.wxHSCROLL | wx.wxTE_DONTWRAP) gridSizer.Add(self.annListCtl, -1, wx.wxEXPAND) gridSizer.Add(wx.wxStaticText(panel, -1, '')) exptext = wx.wxStaticText( panel, -1, 'a list of announces separated by commas or whitespace ' 'and on several lines -\ntrackers on the same line will be tried ' 'randomly, and all the trackers on one line\nwill be tried before ' 'the trackers on the next line.') exptext.SetFont(wx.wxFont(6, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, False)) gridSizer.Add(exptext) gridSizer.Add(wx.wxStaticText(panel, -1, '')) gridSizer.Add(wx.wxStaticText(panel, -1, '')) gridSizer.Add(wx.wxStaticText(panel, -1, 'piece size:')) self.piece_length = wx.wxChoice( 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.wxStaticText(panel, -1, '')) gridSizer.Add(wx.wxStaticText(panel, -1, '')) gridSizer.Add(wx.wxStaticText(panel, -1, 'comment:')) self.commentCtl = wx.wxTextCtrl(panel, -1, '') gridSizer.Add(self.commentCtl, 0, wx.wxEXPAND) gridSizer.AddGrowableCol(1) border = wx.wxBoxSizer(wx.wxVERTICAL) border.Add(gridSizer, 0, wx.wxEXPAND | wx.wxNORTH | wx.wxEAST | wx.wxWEST, 25) b2 = wx.wxButton(panel, -1, 'make') # border.Add(10, 10, 1, wxEXPAND) border.Add(b2, 0, wx.wxALIGN_CENTER | wx.wxSOUTH, 20) wx.EVT_BUTTON(frame, b2.GetId(), self.complete) panel.SetSizer(border) panel.SetAutoLayout(True)
def OpenFile(parent, path): #FIXME: support: svg, sgvz, svg.gz with rsvg or batik (render to temporary #file /tmp/<PID><time()><atime(f.svg>.png and then open a frame) if not os.path.exists(path) or os.path.isdir(path): return frame = wxFrame(parent, -1, "File view: " + path, wxDefaultPosition, wxSize(500, 400)) handled = 0 needFrame = 1 lowerPath = string.lower(path) #for animations or to see if count is > 0: #wxImage_GetImageCount(path) if lowerPath[-3:] in ("ani", "bmp", "cur", "gif", "ico", "iff", "jpg", "pcx", "png", "pnm", \ "tif", "xpm") or lowerPath[-4:] in ("jpeg", "tiff"): #f = open(path, "rb"); data = f.read(); f.close() #stream = StringIO(data) #img = wxImageFromStream(stream) img = wxEmptyImage() img.LoadFile(path) bmp = wxBitmapFromImage(img) #wxStaticBitmap(frame, -1, bmp) #, (15, 45)) width, height = img.GetWidth(), img.GetHeight() if width and height: sw = wxScrolledWindow(frame, -1, wxDefaultPosition, wxDefaultSize, wxHSCROLL | wxVSCROLL) #sw.SetScrollbars(20, 20, img.GetWidth()/20, img.GetHeight()/20) sw.SetVirtualSize(wxSize(width, height)) sw.SetScrollRate(20, 20) wxStaticBitmap(sw, -1, bmp) #, (15, 45)) w, h = 800, 600 #frame.GetSize() w, h = min(w, width), min(h, height) minSize, b = 100, 10 if w < minSize: w = minSize if h < minSize: h = minSize frame.SetSize(wxSize(w+b, h+b)) handled = 1 elif "html" == lowerPath[-4:] or "htm" == path[-3:]: htmlWin = wxHtmlWindow(frame) htmlWin.LoadPage(path) handled = 1 elif "pdf" == lowerPath[-3:]: for cmd in ("xpdf", "acroread"): #FIXME: handle names that contain spaces etc. status, output = commands.getstatusoutput(cmd + " " + path) if 0 == status: handled = 1 needFrame = 0 break #FIXME: mplayer cannot run in background; same goes for Python calling mplayer externally - probably stdin dependence elif "mpeg" == lowerPath[-4:] or \ lowerPath[-3:] in ("asf", "avi", "mov", "mpa", "mpg", "wmv"): for cmd in ("mplayer -quiet",): #FIXME: handle names that contain spaces etc. status, output = commands.getstatusoutput(cmd + " " + path) if 0 == status: handled = 1 needFrame = 0 break elif "ps" == lowerPath[-2:] or "ps.gz" == lowerPath[-5:]: pid = os.fork() if 0 == pid: for cmd in ("ggv", "gv"): try: os.execlp(cmd, cmd, path) except OSError: pass os.exit(1) handled = 1 needFrame = 0 if not handled: minSize = 65536 try: f = open(path, "rb"); data = f.read(minSize); f.close() except IOError, ex: MsgOS(ex) return None txt = wxTextCtrl(frame, -1, data, style=wxTE_READONLY|wxTE_MULTILINE|wxTE_DONTWRAP|wxHSCROLL) if len(data) == minSize: sizer = wxBoxSizer(wxVERTICAL) frame.SetAutoLayout(true) frame.SetSizer(sizer) frame.sizer = sizer b = wxButton(frame, -1, "Show entire file") sizer.Add(txt, 1, wxEXPAND|wxALL, 0) sizer.Add(b, 0, wxALIGN_CENTRE, 0) sizer.Layout()
def __init__(self, config, calls): self.config = config self.calls = calls self.uiflag = threading.Event() self.cancelflag = threading.Event() self.switchlock = threading.Lock() self.working = False self.queue = [] wx.wxInitAllImageHandlers() self.thostselection = self.calls['getCurrentTHost']() self.thostselectnum = 0 self.choices = None self.choices1 = None self.windowStyle = wx.wxSYSTEM_MENU | wx.wxCAPTION | wx.wxMINIMIZE_BOX if self.config['stayontop']: self.windowStyle |= wx.wxSTAY_ON_TOP frame = wx.wxFrame(None, -1, 'T-Make', size=wx.wxSize(-1, -1), style=self.windowStyle) self.frame = frame panel = wx.wxPanel(frame, -1) fullSizer = wx.wxFlexGridSizer(cols=1, vgap=0, hgap=8) colSizer = wx.wxFlexGridSizer(cols=2, vgap=0, hgap=8) leftSizer = wx.wxFlexGridSizer(cols=1, vgap=3) self.stayontop_checkbox = wx.wxCheckBox(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.wxALIGN_CENTER) leftSizer.Add(wx.wxStaticText(panel, -1, '')) button = wx.wxButton(panel, -1, 'use image...') wx.EVT_BUTTON(frame, button.GetId(), self.selectDropTarget) leftSizer.Add(button, -1, wx.wxALIGN_CENTER) self.groupSizer1Box = wx.wxStaticBox(panel, -1, '') groupSizer1 = wx.wxStaticBoxSizer(self.groupSizer1Box, wx.wxHORIZONTAL) groupSizer = wx.wxFlexGridSizer(cols=1, vgap=0) self.dropTarget = self.calls['newDropTarget']((200, 200)) # self.dropTarget = self.calls['newDropTarget']() self.dropTargetPtr = wx.wxStaticBitmap(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.wxALIGN_CENTER) lowerSizer1 = wx.wxGridSizer(cols=3) dirlink = wx.wxStaticText(panel, -1, 'dir') dirlink.SetFont( wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) dirlink.SetForegroundColour('blue') wx.EVT_LEFT_UP(dirlink, self.selectdir) lowerSizer1.Add(dirlink, -1, wx.wxALIGN_LEFT) lowerSizer1.Add(wx.wxStaticText(panel, -1, ''), -1, wx.wxALIGN_CENTER) filelink = wx.wxStaticText(panel, -1, 'file') filelink.SetFont( wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) filelink.SetForegroundColour('blue') wx.EVT_LEFT_UP(filelink, self.selectfile) lowerSizer1.Add(filelink, -1, wx.wxALIGN_RIGHT) groupSizer.Add(lowerSizer1, -1, wx.wxALIGN_CENTER) self.gauge = wx.wxGauge(panel, -1, range=1000, style=wx.wxGA_HORIZONTAL, size=(-1, 15)) groupSizer.Add(self.gauge, 0, wx.wxEXPAND) self.statustext = wx.wxStaticText(panel, -1, 'ready', style=wx.wxALIGN_CENTER | wx.wxST_NO_AUTORESIZE) self.statustext.SetFont( wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxBOLD, False)) groupSizer.Add(self.statustext, -1, wx.wxEXPAND) self.choices = wx.wxChoice(panel, -1, (-1, -1), (self.dropTargetWidth, -1), choices=[]) self.choices.SetFont( wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, False)) wx.EVT_CHOICE(self.choices, -1, self.set_thost) groupSizer.Add(self.choices, 0, wx.wxEXPAND) cancellink = wx.wxStaticText(panel, -1, 'cancel') cancellink.SetFont( wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) cancellink.SetForegroundColour('red') wx.EVT_LEFT_UP(cancellink, self.cancel) groupSizer.Add(cancellink, -1, wx.wxALIGN_CENTER) dummyadvlink = wx.wxStaticText(panel, -1, 'advanced') dummyadvlink.SetFont( wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, False)) dummyadvlink.SetForegroundColour('blue') wx.EVT_LEFT_UP(dirlink, self.selectdir) groupSizer.Add(dummyadvlink, -1, wx.wxALIGN_CENTER) groupSizer1.Add(groupSizer) leftSizer.Add(groupSizer1, -1, wx.wxALIGN_CENTER) leftSizer.Add(wx.wxStaticText(panel, -1, 'make torrent of:'), 0, wx.wxALIGN_CENTER) self.dirCtl = wx.wxTextCtrl(panel, -1, '', size=(250, -1)) leftSizer.Add(self.dirCtl, 1, wx.wxEXPAND) b = wx.wxBoxSizer(wx.wxHORIZONTAL) button = wx.wxButton(panel, -1, 'dir') wx.EVT_BUTTON(frame, button.GetId(), self.selectdir) b.Add(button, 0) button2 = wx.wxButton(panel, -1, 'file') wx.EVT_BUTTON(frame, button2.GetId(), self.selectfile) b.Add(button2, 0) leftSizer.Add(b, 0, wx.wxALIGN_CENTER) leftSizer.Add(wx.wxStaticText(panel, -1, '')) simple_link = wx.wxStaticText(panel, -1, 'back to basic mode') simple_link.SetFont( wx.wxFont(-1, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) simple_link.SetForegroundColour('blue') wx.EVT_LEFT_UP(simple_link, self.calls['switchToBasic']) leftSizer.Add(simple_link, -1, wx.wxALIGN_CENTER) colSizer.Add(leftSizer, -1, wx.wxALIGN_CENTER_VERTICAL) gridSizer = wx.wxFlexGridSizer(cols=2, vgap=6, hgap=8) gridSizer.Add(wx.wxStaticText(panel, -1, 'Torrent host:'), -1, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL) self.choices1 = wx.wxChoice(panel, -1, (-1, -1), (-1, -1), choices=[]) wx.EVT_CHOICE(self.choices1, -1, self.set_thost1) gridSizer.Add(self.choices1, 0, wx.wxEXPAND) b = wx.wxBoxSizer(wx.wxHORIZONTAL) button1 = wx.wxButton(panel, -1, 'set default') wx.EVT_BUTTON(frame, button1.GetId(), self.set_default_thost) b.Add(button1, 0) b.Add(wx.wxStaticText(panel, -1, ' ')) button2 = wx.wxButton(panel, -1, 'delete') wx.EVT_BUTTON(frame, button2.GetId(), self.delete_thost) b.Add(button2, 0) b.Add(wx.wxStaticText(panel, -1, ' ')) button3 = wx.wxButton(panel, -1, 'save as...') wx.EVT_BUTTON(frame, button3.GetId(), self.save_thost) b.Add(button3, 0) gridSizer.Add(wx.wxStaticText(panel, -1, '')) gridSizer.Add(b, 0, wx.wxALIGN_CENTER) gridSizer.Add(wx.wxStaticText(panel, -1, '')) gridSizer.Add(wx.wxStaticText(panel, -1, '')) gridSizer.Add(wx.wxStaticText(panel, -1, 'single tracker url:'), 0, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL) self.annCtl = wx.wxTextCtrl(panel, -1, 'http://my.tracker:6969/announce') gridSizer.Add(self.annCtl, 0, wx.wxEXPAND) a = wx.wxFlexGridSizer(cols=1, vgap=3) a.Add(wx.wxStaticText(panel, -1, 'tracker list:'), 0, wx.wxALIGN_RIGHT) a.Add(wx.wxStaticText(panel, -1, '')) abutton = wx.wxButton(panel, -1, 'copy\nannounces\nfrom\ntorrent', size=(70, 70)) wx.EVT_BUTTON(frame, abutton.GetId(), self.announcecopy) a.Add(abutton, -1, wx.wxALIGN_CENTER) a.Add(wx.wxStaticText(panel, -1, DROP_HERE), -1, wx.wxALIGN_CENTER) gridSizer.Add(a, -1, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL) self.annListCtl = wx.wxTextCtrl( panel, -1, '\n\n\n\n\n', wx.wxPoint(-1, -1), (300, 120), wx.wxTE_MULTILINE | wx.wxHSCROLL | wx.wxTE_DONTWRAP) gridSizer.Add(self.annListCtl, -1, wx.wxEXPAND) gridSizer.Add(wx.wxStaticText(panel, -1, '')) exptext = wx.wxStaticText( panel, -1, 'a list of tracker urls separated by commas or ' 'whitespace\nand on several lines -trackers on the same line will ' 'be\ntried randomly, and all the trackers on one line\nwill be ' 'tried before the trackers on the next line.') exptext.SetFont( wx.wxFont(6, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, False)) gridSizer.Add(exptext, -1, wx.wxALIGN_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.wxStaticText(panel, -1, '')) gridSizer.Add(wx.wxStaticText(panel, -1, '')) gridSizer.Add(wx.wxStaticText(panel, -1, 'piece size:'), 0, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL) self.piece_length = wx.wxChoice(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.wxStaticText(panel, -1, 'comment:'), 0, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL) self.commentCtl = wx.wxTextCtrl(panel, -1, '') gridSizer.Add(self.commentCtl, 0, wx.wxEXPAND) gridSizer.Add(wx.wxStaticText(panel, -1, '')) gridSizer.Add(wx.wxStaticText(panel, -1, '')) b1 = wx.wxButton(panel, -1, 'Cancel', size=(-1, 30)) wx.EVT_BUTTON(frame, b1.GetId(), self.cancel) gridSizer.Add(b1, 0, wx.wxEXPAND) b2 = wx.wxButton(panel, -1, 'MAKE TORRENT', size=(-1, 30)) wx.EVT_BUTTON(frame, b2.GetId(), self.complete) gridSizer.Add(b2, 0, wx.wxEXPAND) gridSizer.AddGrowableCol(1) colSizer.Add(gridSizer, -1, wx.wxALIGN_CENTER_VERTICAL) fullSizer.Add(colSizer) border = wx.wxBoxSizer(wx.wxHORIZONTAL) border.Add(fullSizer, 1, wx.wxEXPAND | wx.wxALL, 15) panel.SetSizer(border) panel.SetAutoLayout(True) border.Fit(panel) frame.Fit() frame.Show(True) EVT_INVOKE(frame, self.onInvoke) wx.EVT_CLOSE(frame, self._close)
def __init__(self, config, calls): self.config = config self.calls = calls self.uiflag = threading.Event() self.cancelflag = threading.Event() self.switchlock = threading.Lock() self.working = False self.queue = [] wx.wxInitAllImageHandlers() self.thostselection = self.calls['getCurrentTHost']() self.thostselectnum = 0 self.choices = None self.choices1 = None self.announce = '' self.announce_list = None self.windowStyle = wx.wxSYSTEM_MENU | wx.wxCAPTION | wx.wxMINIMIZE_BOX if self.config['stayontop']: self.windowStyle |= wx.wxSTAY_ON_TOP frame = wx.wxFrame(None, -1, 'T-Make', size=wx.wxSize(-1, -1), style=self.windowStyle) self.frame = frame panel = wx.wxPanel(frame, -1) mainSizer = wx.wxBoxSizer(wx.wxVERTICAL) groupSizer = wx.wxFlexGridSizer(cols=1, vgap=0, hgap=0) # self.dropTarget = self.calls['newDropTarget']((200, 200)) self.dropTarget = self.calls['newDropTarget']() self.dropTargetPtr = wx.wxStaticBitmap(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.wxALIGN_CENTER) lowerSizer1 = wx.wxGridSizer(cols=6) dirlink = wx.wxStaticText(panel, -1, 'dir') dirlink.SetFont( wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) dirlink.SetForegroundColour('blue') wx.EVT_LEFT_UP(dirlink, self.selectdir) lowerSizer1.Add(dirlink, -1, wx.wxALIGN_LEFT) lowerSizer1.Add(wx.wxStaticText(panel, -1, ''), -1, wx.wxALIGN_CENTER) lowerSizer1.Add(wx.wxStaticText(panel, -1, ''), -1, wx.wxALIGN_CENTER) lowerSizer1.Add(wx.wxStaticText(panel, -1, ''), -1, wx.wxALIGN_CENTER) lowerSizer1.Add(wx.wxStaticText(panel, -1, ''), -1, wx.wxALIGN_CENTER) filelink = wx.wxStaticText(panel, -1, 'file') filelink.SetFont( wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) filelink.SetForegroundColour('blue') wx.EVT_LEFT_UP(filelink, self.selectfile) lowerSizer1.Add(filelink, -1, wx.wxALIGN_RIGHT) groupSizer.Add(lowerSizer1, -1, wx.wxALIGN_CENTER) self.gauge = wx.wxGauge(panel, -1, range=1000, style=wx.wxGA_HORIZONTAL, size=(-1, 15)) groupSizer.Add(self.gauge, 0, wx.wxEXPAND) self.statustext = wx.wxStaticText(panel, -1, 'ready', style=wx.wxALIGN_CENTER | wx.wxST_NO_AUTORESIZE) self.statustext.SetFont( wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxBOLD, False)) groupSizer.Add(self.statustext, -1, wx.wxEXPAND) self.choices = wx.wxChoice(panel, -1, (-1, -1), (self.dropTargetWidth, -1), choices=[]) self.choices.SetFont( wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, False)) wx.EVT_CHOICE(self.choices, -1, self.set_thost) groupSizer.Add(self.choices, 0, wx.wxEXPAND) cancellink = wx.wxStaticText(panel, -1, 'cancel') cancellink.SetFont( wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) cancellink.SetForegroundColour('red') wx.EVT_LEFT_UP(cancellink, self.cancel) groupSizer.Add(cancellink, -1, wx.wxALIGN_CENTER) advlink = wx.wxStaticText(panel, -1, 'advanced') advlink.SetFont( wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) advlink.SetForegroundColour('blue') wx.EVT_LEFT_UP(advlink, self.calls['switchToAdvanced']) groupSizer.Add(advlink, -1, wx.wxALIGN_CENTER) mainSizer.Add(groupSizer, 0, wx.wxALIGN_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) EVT_INVOKE(frame, self.onInvoke) wx.EVT_CLOSE(frame, self._close)
def OpenFile(parent, path): #FIXME: support: svg, sgvz, svg.gz with rsvg or batik (render to temporary #file /tmp/<PID><time()><atime(f.svg>.png and then open a frame) if not os.path.exists(path) or os.path.isdir(path): return frame = wxFrame(parent, -1, "File view: " + path, wxDefaultPosition, wxSize(500, 400)) handled = 0 needFrame = 1 lowerPath = string.lower(path) #for animations or to see if count is > 0: #wxImage_GetImageCount(path) if lowerPath[-3:] in ("ani", "bmp", "cur", "gif", "ico", "iff", "jpg", "pcx", "png", "pnm", \ "tif", "xpm") or lowerPath[-4:] in ("jpeg", "tiff"): #f = open(path, "rb"); data = f.read(); f.close() #stream = StringIO(data) #img = wxImageFromStream(stream) img = wxEmptyImage() img.LoadFile(path) bmp = wxBitmapFromImage(img) #wxStaticBitmap(frame, -1, bmp) #, (15, 45)) width, height = img.GetWidth(), img.GetHeight() if width and height: sw = wxScrolledWindow(frame, -1, wxDefaultPosition, wxDefaultSize, wxHSCROLL | wxVSCROLL) #sw.SetScrollbars(20, 20, img.GetWidth()/20, img.GetHeight()/20) sw.SetVirtualSize(wxSize(width, height)) sw.SetScrollRate(20, 20) wxStaticBitmap(sw, -1, bmp) #, (15, 45)) w, h = 800, 600 #frame.GetSize() w, h = min(w, width), min(h, height) minSize, b = 100, 10 if w < minSize: w = minSize if h < minSize: h = minSize frame.SetSize(wxSize(w + b, h + b)) handled = 1 elif "html" == lowerPath[-4:] or "htm" == path[-3:]: htmlWin = wxHtmlWindow(frame) htmlWin.LoadPage(path) handled = 1 elif "pdf" == lowerPath[-3:]: for cmd in ("xpdf", "acroread"): #FIXME: handle names that contain spaces etc. status, output = commands.getstatusoutput(cmd + " " + path) if 0 == status: handled = 1 needFrame = 0 break #FIXME: mplayer cannot run in background; same goes for Python calling mplayer externally - probably stdin dependence elif "mpeg" == lowerPath[-4:] or \ lowerPath[-3:] in ("asf", "avi", "mov", "mpa", "mpg", "wmv"): for cmd in ("mplayer -quiet", ): #FIXME: handle names that contain spaces etc. status, output = commands.getstatusoutput(cmd + " " + path) if 0 == status: handled = 1 needFrame = 0 break elif "ps" == lowerPath[-2:] or "ps.gz" == lowerPath[-5:]: pid = os.fork() if 0 == pid: for cmd in ("ggv", "gv"): try: os.execlp(cmd, cmd, path) except OSError: pass os.exit(1) handled = 1 needFrame = 0 if not handled: minSize = 65536 try: f = open(path, "rb") data = f.read(minSize) f.close() except IOError, ex: MsgOS(ex) return None txt = wxTextCtrl(frame, -1, data, style=wxTE_READONLY | wxTE_MULTILINE | wxTE_DONTWRAP | wxHSCROLL) if len(data) == minSize: sizer = wxBoxSizer(wxVERTICAL) frame.SetAutoLayout(true) frame.SetSizer(sizer) frame.sizer = sizer b = wxButton(frame, -1, "Show entire file") sizer.Add(txt, 1, wxEXPAND | wxALL, 0) sizer.Add(b, 0, wxALIGN_CENTRE, 0) sizer.Layout()
def __init__(self, config, calls): self.config = config self.calls = calls self.uiflag = threading.Event() self.cancelflag = threading.Event() self.switchlock = threading.Lock() self.working = False self.queue = [] wx.wxInitAllImageHandlers() self.thostselection = self.calls["getCurrentTHost"]() self.thostselectnum = 0 self.choices = None self.choices1 = None self.announce = "" self.announce_list = None self.windowStyle = wx.wxSYSTEM_MENU | wx.wxCAPTION | wx.wxMINIMIZE_BOX if self.config["stayontop"]: self.windowStyle |= wx.wxSTAY_ON_TOP frame = wx.wxFrame(None, -1, "T-Make", size=wx.wxSize(-1, -1), style=self.windowStyle) self.frame = frame panel = wx.wxPanel(frame, -1) mainSizer = wx.wxBoxSizer(wx.wxVERTICAL) groupSizer = wx.wxFlexGridSizer(cols=1, vgap=0, hgap=0) # self.dropTarget = self.calls['newDropTarget']((200, 200)) self.dropTarget = self.calls["newDropTarget"]() self.dropTargetPtr = wx.wxStaticBitmap(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.wxALIGN_CENTER) lowerSizer1 = wx.wxGridSizer(cols=6) dirlink = wx.wxStaticText(panel, -1, "dir") dirlink.SetFont(wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) dirlink.SetForegroundColour("blue") wx.EVT_LEFT_UP(dirlink, self.selectdir) lowerSizer1.Add(dirlink, -1, wx.wxALIGN_LEFT) lowerSizer1.Add(wx.wxStaticText(panel, -1, ""), -1, wx.wxALIGN_CENTER) lowerSizer1.Add(wx.wxStaticText(panel, -1, ""), -1, wx.wxALIGN_CENTER) lowerSizer1.Add(wx.wxStaticText(panel, -1, ""), -1, wx.wxALIGN_CENTER) lowerSizer1.Add(wx.wxStaticText(panel, -1, ""), -1, wx.wxALIGN_CENTER) filelink = wx.wxStaticText(panel, -1, "file") filelink.SetFont(wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) filelink.SetForegroundColour("blue") wx.EVT_LEFT_UP(filelink, self.selectfile) lowerSizer1.Add(filelink, -1, wx.wxALIGN_RIGHT) groupSizer.Add(lowerSizer1, -1, wx.wxALIGN_CENTER) self.gauge = wx.wxGauge(panel, -1, range=1000, style=wx.wxGA_HORIZONTAL, size=(-1, 15)) groupSizer.Add(self.gauge, 0, wx.wxEXPAND) self.statustext = wx.wxStaticText(panel, -1, "ready", style=wx.wxALIGN_CENTER | wx.wxST_NO_AUTORESIZE) self.statustext.SetFont(wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxBOLD, False)) groupSizer.Add(self.statustext, -1, wx.wxEXPAND) self.choices = wx.wxChoice(panel, -1, (-1, -1), (self.dropTargetWidth, -1), choices=[]) self.choices.SetFont(wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, False)) wx.EVT_CHOICE(self.choices, -1, self.set_thost) groupSizer.Add(self.choices, 0, wx.wxEXPAND) cancellink = wx.wxStaticText(panel, -1, "cancel") cancellink.SetFont(wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) cancellink.SetForegroundColour("red") wx.EVT_LEFT_UP(cancellink, self.cancel) groupSizer.Add(cancellink, -1, wx.wxALIGN_CENTER) advlink = wx.wxStaticText(panel, -1, "advanced") advlink.SetFont(wx.wxFont(7, wx.wxDEFAULT, wx.wxNORMAL, wx.wxNORMAL, True)) advlink.SetForegroundColour("blue") wx.EVT_LEFT_UP(advlink, self.calls["switchToAdvanced"]) groupSizer.Add(advlink, -1, wx.wxALIGN_CENTER) mainSizer.Add(groupSizer, 0, wx.wxALIGN_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) EVT_INVOKE(frame, self.onInvoke) wx.EVT_CLOSE(frame, self._close)
def __init__(self, parent, id, file, data, isValidCallback = None, pos = wx.wxDefaultPosition, size = wx.wxDefaultSize, style = wx.wxTAB_TRAVERSAL, name = "ImportWizardPanel"): wx.wxPanel.__init__(self, parent, id, pos, size, style, name) self.SetAutoLayout(wx.true) mainSizer = wx.wxFlexGridSizer(3, 1) self.SetSizer(mainSizer) mainSizer.AddGrowableCol(0) self.initialized = wx.false self.data = data self.isValidCallback = isValidCallback self.Validate = (isValidCallback and self.Validate) or self.BuildPreview dlg = wx.wxProgressDialog("Import Wizard", "Analyzing %s... Please wait." % file, 3, parent, wx.wxPD_APP_MODAL | wx.wxPD_AUTO_HIDE) textQualifier = guessTextQualifier(data) dlg.Update(1) newdata = organizeIntoLines(data, textQualifier = textQualifier, limit = 100) dlg.Update(2) delimiter = guessDelimiter(newdata, textQualifier = textQualifier) dlg.Update(3) dlg.Destroy() # ------------- msg = ("This screen lets you set the delimiters your data contains.\n" "You can see how your data is affected in the preview below.") message1 = wx.wxStaticText(self, -1, msg) # ------------- delimiterBox = wx.wxBoxSizer(wx.wxHORIZONTAL) delimStaticBox = wx.wxStaticBox(self, -1, "Delimiters") delimStaticSizer = wx.wxStaticBoxSizer(delimStaticBox, wx.wxVERTICAL) delimGridSizer = wx.wxFlexGridSizer(2, 3) delims = { 'Tab': '\t', 'Semicolon': ';', 'Comma': ',', 'Space': ' ', } self.delimChecks = {} for label, value in delims.items(): self.delimChecks[value] = wx.wxCheckBox(self, -1, label) delimGridSizer.Add(self.delimChecks[value], 0, wx.wxALL, 3) wx.EVT_CHECKBOX(self, self.delimChecks[value].GetId(), self.Validate) otherSizer = wx.wxBoxSizer(wx.wxHORIZONTAL) self.delimChecks['Other'] = wx.wxCheckBox(self, -1, 'Other:') wx.EVT_CHECKBOX(self, self.delimChecks['Other'].GetId(), self.Validate) self.otherDelim = wx.wxTextCtrl(self, -1, size = (20, -1)) wx.EVT_TEXT(self, self.otherDelim.GetId(), self.OnCustomDelim) if self.delimChecks.has_key(delimiter): self.delimChecks[delimiter].SetValue(wx.true) elif delimiter is not None: self.delimChecks['Other'].SetValue(wx.true) self.otherDelim.SetValue(delimiter) otherSizer.AddMany([ (self.delimChecks['Other'], 0, wx.wxALL, 3), (self.otherDelim, 0, wx.wxALIGN_CENTER), ]) delimGridSizer.Add(otherSizer) delimStaticSizer.Add(delimGridSizer, 1, wx.wxEXPAND) delimOtherSizer = wx.wxBoxSizer(wx.wxVERTICAL) self.consecutiveDelimsAs1 = wx.wxCheckBox(self, -1, "Treat consecutive delimiters as one") self.consecutiveDelimsAs1.Enable(wx.false) tqSizer = wx.wxBoxSizer(wx.wxHORIZONTAL) self.textQualifierChoice = wx.wxChoice(self, -1, choices = ['"', "'", "{None}"]) wx.EVT_CHOICE(self, self.textQualifierChoice.GetId(), self.BuildPreview) if textQualifier is not None: self.textQualifierChoice.SetStringSelection(textQualifier) else: self.textQualifierChoice.SetStringSelection('{None}') tqSizer.AddMany([ (wx.wxStaticText(self, -1, "Text qualifier:"), 0, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL), (self.textQualifierChoice, 0, wx.wxALL | wx.wxALIGN_LEFT | wx.wxALIGN_CENTER_VERTICAL, 5), ]) delimOtherSizer.AddMany([ (self.consecutiveDelimsAs1, 1, wx.wxEXPAND | wx.wxALL, 5), (tqSizer, 1, wx.wxALL | wx.wxALIGN_CENTER, 5), ]) delimiterBox.AddMany([ (delimStaticSizer, 0, wx.wxALIGN_CENTER), (delimOtherSizer, 0, wx.wxALIGN_CENTER), ]) delimStaticBox.Fit() # ------------- self.displayRows = 6 previewSettingsBox = wx.wxBoxSizer(wx.wxHORIZONTAL) self.hasHeaderRow = wx.wxCheckBox(self, -1, "First row is header") wx.EVT_CHECKBOX(self, self.hasHeaderRow.GetId(), self.BuildPreview) if wx.wxPlatform in ('__WX.WXGTK__', '__WX.WXMSW__'): # wx.wxSpinCtrl causes seg fault under GTK when <enter> is hit in text - use wx.wxSpinButton instead self.previewRowsText = wx.wxTextCtrl(self, -1, str(self.displayRows), size = (30, -1), style = wx.wxTE_PROCESS_ENTER) h = self.previewRowsText.GetSize().height self.previewRows = wx.wxSpinButton(self, -1, size = (-1, h), style = wx.wxSP_VERTICAL) self.previewRows.SetRange(self.displayRows, 100) self.previewRows.SetValue(self.displayRows) wx.EVT_SPIN(self, self.previewRows.GetId(), self.OnSpinPreviewRows) wx.EVT_TEXT_ENTER(self, self.previewRowsText.GetId(), self.OnTextPreviewRows) else: self.previewRows = wx.wxSpinCtrl(self, -1, str(self.displayRows), min = self.displayRows, max = 100, size = (50, -1)) wx.EVT_SPINCTRL(self, self.previewRows.GetId(), self.BuildPreview) previewSettingsBox.AddMany([ (self.hasHeaderRow, 1, wx.wxALL | wx.wxEXPAND, 5), (wx.wxStaticText(self, -1, "Preview"), 0, wx.wxWEST | wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL, 10), ]) if wx.wxPlatform in ('__WX.WXGTK__', '__WX.WXMSW__'): previewSettingsBox.Add(self.previewRowsText, 0, wx.wxALIGN_CENTER | wx.wxALL, 3) previewSettingsBox.AddMany([ (self.previewRows, 0, wx.wxALIGN_CENTER | wx.wxALL, 3), (wx.wxStaticText(self, -1, "rows"), 0, wx.wxALIGN_RIGHT | wx.wxALIGN_CENTER_VERTICAL), ]) # ------------- if delimiter is not None: previewData = importDSV(newdata[:self.displayRows], textQualifier = textQualifier, delimiter = delimiter, errorHandler = padRow) hasHeaders = guessHeaders(previewData) self.hasHeaderRow.SetValue(hasHeaders) cols = len(previewData[0]) else: previewData = [] hasHeaders = 0 cols = 1 previewStaticBox = wx.wxStaticBox(self, -1, "Data Preview") previewStaticSizer = wx.wxStaticBoxSizer(previewStaticBox, wx.wxVERTICAL) self.preview = grid.wxGrid(self, -1) self.preview.CreateGrid(self.displayRows, cols) self.preview.SetDefaultRowSize(self.preview.GetCharHeight() + 4, wx.true) self.preview.EnableEditing(wx.false) self.preview.SetColLabelSize(0) self.preview.SetRowLabelSize(0) self.preview.SetMargins(1, 0) self.initialized = wx.true self.BuildPreview() rowheight = self.preview.GetRowSize(0) + 2 self.preview.SetSize((-1, rowheight * self.displayRows)) previewStaticSizer.Add(self.preview, 0, wx.wxALL | wx.wxEXPAND, 5) # ------------- mainSizer.AddMany([ (message1, 0, wx.wxALL, 5), (delimiterBox, 0, wx.wxALL, 5), (previewSettingsBox, 0, wx.wxALL, 5), (previewStaticSizer, 0, wx.wxALL | wx.wxEXPAND, 5), ]) self.Layout() self.Fit()