def __init__(self, parent, title, fName=None, html=None): wx.Frame.__init__(self, parent, -1, title, size=(600, 400)) assert (fName is None or html is None) self.win = wx.html.HtmlWindow(self, -1) if fName is not None: fn = os.path.join(getHome(), fName) self.win.LoadFile(fn) if html is not None: self.win.SetPage(html)
def __init__(self, parent, title, fName=None, html=None): wx.Frame.__init__(self, parent, -1, title, size=(600, 400)) assert(fName is None or html is None) self.win = wx.html.HtmlWindow(self, -1) if fName is not None: fn = os.path.join(getHome(), fName) self.win.LoadFile(fn) if html is not None: self.win.SetPage(html)
def OnInit(self): # Show a splash screen png = os.path.join(getHome(), "Icons", "splash.png") bmp = wx.Image(png).ConvertToBitmap() wx.SplashScreen(bmp, wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT, 5000, None, -1) self.frame = Frame(None) self.frame.Show(True) self.frame.Center() self.frame.Raise() self.SetTopWindow(self.frame) return True
def OnInit(self): wx.InitAllImageHandlers() # Show a splash screen png = os.path.join(getHome(), "Icons", "splash.png") bmp = wx.Image(png).ConvertToBitmap() wx.SplashScreen(bmp, wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT, 5000, None, -1) self.frame = Frame(None) self.frame.Show(True) self.frame.Center() self.frame.Raise() self.SetTopWindow(self.frame) return True
def __init__(self, parent): wx.Dialog.__init__(self, parent, -1, "About OpenSTV") sizer = wx.BoxSizer(wx.VERTICAL) fn = os.path.join(getHome(), "Icons", "splash.png") bmp = wx.Image(fn, wx.BITMAP_TYPE_PNG).ConvertToBitmap() bm = wx.StaticBitmap(self, -1, bmp) sizer.Add(bm) button = wx.Button(self, wx.ID_OK, "Close") button.SetDefault() sizer.Add(button, 0, wx.ALIGN_CENTER|wx.ALL, 5) sizer.Fit(self) self.SetAutoLayout(True) self.SetSizer(sizer)
def getPlugins(package, baseClass, format, exclude0): """Find plugins of a specified type. Each plugin has a status value that may be 0, 1, or 2. For status=0, the plugin is excluded by default, but will be included if exclude0 is set to False. For Method plugins, status=1 or 2 indicates whether the method appears in the fist tier list or second tier list. For Loader and Report plugins there is only one tier. """ assert (format in ["byName", "classes"]) # Import all modules in package ppath = package.__path__ pname = package.__name__ + "." for importer, modname, ispkg in pkgutil.iter_modules(ppath, pname): module = __import__(modname, fromlist="dummy") # Look for user-installed plugins externalPluginDir = os.path.join(getHome(), "Plugins") if os.path.exists(externalPluginDir): if externalPluginDir not in sys.path: sys.path.append(externalPluginDir) externalPlugins = [ x[:-3] for x in os.listdir(externalPluginDir) if x.endswith(".py") ] for plugin in externalPlugins: __import__(plugin) # Get plugin list from subclasses of baseClass pluginClasses = [] for m in baseClass.__subclasses__(): if exclude0 and m.status == 0: del m else: pluginClasses.append(m) if format == "classes": return pluginClasses elif format == "byName": pluginClass = {} for p in pluginClasses: pluginClass[p.__name__] = p return pluginClass else: assert (0)
def __init__(self, parent): wx.Dialog.__init__(self, parent, -1, "About OpenSTV") sizer = wx.BoxSizer(wx.VERTICAL) fn = os.path.join(getHome(), "Icons", "splash.png") bmp = wx.Image(fn, wx.BITMAP_TYPE_PNG).ConvertToBitmap() bm = wx.StaticBitmap(self, -1, bmp) sizer.Add(bm) button = wx.Button(self, wx.ID_OK, "Close") button.SetDefault() sizer.Add(button, 0, wx.ALIGN_CENTER | wx.ALL, 5) sizer.Fit(self) self.SetAutoLayout(True) self.SetSizer(sizer)
def getPlugins(package, baseClass, format, exclude0): """Find plugins of a specified type. Each plugin has a status value that may be 0, 1, or 2. For status=0, the plugin is excluded by default, but will be included if exclude0 is set to False. For Method plugins, status=1 or 2 indicates whether the method appears in the fist tier list or second tier list. For Loader and Report plugins there is only one tier. """ assert(format in ["byName", "classes"]) # Import all modules in package ppath = package.__path__ pname = package.__name__ + "." for importer, modname, ispkg in pkgutil.iter_modules(ppath, pname): module = __import__(modname, fromlist = "dummy") # Look for user-installed plugins externalPluginDir = os.path.join(getHome(), "Plugins") if os.path.exists(externalPluginDir): if externalPluginDir not in sys.path: sys.path.append(externalPluginDir) externalPlugins = [x[:-3] for x in os.listdir(externalPluginDir) if x.endswith(".py")] for plugin in externalPlugins: __import__(plugin) # Get plugin list from subclasses of baseClass pluginClasses = [] for m in baseClass.__subclasses__(): if exclude0 and m.status == 0: del m else: pluginClasses.append(m) if format == "classes": return pluginClasses elif format == "byName": pluginClass = {} for p in pluginClasses: pluginClass[p.__name__] = p return pluginClass else: assert(0)
def __init__(self, parent): wx.Frame.__init__(self, parent, -1, "OpenSTV", size=(900, 600)) warnings.showwarning = self.catchWarnings # Get method plugins and create dict for easy access plugins = getMethodPlugins("classes") self.methodClasses1 = {} # Methods enabled by default self.methodClasses2 = {} # All methods self.lastMethod = "Scottish STV" for p in plugins: if p.status == 1: self.methodClasses1[p.longMethodName] = p self.methodClasses2[p.longMethodName] = p self.methodClasses = self.methodClasses1 # Methods currently viewable to user self.breakTiesRandomly = False fn = os.path.join(getHome(), "Icons", "pie.ico") self.icon = wx.Icon(fn, wx.BITMAP_TYPE_ICO) self.SetIcon(self.icon) self.lastBallotFile = "" self.electionList = [] self.menuBar = wx.MenuBar() self.MakeMenu() self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) # create a notebook self.notebook = wx.Notebook(self, -1) # create a console window self.console = wx.TextCtrl(self.notebook, -1, style=wx.TE_MULTILINE|wx.TE_READONLY|\ wx.TE_WORDWRAP|wx.FIXED|wx.TE_RICH2) self.console.SetMaxLength(0) ps = self.console.GetFont().GetPointSize() font = wx.Font(ps, wx.MODERN, wx.NORMAL, wx.NORMAL) self.console.SetFont(font) # add the console as the first page self.notebook.AddPage(self.console, "Console") self.output = Output(self.notebook) sys.stdout = self.output sys.stderr = self.output self.introText = """\ OpenSTV Copyright 2003-2010 Jeffrey O'Neill GNU General Public License See Help->License for more details. To run an election with an existing ballot file, select "New Election" from the File menu. To create a new ballot file, select "Create New Ballot File" from the File menu. To edit an existing ballot file, select "Edit Ballot File" from the File menu. For more information about the operation of OpenSTV, see the Help menu, go to www.OpenSTV.org, or send an email to [email protected]. """ self.console.AppendText(self.introText)
def __init__(self, parent, mode): wx.Frame.__init__(self, parent, -1, "Ballot File Editor") warnings.showwarning = self.catchWarnings self.MakeMenu() self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self.logfName = "" fn = os.path.join(getHome(), "Icons", "blt.ico") icon = wx.Icon(fn, wx.BITMAP_TYPE_ICO) self.SetIcon(icon) # Edit a new ballot file if mode == "new": # Create an empty ballots class instance self.b = Ballots() # Get the candidate names from the user dlg = CandidatesDialog(parent, self.b) dlg.Center() if dlg.ShowModal() != wx.ID_OK: dlg.Destroy() self.Destroy() return dlg.Destroy() # Edit an existing ballot file elif mode == "old": dlg = wx.FileDialog(self, "Edit Ballot File", style=wx.FD_OPEN|wx.FD_CHANGE_DIR) if dlg.ShowModal() != wx.ID_OK: dlg.Destroy() self.Destroy() return fName = dlg.GetPath() dlg.Destroy() # Open the file try: self.b = Ballots() self.b.loadUnknown(fName) except RuntimeError as msg: wx.MessageBox(str(msg), "Error", wx.OK|wx.ICON_ERROR) self.Destroy() return else: assert(0) # Set the window title to include the filename fn = self.b.getFileName() if fn is not None: title = "%s - Ballot File Editor" % os.path.basename(fn) else: title = "%s - Ballot File Editor" % "New File" self.SetTitle(title) # Create a notebook with an editing page and a log page nb = wx.Notebook(self, -1) self.panel = BallotsPanel(nb, self.b) nb.AddPage(self.panel, "Ballots") self.logN = 1 # counter for display purposes self.log = wx.TextCtrl(nb, -1, style=wx.TE_MULTILINE|wx.TE_READONLY|\ wx.TE_WORDWRAP|wx.FIXED) nb.AddPage(self.log, "Log") # Initialize if mode == "new": self.panel.NeedToSaveBallots = True self.Log("Created a new ballot file.") elif mode == "old": self.panel.NeedToSaveBallots = False self.Log("Loaded %d ballots from file %s." %\ (self.b.numBallots, os.path.basename(self.b.getFileName()))) else: assert(0) # Set up the sizer sizer = wx.BoxSizer() sizer.Add(nb, 1, wx.EXPAND, 0) self.SetSizer(sizer) sizer.Fit(self) sizer.SetSizeHints(self)
def __init__(self, parent, mode): wx.Frame.__init__(self, parent, -1, "Ballot File Editor") warnings.showwarning = self.catchWarnings self.MakeMenu() self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self.logfName = "" fn = os.path.join(getHome(), "Icons", "blt.ico") icon = wx.Icon(fn, wx.BITMAP_TYPE_ICO) self.SetIcon(icon) # Edit a new ballot file if mode == "new": # Create an empty ballots class instance self.b = Ballots() # Get the candidate names from the user dlg = CandidatesDialog(parent, self.b) dlg.Center() if dlg.ShowModal() != wx.ID_OK: dlg.Destroy() self.Destroy() return dlg.Destroy() # Edit an existing ballot file elif mode == "old": dlg = wx.FileDialog(self, "Edit Ballot File", style=wx.OPEN|wx.CHANGE_DIR) if dlg.ShowModal() != wx.ID_OK: dlg.Destroy() self.Destroy() return fName = dlg.GetPath() dlg.Destroy() # Open the file try: self.b = Ballots() self.b.loadUnknown(fName) except RuntimeError as msg: wx.MessageBox(str(msg), "Error", wx.OK|wx.ICON_ERROR) self.Destroy() return else: assert(0) # Set the window title to include the filename fn = self.b.getFileName() if fn is not None: title = "%s - Ballot File Editor" % os.path.basename(fn) else: title = "%s - Ballot File Editor" % "New File" self.SetTitle(title) # Create a notebook with an editing page and a log page nb = wx.Notebook(self, -1) self.panel = BallotsPanel(nb, self.b) nb.AddPage(self.panel, "Ballots") self.logN = 1 # counter for display purposes self.log = wx.TextCtrl(nb, -1, style=wx.TE_MULTILINE|wx.TE_READONLY|\ wx.TE_WORDWRAP|wx.FIXED) self.log.SetMaxLength(0) nb.AddPage(self.log, "Log") # Initialize if mode == "new": self.panel.NeedToSaveBallots = True self.Log("Created a new ballot file.") elif mode == "old": self.panel.NeedToSaveBallots = False self.Log("Loaded %d ballots from file %s." %\ (self.b.numBallots, os.path.basename(self.b.getFileName()))) else: assert(0) # Set up the sizer sizer = wx.BoxSizer() sizer.Add(nb, 1, wx.EXPAND, 0) self.SetSizer(sizer) sizer.Fit(self) sizer.SetSizeHints(self)