Skip to content

Commit

Permalink
global reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
zdimension committed Apr 13, 2018
1 parent f204f29 commit 2d36b00
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 27 deletions.
6 changes: 4 additions & 2 deletions src/algo/stmts/GFuncStmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def __init__(self, var: str, expr: AstNode, start: AstNode, end: AstNode, step:
self.color = color

def __str__(self):
return "[Func (%s) -> (%s) [%s; %s] / %s - %s]" % (self.var, self.expr, self.start, self.end, self.step, self.color)
return "[Func (%s) -> (%s) [%s; %s] / %s - %s]" % (
self.var, self.expr, self.start, self.end, self.step, self.color)

def __repr__(self):
return "GFuncStmt(%r, %r, %r, %r, %r, %r)" % (self.var, self.expr, self.start, self.end, self.step, self.color)
Expand All @@ -30,7 +31,8 @@ def get_function(self) -> LambdaNode:
return LambdaNode([self.var], self.expr)

def python(self) -> List[str]:
return ["g_func(%s)" % ", ".join(x.python() for x in (self.get_function(), self.start, self.end, self.step, self.color))]
return ["g_func(%s)" % ", ".join(
x.python() for x in (self.get_function(), self.start, self.end, self.step, self.color))]

def get_children(self) -> List[AstNode]:
return [x for c in (self.expr, self.start, self.end, self.step, self.color) for x in c.flatten()]
3 changes: 1 addition & 2 deletions src/algo/worker.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
import time
import typing
from collections import Iterable
from typing import Union

import time

from algo.stmts import *
from maths.evaluator import Evaluator
from maths.nodes import *
Expand Down
2 changes: 1 addition & 1 deletion src/forms/alg_gfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from forms.inline_code_dialog import InlineCodeDialog
from forms.ui_alg_gfunc import Ui_AlgoGFuncStmt
from maths.parser import quick_parse as parse
from maths.nodes import *
from maths.parser import quick_parse as parse
from util.code import try_parse
from util.widgets import center_widget, get_themed_box

Expand Down
38 changes: 21 additions & 17 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
settings: QSettings = None
recent_actions = None


def sleep(duration):
duration *= 1000
begin = datetime.datetime.now()
Expand Down Expand Up @@ -575,6 +576,7 @@ def breakpoint_message(message=""):
"red"))
update_output()


def python_breakpoint(message=""):
global after_output
breakpoint_message(message)
Expand Down Expand Up @@ -902,7 +904,8 @@ def handler_New():
msg.setIcon(QMessageBox.Question)
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
msg.setDefaultButton(QMessageBox.No)
msg.setText(translate("MainWindow", "Do you really want to create a new file?\nAll unsaved changes will be lost."))
msg.setText(
translate("MainWindow", "Do you really want to create a new file?\nAll unsaved changes will be lost."))
msg.adjustSize()
center_widget(msg, window)
if msg.exec_() != QMessageBox.Yes:
Expand All @@ -916,10 +919,10 @@ def handler_New():


def handler_ZoomIn():
if mode_python:
code_editor.zoom_in()
else:
set_algo_size(ui.treeWidget.font().pointSize() + 1)
if mode_python:
code_editor.zoom_in()
else:
set_algo_size(ui.treeWidget.font().pointSize() + 1)


def handler_ZoomOut():
Expand Down Expand Up @@ -962,7 +965,6 @@ def copy_action(source: QAction, target: QAction):
target.triggered.connect(source.trigger)



def change_language(language: str):
available = [x.statusTip() for x in ui.menuLanguage.actions()]
if language not in available and util.get_short_lang(language) not in available:
Expand Down Expand Up @@ -1249,8 +1251,8 @@ def add_gwindow():
dlg = alg_gwindow.AlgoGWindowStmt(window)
if dlg.run():
append_line(GWindowStmt(dlg.f_x_min, dlg.f_x_max, dlg.f_y_min, dlg.f_y_max, dlg.f_x_grad, dlg.f_y_grad))


def add_gfunc():
from forms import alg_gfunc
dlg = alg_gfunc.AlgoGFuncStmt(window)
Expand All @@ -1271,8 +1273,8 @@ def add_stop_stmt():
dlg = alg_stop.AlgoStopStmt(window)
if dlg.run():
append_line(StopStmt(dlg.expr))


def add_sleep_stmt():
from forms import alg_sleep
dlg = alg_sleep.AlgoSleepStmt(window)
Expand Down Expand Up @@ -1342,13 +1344,13 @@ def btn_edit_line():
dlg = alg_return.AlgoReturnStmt(window, stmt.value.code() if stmt.value is not None else None)
if dlg.run():
stmt.value = dlg.expr

