- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在启动一个简单的小 GUI,用于给我学生的 Python 源代码评分。有没有一种简单的方法可以在 GUI 中自动格式化 python 代码的显示?例如,从某个编辑器中提取颜色格式?
我已经开始使用 Python tkk(只是为了一些额外的 python 练习,我教它但不经常使用它)但是如果在这方面更容易,我不反对切换语言。
输出将是一个包含所有成绩等的网页,但会使用 Google Prettify 显示 python 代码(除非有人有更好的建议),所以我不需要保留配色方案,只需要显示它即可评分更容易。
非常感谢!
最佳答案
只记得 wxPython 与 SciTe 捆绑在一起:
#!/usr/bin/env python
import wx
from wx import stc
import keyword
class PyDialog(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None, -1, 'Python Code')
sizer = wx.BoxSizer(wx.VERTICAL)
self.stc = stc.StyledTextCtrl(self, -1)
self.stc.SetSizeHints(400, 400)
self.stc.SetLexer(stc.STC_LEX_PYTHON)
self.stc.SetKeyWords(0, " ".join(keyword.kwlist))
self.stc.SetMarginType(1, stc.STC_MARGIN_NUMBER)
# Python styles
self.stc.StyleSetSpec(wx.stc.STC_P_DEFAULT, 'fore:#000000')
# Comments
self.stc.StyleSetSpec(wx.stc.STC_P_COMMENTLINE, 'fore:#008000,back:#F0FFF0')
self.stc.StyleSetSpec(wx.stc.STC_P_COMMENTBLOCK, 'fore:#008000,back:#F0FFF0')
# Numbers
self.stc.StyleSetSpec(wx.stc.STC_P_NUMBER, 'fore:#008080')
# Strings and characters
self.stc.StyleSetSpec(wx.stc.STC_P_STRING, 'fore:#800080')
self.stc.StyleSetSpec(wx.stc.STC_P_CHARACTER, 'fore:#800080')
# Keywords
self.stc.StyleSetSpec(wx.stc.STC_P_WORD, 'fore:#000080,bold')
# Triple quotes
self.stc.StyleSetSpec(wx.stc.STC_P_TRIPLE, 'fore:#800080,back:#FFFFEA')
self.stc.StyleSetSpec(wx.stc.STC_P_TRIPLEDOUBLE, 'fore:#800080,back:#FFFFEA')
# Class names
self.stc.StyleSetSpec(wx.stc.STC_P_CLASSNAME, 'fore:#0000FF,bold')
# Function names
self.stc.StyleSetSpec(wx.stc.STC_P_DEFNAME, 'fore:#008080,bold')
# Operators
self.stc.StyleSetSpec(wx.stc.STC_P_OPERATOR, 'fore:#800000,bold')
# Identifiers. I leave this as not bold because everything seems
# to be an identifier if it doesn't match the above criterae
self.stc.StyleSetSpec(wx.stc.STC_P_IDENTIFIER, 'fore:#000000')
# Caret color
self.stc.SetCaretForeground("BLUE")
# Selection background
self.stc.SetSelBackground(1, '#66CCFF')
sizer.Add(self.stc, 0, wx.EXPAND)
button = wx.Button(self, -1, 'Open...')
self.Bind(wx.EVT_BUTTON, self.OnOpen, button)
sizer.Add(button)
self.SetSizer(sizer)
sizer.Fit(self)
def OnOpen(self, evt):
dlg = wx.FileDialog(
self,
message = 'Choose File',
wildcard = 'Python source (*.py)|*.py',
style = wx.OPEN)
if dlg.ShowModal() != wx.ID_OK:
return
with open(dlg.GetPath()) as fo:
self.stc.SetText(fo.read())
dlg.Destroy()
if __name__ == '__main__':
app = wx.PySimpleApp()
dlg = PyDialog()
with open(__file__) as fo:
dlg.stc.SetText(fo.read())
dlg.ShowModal()
关于python - 在 Python(或其他)GUI 中显示漂亮的 Python 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13925620/
在通过REST Request Body方法发出搜索请求时,例如 GET /bank/_search { "query": { "match_all": {} }, "sort": [
有没有办法检测用户是否停止滑动?也许 bij 鼠标输入检查之类的。我尝试在 onSliderChange 事件中使用鼠标 isButton0Release 和 hasFocus 来检查用户是否停止滑动
(来源:google.com) 最近,我发现我的应用程序中显示的汉字相当难看。 我想我应该让它们“消除锯齿”。但是,我如何在 Java 中做到这一点? 仅供引用,我没有明确选择要在 GUI 应用程序中
我正在创建一个网站,根据某些条件(即是否登录、是否填写表格等),不同页面的外观可能会有很大差异。这使得需要在不同的时间输出不同的html block 。 但是,这样做会使我的 php 代码看起来很糟糕
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
如果我有一个类包含例如几个将用向量填充的槽,那么问题通常会出现。如果我想让这个类的对象或多或少透明,我会为它实现 print-object。在这里我遇到了问题: 如果我在一行中打印所有内容,REPL
我有一个允许上传到我网站的文件扩展名列表。 我用 jQuery Validation plugin 检查它们. 如果他们选择了不受支持的扩展程序,我会显示一条错误消息。 看起来像 var msg =
在一个本身嵌套在一个或多个父数组/结构/union 中的数组/结构/union 中读取多个数字/字符串的最佳方法是什么? 没有临时变量的第一个例子: printf("%d %d\n", a[9][3]
我是 AngularJS 的新手。我目前在为我的观点编写漂亮的 url 时遇到问题。我已经设置了 $locationProvider.html5Mode(true);删除 #从地址栏中显示的网址。但是
我有一个带有 ElasticSearch 的自动完成 jquery 功能。输入第一个字母时出现以下错误。 跨源请求被阻止:同源策略不允许读取 http://localhost:9200/test12/
我是一名优秀的程序员,十分优秀!