def set_new_view(self, input_exp): if Fractal.is_working: return try: Fractal(ShowPanel.parent, input_exp) except Exception as e: error_content = '{}\n{}\n{}\n{}'.format(YOUR_EXP, input_exp, HAS_ERR, e.args[0]) ShowPanel.errDialog(error_content) StatusPanel.set_status(ERR_INVALID_EXP, StatusPanel.INFO_ERROR) return None ShowPanel.exp = input_exp info = self.__history[0] self.__history.clear() self.refresh_view(info.shiftx, info.shifty, info.rx, info.ry, True)
def __init__(self): super().__init__() self.initUI() Window.status_panel = StatusPanel(self) Window.ctrl_panel = ControlPanel(self) Window.show_panel = ShowPanel(self) self.show()
def refresh_hist_view(self, is_record): if ShowPanel.rect is None: ShowPanel.rect = Rectangle(0, 0, PIC_WIDTH, PIC_HEIGHT) info = self.__history[-1] shiftx = info.shiftx - info.rx / PIC_WIDTH * int( PIC_WIDTH // 2 - ShowPanel.rect.x - ShowPanel.rect.width // 2) * 2 * (-1 if ShowPanel.is_moving else 1) shifty = info.shifty - info.ry / PIC_HEIGHT * int( PIC_HEIGHT // 2 - ShowPanel.rect.y - ShowPanel.rect.height // 2) * 2 * (-1 if ShowPanel.is_moving else 1) rx = info.rx / (PIC_WIDTH / ShowPanel.rect.width) ry = info.ry / (PIC_HEIGHT / ShowPanel.rect.height) if rx < 1e-10 or ry < 1e-10: StatusPanel.set_status(ERR_TOO_LARGE_SCALE, StatusPanel.INFO_ERROR) return self.refresh_view(shiftx, shifty, rx, ry, is_record)
def test_interface_get_ready_to_go(self): """ GIVEN :engine, gearbox, electronics, status_panel WHEN :call get_ready_to_go interface THEN :return true """ self.assertTrue( self.ctrl.get_ready_to_go(Engine(), GearBox(), Electronics(), StatusPanel()))
def refresh_view(self, shiftx, shifty, rx, ry, is_record): StatusPanel.set_scale(INIT_RX * INIT_RY / (rx * ry)) StatusPanel.set_details(shiftx, shifty, rx, ry) if is_record: self.__history.append(ViewInfo(shiftx, shifty, rx, ry)) try: f = Fractal(ShowPanel.parent, ShowPanel.exp, ShowPanel.boost) except ValueError as e: ShowPanel.errDialog(e.args[0]) ShowPanel.exp = Fractal.last_exp return None try: f.createFractalImage(PIC_WIDTH, PIC_HEIGHT, shiftx, shifty, rx, ry) except Exception as e: ShowPanel.errDialog(e.args[0]) ShowPanel.exp = Fractal.last_exp raise e self.update_undo()
def update_status(self, w0, w1): if w0 == FINISHED_SIG or w1 == FINISHED_SIG: progress = FINISHED_SIG else: progress = w0 + w1 Fractal.pic = QPixmap(PIC_WIDTH, PIC_HEIGHT) painter = QPainter() painter.begin(Fractal.pic) painter.drawPixmap(0, 0, PIC_WIDTH, PIC_HEIGHT // 2, self.pic0) painter.drawPixmap(0, PIC_HEIGHT // 2, PIC_WIDTH, PIC_HEIGHT // 2, self.pic1) if FractalThread.workers[0] != FINISHED_SIG or FractalThread.workers[ 1] != FINISHED_SIG: h0 = PIC_WIDTH / 2 if w0 == FINISHED_SIG else w0 + 1 h1 = PIC_WIDTH / 2 if w1 == FINISHED_SIG else (PIC_HEIGHT - w1) - 1 try: painter.setPen(QPen(COLOR_UPDATE_LINE, WIDTH_UPDATE_LINE)) except Exception as e: print(e) painter.drawLine(0, h0, PIC_WIDTH, h0) painter.drawLine(0, h1, PIC_WIDTH, h1) painter.end() self.__root.update_pic(Fractal.pic) if progress != FINISHED_SIG: StatusPanel.set_status( '{:.2f}%'.format(progress * 100 / PIC_HEIGHT), StatusPanel.INFO_PROCESS) else: if FractalThread.workers[ 0] != FINISHED_SIG or FractalThread.workers[ 1] != FINISHED_SIG: return # Both workers are finished StatusPanel.set_status(time.clock() - self.t, StatusPanel.INFO_SUCCESS) Fractal.is_working = False
def createStatusPanel(): global statusPanel statusPanel = StatusPanel() return statusPanel
def setUp(self): self.ctrl = CarController() self.panel = StatusPanel() self.electronics = Electronics()
def __init__(self, progPath, config, torrentHandler, persister, version): self.progPath = progPath self.config = config self.torrentHandler = torrentHandler self.persister = persister self.version = version self.log = logging.getLogger("Gui") self.stopFlag = False ##locale self.locale = wx.Locale(wx.LANGUAGE_ENGLISH) ##Gui Stuff wx.Frame.__init__(self, None, -1, 'PyBit', size = wx.Size(800, 600), style = wx.DEFAULT_FRAME_STYLE | wx.CLIP_CHILDREN) self.CentreOnScreen() #Layoutmanager vBox = wx.BoxSizer(wx.VERTICAL) #Menu menubar = wx.MenuBar() file = wx.Menu() file.Append(101, 'Add (by File)', 'Opens a torrent from your harddisk') file.Append(102, 'Add (by Url)', 'Fetches a torrent via http and adds it afterwards') file.AppendSeparator() file.Append(103, 'Create', 'Creates a new torrent') file.AppendSeparator() file.Append(104, 'Quit', 'Terminates the program, this could take a few seconds') menubar.Append(file, '&File') config = wx.Menu() config.Append(121, 'Configuration', 'Opens a configuration dialog') menubar.Append(config, '&Config') about = wx.Menu() about.Append(131, 'About', 'Information about the version and the authors of this software') about.Append(132, 'Show Changelog', 'Shows the changlog of PyBit') about.Append(133, 'Show Readme', 'Shows the readme') menubar.Append(about, '&About') self.SetMenuBar(menubar) #Windows self.splitter = wx.SplitterWindow(self, style=wx.CLIP_CHILDREN) self.splitter.SetMinimumPaneSize(50) #Child Windows self.childWindows = StatusPanel(self.splitter) self.torrentStats = TorrentStats(self.torrentHandler.getStats, self.childWindows) self.torrentConnectionList = TorrentConnectionList(self.persister, self.version, self.torrentHandler.getStats, self.childWindows) self.torrentFileList = TorrentFileList(self.persister, self.version, self.torrentHandler.getStats, self.torrentHandler.setFilePriority, self.torrentHandler.setFileWantedFlag, self.childWindows) self.torrentRequestList = TorrentRequestList(self.persister, self.version, self.torrentHandler.getStats, self.childWindows) self.torrentTrackerList = TorrentTrackerList(self.persister, self.version, self.torrentHandler.getStats, self.torrentHandler.getTrackerInfo, self.torrentHandler.setTrackerInfo, self.childWindows) self.childWindows.addChild(self.torrentStats, 'General') self.childWindows.addChild(self.torrentConnectionList, 'Connections') self.childWindows.addChild(self.torrentFileList, 'Files') self.childWindows.addChild(self.torrentRequestList, 'Requests') self.childWindows.addChild(self.torrentTrackerList, 'Tracker') #Main Window self.torrentList = TorrentList(self.persister, self.version, self.torrentHandler, self.childWindows.changeTorrentId, self.torrentHandler.getStats, self.splitter) #startup the splitter self.splitter.SplitHorizontally(self.torrentList, self.childWindows) #Statusbar funcCaller = FunctionCallConverter(self.torrentHandler.getStats, funcKw={'wantedStats':{'transfer':True}}, resultFilter=['inRawSpeed', 'outRawSpeed'], resultFilterFormat='list') self.sb = StatusBar(funcCaller.callForValue, self) self.SetStatusBar(self.sb) #Toolbar toolbar = self.CreateToolBar() toolbar.SetToolBitmapSize(wx.Size(22,22)) toolbar.AddLabelTool(201, 'New', wx.BitmapFromImage(wx.Image('Icons/newFile.png', wx.BITMAP_TYPE_PNG)), shortHelp='Create Torrentfile', longHelp='Use to create a new torrent file') toolbar.AddLabelTool(202, 'Open File', wx.BitmapFromImage(wx.Image('Icons/openFile.png', wx.BITMAP_TYPE_PNG)), shortHelp='Open Torrentfile', longHelp='Use to open a torrent file') toolbar.AddLabelTool(203, 'Open Url', wx.BitmapFromImage(wx.Image('Icons/openUrl.png', wx.BITMAP_TYPE_PNG)), shortHelp='Fetch and open Torrentfile from url', longHelp='Use to fetch (and add) a torrent file via http') toolbar.AddSeparator() toolbar.AddLabelTool(211, 'Start',wx.BitmapFromImage(wx.Image('Icons/start.png', wx.BITMAP_TYPE_PNG)), shortHelp='Start', longHelp='Starts all selected torrents') toolbar.AddLabelTool(212, 'Stop',wx.BitmapFromImage(wx.Image('Icons/stop.png', wx.BITMAP_TYPE_PNG)), shortHelp='Stop', longHelp='Stops all selected torrents') toolbar.AddLabelTool(213, 'Remove',wx.BitmapFromImage(wx.Image('Icons/remove.png', wx.BITMAP_TYPE_PNG)), shortHelp='Remove', longHelp='Removes all selected torrents') toolbar.AddSeparator() toolbar.AddLabelTool(221, 'Up',wx.BitmapFromImage(wx.Image('Icons/up.png', wx.BITMAP_TYPE_PNG)), shortHelp='Up', longHelp='Moves all selected torrents one row up') toolbar.AddLabelTool(222, 'Down',wx.BitmapFromImage(wx.Image('Icons/down.png', wx.BITMAP_TYPE_PNG)), shortHelp='Down', longHelp='Moves all selected torrents one row down') toolbar.AddSeparator() toolbar.AddLabelTool(231, 'Quit', wx.BitmapFromImage(wx.Image('Icons/quit.png', wx.BITMAP_TYPE_PNG)), shortHelp='Quit', longHelp='Quits the application, this could take a moment.') toolbar.Realize() #menu events self.Bind(wx.EVT_MENU, self.OnAddFromFile, id=101) self.Bind(wx.EVT_MENU, self.OnAddFromUrl, id=102) self.Bind(wx.EVT_MENU, self.OnCreateTorrent, id=103) self.Bind(wx.EVT_MENU, self.OnClose, id=104) self.Bind(wx.EVT_MENU, self.OnConfig, id=121) self.Bind(wx.EVT_MENU, self.OnAbout, id=131) self.Bind(wx.EVT_MENU, self.OnChangelog, id=132) self.Bind(wx.EVT_MENU, self.OnReadme, id=133) #toolbar events self.Bind(wx.EVT_TOOL, self.OnCreateTorrent, id=201) self.Bind(wx.EVT_TOOL, self.OnAddFromFile, id=202) self.Bind(wx.EVT_TOOL, self.OnAddFromUrl, id=203) self.Bind(wx.EVT_TOOL, self.torrentList.OnStart, id=211) self.Bind(wx.EVT_TOOL, self.torrentList.OnStop, id=212) self.Bind(wx.EVT_TOOL, self.torrentList.OnRemove, id=213) self.Bind(wx.EVT_TOOL, self.torrentList.OnUp, id=221) self.Bind(wx.EVT_TOOL, self.torrentList.OnDown, id=222) self.Bind(wx.EVT_TOOL, self.OnClose, id=231) #other events self.Bind(wx.EVT_CLOSE, self.OnClose) self.Show(True) #updater self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) self.timer.Start(1000)
class Gui(wx.Frame): def __init__(self, progPath, config, torrentHandler, persister, version): self.progPath = progPath self.config = config self.torrentHandler = torrentHandler self.persister = persister self.version = version self.log = logging.getLogger("Gui") self.stopFlag = False ##locale self.locale = wx.Locale(wx.LANGUAGE_ENGLISH) ##Gui Stuff wx.Frame.__init__(self, None, -1, 'PyBit', size = wx.Size(800, 600), style = wx.DEFAULT_FRAME_STYLE | wx.CLIP_CHILDREN) self.CentreOnScreen() #Layoutmanager vBox = wx.BoxSizer(wx.VERTICAL) #Menu menubar = wx.MenuBar() file = wx.Menu() file.Append(101, 'Add (by File)', 'Opens a torrent from your harddisk') file.Append(102, 'Add (by Url)', 'Fetches a torrent via http and adds it afterwards') file.AppendSeparator() file.Append(103, 'Create', 'Creates a new torrent') file.AppendSeparator() file.Append(104, 'Quit', 'Terminates the program, this could take a few seconds') menubar.Append(file, '&File') config = wx.Menu() config.Append(121, 'Configuration', 'Opens a configuration dialog') menubar.Append(config, '&Config') about = wx.Menu() about.Append(131, 'About', 'Information about the version and the authors of this software') about.Append(132, 'Show Changelog', 'Shows the changlog of PyBit') about.Append(133, 'Show Readme', 'Shows the readme') menubar.Append(about, '&About') self.SetMenuBar(menubar) #Windows self.splitter = wx.SplitterWindow(self, style=wx.CLIP_CHILDREN) self.splitter.SetMinimumPaneSize(50) #Child Windows self.childWindows = StatusPanel(self.splitter) self.torrentStats = TorrentStats(self.torrentHandler.getStats, self.childWindows) self.torrentConnectionList = TorrentConnectionList(self.persister, self.version, self.torrentHandler.getStats, self.childWindows) self.torrentFileList = TorrentFileList(self.persister, self.version, self.torrentHandler.getStats, self.torrentHandler.setFilePriority, self.torrentHandler.setFileWantedFlag, self.childWindows) self.torrentRequestList = TorrentRequestList(self.persister, self.version, self.torrentHandler.getStats, self.childWindows) self.torrentTrackerList = TorrentTrackerList(self.persister, self.version, self.torrentHandler.getStats, self.torrentHandler.getTrackerInfo, self.torrentHandler.setTrackerInfo, self.childWindows) self.childWindows.addChild(self.torrentStats, 'General') self.childWindows.addChild(self.torrentConnectionList, 'Connections') self.childWindows.addChild(self.torrentFileList, 'Files') self.childWindows.addChild(self.torrentRequestList, 'Requests') self.childWindows.addChild(self.torrentTrackerList, 'Tracker') #Main Window self.torrentList = TorrentList(self.persister, self.version, self.torrentHandler, self.childWindows.changeTorrentId, self.torrentHandler.getStats, self.splitter) #startup the splitter self.splitter.SplitHorizontally(self.torrentList, self.childWindows) #Statusbar funcCaller = FunctionCallConverter(self.torrentHandler.getStats, funcKw={'wantedStats':{'transfer':True}}, resultFilter=['inRawSpeed', 'outRawSpeed'], resultFilterFormat='list') self.sb = StatusBar(funcCaller.callForValue, self) self.SetStatusBar(self.sb) #Toolbar toolbar = self.CreateToolBar() toolbar.SetToolBitmapSize(wx.Size(22,22)) toolbar.AddLabelTool(201, 'New', wx.BitmapFromImage(wx.Image('Icons/newFile.png', wx.BITMAP_TYPE_PNG)), shortHelp='Create Torrentfile', longHelp='Use to create a new torrent file') toolbar.AddLabelTool(202, 'Open File', wx.BitmapFromImage(wx.Image('Icons/openFile.png', wx.BITMAP_TYPE_PNG)), shortHelp='Open Torrentfile', longHelp='Use to open a torrent file') toolbar.AddLabelTool(203, 'Open Url', wx.BitmapFromImage(wx.Image('Icons/openUrl.png', wx.BITMAP_TYPE_PNG)), shortHelp='Fetch and open Torrentfile from url', longHelp='Use to fetch (and add) a torrent file via http') toolbar.AddSeparator() toolbar.AddLabelTool(211, 'Start',wx.BitmapFromImage(wx.Image('Icons/start.png', wx.BITMAP_TYPE_PNG)), shortHelp='Start', longHelp='Starts all selected torrents') toolbar.AddLabelTool(212, 'Stop',wx.BitmapFromImage(wx.Image('Icons/stop.png', wx.BITMAP_TYPE_PNG)), shortHelp='Stop', longHelp='Stops all selected torrents') toolbar.AddLabelTool(213, 'Remove',wx.BitmapFromImage(wx.Image('Icons/remove.png', wx.BITMAP_TYPE_PNG)), shortHelp='Remove', longHelp='Removes all selected torrents') toolbar.AddSeparator() toolbar.AddLabelTool(221, 'Up',wx.BitmapFromImage(wx.Image('Icons/up.png', wx.BITMAP_TYPE_PNG)), shortHelp='Up', longHelp='Moves all selected torrents one row up') toolbar.AddLabelTool(222, 'Down',wx.BitmapFromImage(wx.Image('Icons/down.png', wx.BITMAP_TYPE_PNG)), shortHelp='Down', longHelp='Moves all selected torrents one row down') toolbar.AddSeparator() toolbar.AddLabelTool(231, 'Quit', wx.BitmapFromImage(wx.Image('Icons/quit.png', wx.BITMAP_TYPE_PNG)), shortHelp='Quit', longHelp='Quits the application, this could take a moment.') toolbar.Realize() #menu events self.Bind(wx.EVT_MENU, self.OnAddFromFile, id=101) self.Bind(wx.EVT_MENU, self.OnAddFromUrl, id=102) self.Bind(wx.EVT_MENU, self.OnCreateTorrent, id=103) self.Bind(wx.EVT_MENU, self.OnClose, id=104) self.Bind(wx.EVT_MENU, self.OnConfig, id=121) self.Bind(wx.EVT_MENU, self.OnAbout, id=131) self.Bind(wx.EVT_MENU, self.OnChangelog, id=132) self.Bind(wx.EVT_MENU, self.OnReadme, id=133) #toolbar events self.Bind(wx.EVT_TOOL, self.OnCreateTorrent, id=201) self.Bind(wx.EVT_TOOL, self.OnAddFromFile, id=202) self.Bind(wx.EVT_TOOL, self.OnAddFromUrl, id=203) self.Bind(wx.EVT_TOOL, self.torrentList.OnStart, id=211) self.Bind(wx.EVT_TOOL, self.torrentList.OnStop, id=212) self.Bind(wx.EVT_TOOL, self.torrentList.OnRemove, id=213) self.Bind(wx.EVT_TOOL, self.torrentList.OnUp, id=221) self.Bind(wx.EVT_TOOL, self.torrentList.OnDown, id=222) self.Bind(wx.EVT_TOOL, self.OnClose, id=231) #other events self.Bind(wx.EVT_CLOSE, self.OnClose) self.Show(True) #updater self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) self.timer.Start(1000) def OnTimer(self, event): try: if not self.stopFlag: #update Torrentlist self.torrentList.manualUpdate() self.childWindows.manualUpdate() #update Statusbar self.sb.manualUpdate() except: self.log.error("Failure in timer:\n%s", logTraceback()) def OnAddFromFile(self, event): #torrentpath torrentDefaultDir = self.config.get('paths','torrentFolder') downloadDefaultDir = self.config.get('paths','downloadFolder') #let user select a torrent diag = wx.FileDialog(self, message='Select the torrent to open',defaultDir=torrentDefaultDir,\ wildcard='Torrent files (*.torrent)|*.torrent|All files (*.*)|*.*',\ style=wx.OPEN | wx.MULTIPLE) if diag.ShowModal() == wx.ID_OK: #user did select something torrentPaths = diag.GetPaths() #directory in which the download data should be stored saveDiag = wx.DirDialog(self, message='Select the directory in which the downloaded data should be stored',\ defaultPath=downloadDefaultDir,style=wx.DD_NEW_DIR_BUTTON) if saveDiag.ShowModal() == wx.ID_OK: #user selected something savePath = saveDiag.GetPath() #load torrents one by one for torrentPath in torrentPaths: self.log.info('Trying to read torrent file from "%s"', torrentPath) try: fl = open(torrentPath, 'rb') with fl: data = fl.read() except (IOError, OSError): data = None if data is None: #failed to read file self.log.error('Failed to read torrent file from "%s", torrent not added', torrentPath) showErrorMessage(self, 'Failed to read torrent file from "%s".', torrentPath) else: #worked self.log.info('Adding torrent with data path "%s"', savePath) try: self.torrentList.addTorrentByFile(data, savePath) except MultiBtException, e: self.log.error('Failed to add torrent, reason: %s', e.reason) showErrorMessage(self, '%s.', e.reason) except Exception, e: self.log.critical('Internal error while adding torrent:\n%s', logTraceback()) showErrorMessage(self, 'Internal error, torrent not added.\n%s.', logTraceback()) del saveDiag