elif isinstance(stmt, StopStmt):
from forms import alg_stop
dlg = alg_stop.AlgoStopStmt(window, stmt.message.code() if stmt.message is not None else None)
if dlg.run():
stmt.message = dlg.expr

elif isinstance(stmt, SleepStmt):
from forms import alg_sleep
dlg = alg_sleep.AlgoSleepStmt(window, stmt.duration.code())
Expand Down Expand Up @@ -1432,7 +1434,8 @@ def btn_edit_line():

elif isinstance(stmt, GFuncStmt):
from forms import alg_gfunc
dlg = alg_gfunc.AlgoGFuncStmt(window, (stmt.var, stmt.expr.code(), stmt.start.code(), stmt.end.code(), stmt.step.code(), stmt.color.code()))
dlg = alg_gfunc.AlgoGFuncStmt(window, (
stmt.var, stmt.expr.code(), stmt.start.code(), stmt.end.code(), stmt.step.code(), stmt.color.code()))
if dlg.run():
stmt.var = dlg.f_variable
stmt.expr = dlg.f_function
Expand Down Expand Up @@ -1711,7 +1714,8 @@ def str_stmt(stmt):
)

elif isinstance(stmt, GFuncStmt):
ret = translate("Algo", "[k]PLOT FUNCTION[/k] [c]{color}[/c] [i]f[/i]({var}) = [c]{expr}[/c] [k]FROM[/k] [c]{begin}[/c] [k]TO[/k] [c]{end}[/c] [k]STEP[/k] [c]{step}[/c]").format(
ret = translate("Algo",
"[k]PLOT FUNCTION[/k] [c]{color}[/c] [i]f[/i]({var}) = [c]{expr}[/c] [k]FROM[/k] [c]{begin}[/c] [k]TO[/k] [c]{end}[/c] [k]STEP[/k] [c]{step}[/c]").format(
color=code(stmt.color),
var=stmt.var,
expr=code(stmt.expr),
Expand Down Expand Up @@ -1865,7 +1869,8 @@ def algo_sel_changed():
for p in current:
parent_stack.append(parent_stack[-1].children[p])

existing_else = current[-1] + 1 < len(parent_stack[-2].children) and isinstance(parent_stack[-2].children[current[-1] + 1], ElseStmt)
existing_else = current[-1] + 1 < len(parent_stack[-2].children) and isinstance(
parent_stack[-2].children[current[-1] + 1], ElseStmt)

ui.btnAlgo_Else.setEnabled(isinstance(current_stmt, IfStmt) and not existing_else)

Expand Down Expand Up @@ -2062,7 +2067,7 @@ def version_check():
if __name__ == "__main__":
sys.excepthook = except_hook
setup_thread_excepthook()
#global app, settings
# global app, settings
app = QApplication(sys.argv)
app.setApplicationName("Turing")
app.setApplicationVersion(__version__)
Expand All @@ -2078,7 +2083,6 @@ def version_check():
font = QFont("Segoe UI", 9)
app.setFont(font)

import turing_rc
splash = QSplashScreen(QPixmap(":/icon/media/icon_128.png"), Qt.WindowStaysOnTopHint)
splash.show()
app.processEvents()
Expand Down
2 changes: 0 additions & 2 deletions src/maths/lib/trig.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-

import cmath

from maths.lib import basic
from util import translate
from util.math import mod, mods
Expand Down
2 changes: 1 addition & 1 deletion src/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ def flatten(lst: Iterable) -> List:
def get_short_lang(lang):
if "_" not in lang:
return lang
return lang[0:lang.index("_")]
return lang[0:lang.index("_")]
5 changes: 4 additions & 1 deletion src/util/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,17 @@ def check_type(obj: Any, typ: str) -> bool:

raise ValueError("unknown type %s" % typ)


def mod(x):
import cmath, math
return cmath if type(x) == complex else math


def modn(x):
import cmath, math
return cmath if type(x) == complex or x < 0 else math


def mods(x, b):
import cmath, math
return cmath if type(x) == complex or abs(x) > b else math
return cmath if type(x) == complex or abs(x) > b else math
2 changes: 1 addition & 1 deletion src/util/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ def set_font_size(wgt, size, index=None):
if index is None:
wgt.setFont(result)
else:
wgt.setFont(index, result)
wgt.setFont(index, result)

0 comments on commit 2d36b00

Please sign in to comment.