def OnSubmit(buff, evt): """Callback for buffer context menu event. Opens the submission dialog @param buff: EditraStc @param evt: MenuEvent """ if evt.GetId() == ID_TDWTF: app = wx.GetApp() dlg = SubmitDialog(buff, title=_("Submit your WTF"), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) dlg.SetSenderName(wx.GetUserName()) dlg.SetSnippetField(buff.GetSelectedText()) dlg.CenterOnParent() if dlg.ShowModal() == wx.ID_OK: # send it info = dlg.GetSubmissionInfo() dlg.Destroy() # Need to encode as UTF-8 try: info = [data.encode('utf-8') for data in info] except UnicodeEncodeError, msg: util.Log("[dailywtf][err] %s" % msg) return host = "thedailywtf.com" bodytxt = SUBMIT_TPL % tuple(info) message = ebmlib.SOAP12Message(host, "/SubmitWTF.asmx", bodytxt, "http://thedailywtf.com/Submit") message.Send() # TODO check return code to make sure it was submitted else: dlg.Destroy() # Canceled
def __init__(self, *args, **kargs): """Initialize that main app and its attributes @postcondition: application is created and ready to be run in mainloop """ wx.App.__init__(self, *args, **kargs) events.AppEventHandlerMixin.__init__(self) self.SetAppName(ed_glob.PROG_NAME) # Attributes self.profile_updated = InitConfig() self._log = dev_tool.DEBUGP self._lock = False self._windows = dict() if ed_glob.SINGLE: # Setup the instance checker instance_name = u"%s-%s" % (self.GetAppName(), wx.GetUserId()) self._instance = wx.SingleInstanceChecker(instance_name) if self._instance.IsAnotherRunning(): try: opts, args = getopt.getopt(sys.argv[1:], "dhv", ['debug', 'help', 'version']) except getopt.GetoptError, msg: self._log("[app][err] %s" % str(msg)) args = list() if not len(args): args.append(APP_CMD_OPEN_WINDOW) rval = ed_ipc.SendCommands(args, profiler.Profile_Get('SESSION_KEY')) # If sending the command failed then let the editor startup # a new instance if not rval: self._isfirst = True else: self._log("[app][info] Starting Ipc server...") # Set the session key and save it to the users profile so # that other instances can access the server key = unicode(base64.b64encode(os.urandom(8), 'zZ')) key = wx.GetUserName() + key profiler.Profile_Set('SESSION_KEY', key) profiler.Profile_Set('ISBINARY', hasattr(sys, 'frozen')) path = profiler.Profile_Get('MYPROFILE') profiler.Profile().Write(path) try: self._server = ed_ipc.EdIpcServer( self, profiler.Profile_Get('SESSION_KEY')) self._server.start() except Exception, msg: self._log("[app][err] Failed to start ipc server") self._log("[app][err] %s" % str(msg)) self._server = None self._isfirst = True
def OnInit(self): """Initialize the Editor @note: this gets called before __init__ @postcondition: custom artprovider and plugins are loaded """ self.SetAppName(ed_glob.PROG_NAME) self._log = dev_tool.DEBUGP self._log("[app][info] Editra is Initializing") self._isfirst = False # Is the first instance self._instance = None if ed_glob.SINGLE: # Setup the instance checker instance_name = u"%s-%s" % (self.GetAppName(), wx.GetUserId()) self._instance = wx.SingleInstanceChecker(instance_name) if self._instance.IsAnotherRunning(): try: opts, args = getopt.getopt(sys.argv[1:], "dhv", ['debug', 'help', 'version']) except getopt.GetoptError, msg: self._log("[app][err] %s" % str(msg)) args = list() if not len(args): args.append(APP_CMD_OPEN_WINDOW) rval = ed_ipc.SendCommands(args, profiler.Profile_Get('SESSION_KEY')) # If sending the command failed then let the editor startup # a new instance if not rval: self._isfirst = True else: self._log("[app][info] Starting Ipc server...") # Set the session key and save it to the users profile so # that other instances can access the server key = unicode(base64.b64encode(os.urandom(8), 'zZ')) key = wx.GetUserName() + key profiler.Profile_Set('SESSION_KEY', key) profiler.Profile_Set('ISBINARY', hasattr(sys, 'frozen')) path = profiler.Profile_Get('MYPROFILE') profiler.Profile().Write(path) try: self._server = ed_ipc.EdIpcServer( self, profiler.Profile_Get('SESSION_KEY')) self._server.start() except Exception, msg: self._log("[app][err] Failed to start ipc server") self._log("[app][err] %s" % str(msg)) self._server = None self._isfirst = True
def test_utilsSomeOtherStuff(self): wx.GetBatteryState() wx.GetPowerType() wx.GetKeyState(wx.WXK_F1) wx.GetMousePosition() wx.GetMouseState() wx.EnableTopLevelWindows(True) wx.FindWindowAtPoint((1, 1)) wx.NewId() wx.RegisterId(12345) wx.GetUserName() wx.GetUserId() wx.GetOsDescription()
def LoadINI(): """ initialization """ iniFile = os.environ['HOME'] + '/c2pdf.ini' param = {'user': wx.GetUserName(), 'lab': '1'} if fileExist(iniFile, 'N'): # for line in open(iniFile,'r'): # s = line.split('=') # param[s[0].rstrip(' ')] = s[1].strip(' ').rstrip('\n') f = open(iniFile, 'r') for x, y in pickle.load(f).items(): param[x] = y return param
def drawFooter(c, page, srcFile, no): #2013.10.10 srcFile = srcFile.decode('utf8') #? line = "Page %d-%d %s : %s %s" % (no, page, wx.GetHostName(), wx.GetUserName(), srcFile) t = time.localtime() ctime = '%04d-%02d-%02d %02d:%02d:%02d' % (t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec) c.setFont("MyFont", 8) c.line(5, 25, 590, 25) c.drawString(10, 10, line) c.drawRightString(585, 10, ctime) c.line(5, 810, 590, 810) line = u"2014级程序设计原理与C语言" c.drawString(10, 820, line) line = "Principles of Programming for grade 2014" c.drawRightString(585, 820, line)
def 程序_取系统用户名(): "返回示例: Administrator" return wx.GetUserName()
def generateSignature(self): #username=os.environ['USERNAME'] username=wx.GetUserName() sign_time = time.asctime(time.localtime()) signature = "Adopted QMED="+str(config.analysis.qmed_analysis.adopted_qmed_value)+" "+str(username)+" "+str(sign_time) return signature
def test(srcFiles, values={}, passwd='C2014', outfile=None): srcFiles = sorted(srcFiles, key=basename) registerFont(UnicodeCIDFont('STSong-Light')) from reportlab.pdfbase import ttfonts # font = ttfonts.TTFont('MyFont', r'C:\Windows\Fonts\simhei.ttf') font = ttfonts.TTFont('MyFont', r'msyhbd.ttf') # font = ttfonts.TTFont('MyFont', 'msyhbd.ttf') registerFont(font) user = values.get('user', '') if user: user = user.encode('utf8') name = values.get('name', '').encode('utf8') password = values.get('passwd', '') if password.strip(): passwd = password.encode('utf8') #? if values.get('lab', '') != '': labv = int(values.get('lab', '0')) else: labv = 0 if 0 < labv < 20: lab = ('Lab%d' % labv).encode('utf8') else: lab = u'' # if user.startswith('10132130') and 0<labv<20: # 2013.10.10 if user.startswith('101') and len(user) == 11 and 0 < labv < 20: # 2013.10.10 # outfile = (os.getcwd()+'/'+user.encode('utf8')+'_'+'%02d.c'%labv).encode('utf8') #? outfile = (os.getcwdu() + u'/' + user.encode('utf8') + u'_' + u'%02d.PDF' % labv) if outfile == None: # if srcFiles[0].rfind('.')!=-1: # pdffile = srcFiles[0][:srcFiles[0].rfind('.')] # else: pdffile = srcFiles[0] # 2013.10.10 bname = basename(srcFiles[0]) if bname.rfind('.') != -1: pdffile = bname[:bname.rfind('.')] else: pdffile = bname pdffile = os.getcwd() + '/' + pdffile # 2013.10.10 pdffile = unicode(pdffile.decode('utf8')) #? else: if outfile.rfind('.') != -1: pdffile = outfile[:outfile.rfind('.')] else: pdffile = outfile # 2013.10.10 # pdffile --> pdffile.encode('gbk') if passwd == "C2014": c = Canvas(pdffile.encode('utf8') + '.pdf') else: c = Canvas(pdffile.encode('utf8')+'.pdf',\ encrypt=pdfencrypt.StandardEncryption\ (passwd,ownerPassword='******',canPrint=0,canCopy=0)) # c = Canvas(pdffile+'.pdf') c.showOutline() c.setAuthor(u"LU") c.setTitle(u"2014级程序设计原理与C语言作业") c.setSubject(u"作业") c.setCreator(u"C2PDF") c.setKeywords(['C语言', '程序设计', '作业', '2014级']) blank = "", "" line1 = u"课程名", u"2014级程序设计原理与C语言" + ' ' + u"Principles of Programming & C" chost = u"机器名", wx.GetHostName() cuser = u"用户名", wx.GetUserName() ID = u"学号", user USER = u"姓名", name grade = u"成绩", u" " labName = u"作业名", lab lines = (line1, chost, cuser, ID, USER, blank, labName, grade) c.setFont("MyFont", 12) x, y, delta = 50, 800, 20 for line in lines: c.drawString(x, y, line[0]) from reportlab.lib.colors import pink, black, red, blue, green if line[0] == u"成绩": # c.saveState() c.setFillColor(red) c.setFont("MyFont", 20) y -= 15 c.drawString(x + 70, y, line[1]) c.setFont("MyFont", 12) c.setFillColor(black) # c.restoreState() else: c.drawString(x + 70, y, line[1]) y -= delta filelist = srcFiles s0 = "Table of Contents" c.bookmarkPage(s0, 'FitH') c.addOutlineEntry(s0, s0) for no, f in enumerate(filelist): # c.addOutlineEntry(basename(f),f) # 2013.10.10 c.addOutlineEntry(basename(f).decode('utf8'), f) #? y -= delta # c.drawString(x, y, "%2d: %s"%(no+1,f)) # 2013.10.10 c.drawString(x, y, "%2d: %s" % (no + 1, f.decode('utf8'))) #? c.linkRect("", f, (x, y + delta - 5, x + 400, y - 5), Border='[0 0 0]') t = time.localtime() ctime = '%04d-%02d-%02d %02d:%02d:%02d' % (t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec) c.drawString(x + 70, y - 2 * delta, ctime) c.showPage() for no, f in enumerate(filelist): outOneFile(f, c, no + 1) """ from reportlab.lib.styles import getSampleStyleSheet from reportlab.platypus import Paragraph, Frame styles = getSampleStyleSheet() toc = TableOfContents() PS = ParagraphStyle toc.levelStyles = [ PS(fontName='Times-Bold', fontSize=14, name='TOCHeading1',\ leftIndent=20, firstLineIndent=-20, spaceBefore=5, leading=16), PS(fontSize=12, name='TOCHeading2',\ leftIndent=40, firstLineIndent=-20, spaceBefore=0, leading=12) ] styleN = styles['Normal'] styleH = styles['Heading1'] styleH2 = styles['Heading2'] story = [ ] story.append(Paragraph("This is a Heading<font size=54> abc[α] <greek>e</greek> <greek>p</greek> </font>",styleH)) story.append(Spacer(inch,inch)) story.append(Paragraph("This is a paragraph in <i>Normal</i> style.", styleN)) story.append(Paragraph("This is a Heading2 style.", styleH2)) toc.addEntry(0, 'txt', 1) toc.addEntry(1, 'txt1', 2) story.append(toc) f = Frame(inch, inch, 6*inch, 9*inch, showBoundary=1) f.addFromList(story,c) """ c.save() # print 'saved PDF file for '+pdffile return pdffile + u'.pdf'