def convert(jsonfile, outfile): f = open(jsonfile, 'r') jsonstr = f.read() graph = parser.parse(jsonstr) layout.layout(graph["node"]) svg = render.render(graph) of = open(outfile, 'w') of.write(svg)
def __init__(self, config_file=None, layout_location=None, fonts_dir=None): ## @var log # Handle to system logger self.log = logging.getLogger('system') ## @var pm # Handle to pyplum instance self.pm = pyplum.pyplum() self.pm.register_parameter("log_level", self.extra["module_name"], value='debug', store=True) self.pm.register_parameter("config_file", self.extra["module_name"], value=config_file) self.pm.register_parameter("layout_location", self.extra["module_name"], value=layout_location) self.pm.register_parameter("fonts_dir", self.extra["module_name"], value=fonts_dir) ## @var layout # Handle to layout instance self.layout = layout.layout() ## @var events # Handle to events instance self.log.debug("Initialising events", extra=self.extra) self.events = events.events()
def parseFromSource(self, parser, text): filename = "test" rawTokens = lex(filename, text) layoutTokens = layout(rawTokens, skipAnalysis=True) reader = Reader(filename, layoutTokens) result = Phrase(parser)(reader) if not result: raise ParseException(result.location, result.message) return result.value
def analyzeFromSource(self, source): filename = "(test)" rawTokens = lex(filename, source) layoutTokens = layout(rawTokens) ast = parse(filename, layoutTokens) info = CompileInfo(ast) analyzeDeclarations(info) analyzeInheritance(info) analyzeTypes(info) return info
def paintEvent(self, ev): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) margin = self.width() / 10.0 availWidth = self.width() - margin * 2 availHeight = self.height() - margin * 2 # layout tree = self.syntaxTree.clone() layout(tree) # calc extent xs, ys = zip(*((t.x, t.y) for t in tree)) minX, maxX = min(xs), max(xs) minY, maxY = min(ys), max(ys) dx, dy = float(maxX - minX), float(maxY - minY) # scale for node in tree: pen = painter.pen() pen.setWidthF(0.2) painter.setPen(pen) node.x = margin + availWidth * ( (node.x - minX) / dx if dx else 0.5) node.y = margin + availHeight * ( (node.y - minY) / dy if dy else 0.5) # draw lines for node in tree: for c in node.children: painter.drawLine(node.x, node.y, c.x, c.y) # draw nonterminals painter.setFont(QFont('Courier New', 8)) pen = painter.pen() pen.setBrush(QBrush(QColor(120, 120, 120))) painter.setPen(pen) for node in filter(lambda t: isinstance(t.data, Nonterminal), tree): painter.drawText(node.x - margin, node.y - margin, 2 * margin, 2 * margin, Qt.AlignCenter, str(node.data)) # draw terminals painter.setFont(QFont('Courier New', 14, QFont.Bold)) pen = painter.pen() pen.setBrush(QBrush(QColor(0, 0, 0))) painter.setPen(pen) for node in filter(lambda t: isinstance(t.data, Terminal), tree): painter.drawText(node.x - margin, node.y - margin, 2 * margin, 2 * margin, Qt.AlignCenter, str(node.data))
def paintEvent(self, ev): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) margin = self.width() / 10.0 availWidth = self.width() - margin * 2 availHeight = self.height() - margin * 2 # layout tree = self.syntaxTree.clone() layout(tree) # calc extent xs, ys = zip(*((t.x, t.y) for t in tree)) minX, maxX = min(xs), max(xs) minY, maxY = min(ys), max(ys) dx, dy = float(maxX - minX), float(maxY - minY) # scale for node in tree: pen = painter.pen() pen.setWidthF(0.2) painter.setPen(pen) node.x = margin + availWidth * ((node.x - minX) / dx if dx else 0.5) node.y = margin + availHeight * ((node.y - minY) / dy if dy else 0.5) # draw lines for node in tree: for c in node.children: painter.drawLine(node.x, node.y, c.x, c.y) # draw nonterminals painter.setFont(QFont('Courier New', 8)) pen = painter.pen() pen.setBrush(QBrush(QColor(120,120,120))) painter.setPen(pen) for node in filter(lambda t: isinstance(t.data, Nonterminal), tree): painter.drawText(node.x - margin, node.y - margin, 2 * margin, 2 * margin, Qt.AlignCenter, str(node.data)) # draw terminals painter.setFont(QFont('Courier New', 14, QFont.Bold)) pen = painter.pen() pen.setBrush(QBrush(QColor(0,0,0))) painter.setPen(pen) for node in filter(lambda t: isinstance(t.data, Terminal), tree): painter.drawText(node.x - margin, node.y - margin, 2 * margin, 2 * margin, Qt.AlignCenter, str(node.data))
def setup_app_and_layout(): from app import app from layout import layout from data import get_test_list from data import get_org_list app.layout = layout( get_test_list(), get_org_list("ccg_id"), get_org_list("lab_id"), get_org_list("practice_id"), ) return app
def analyzeFromSource(self, source): filename = "(test)" rawTokens = lex(filename, source) layoutTokens = layout(rawTokens) ast = parse(filename, layoutTokens) package = Package(TARGET_PACKAGE_ID) packageLoader = FakePackageLoader([]) info = CompileInfo(ast, package, packageLoader, isUsingStd=False) analyzeDeclarations(info) analyzeInheritance(info) analyzeTypes(info) convertClosures(info) return info
def test_layout_simple_merge_with_crossover(): develop = Node("develop") autovalue = Node("feature/auto.value", develop) deadlock = Node("feature/deadlock.transfercontroller", develop) workshop = Node("workshop", autovalue, deadlock) freebuilder = Node("feature/freebuilder", autovalue) branches = [ freebuilder, workshop, deadlock, autovalue, develop ] assert layout(branches) == [ Row(at = 1, down = [1]), Row(at = 0, up = [1], down = [0,1]), Row(at = 0, up = [0], down = [0], through = [1]), Row(at = 1, up = [0,1], down = [0]), Row(at = 0, up = [0]), ]
def write_layout(trust_dir: str, output_filename: str) -> None: developer_step, developer_pubkeys = get_developer_step(trust_dir) machine_step, machine_pubkeys = get_machine_step(trust_dir, developer_step) metablock = layout( trust_dir, 'minimal-root-layout', steps=[developer_step, machine_step], keys={ **developer_pubkeys, **machine_pubkeys }, expires_years=1, ) metablock.dump(output_filename) print(f'Wrote minimal root layout to: {output_filename}') print(f'jq -C "." {output_filename} | less -R')
def test_layout_multi_branch_merge(): gh_pages = Node("gh-pages") master = Node("master") footnotes = Node("footnotes", master, Node("origin/footnotes")) issue4 = Node("issue4.idiomatic.java7", master) test_logs = Node("cleaner.test.logs", master) issue29 = Node("issue29-wildcards-in-optional-types", master) cleanup = Node("cleanup", master) issue2 = Node("issue2.nulls", master) issue27 = Node("issue27.dogfood", cleanup, issue2) develop = Node("develop", issue4, test_logs, issue29, issue27) refactor = Node("code.generator.refactor", develop) issue24 = Node("issue24.nested.classes.last", refactor) excerpt = Node("excerpt", issue24) qualified_name = Node("qualified.name", excerpt) no_warnings = Node("assert.no.warnings", qualified_name) issue1 = Node("issue1.generics", no_warnings) branches = [ issue1, no_warnings, qualified_name, excerpt, issue24, refactor, develop, issue27, issue2, cleanup, issue29, test_logs, issue4, footnotes, master, gh_pages ] assert layout(branches) == [ Row(at = 0, down = [0]), Row(at = 0, up = [0], down = [0]), Row(at = 0, up = [0], down = [0]), Row(at = 0, up = [0], down = [0]), Row(at = 0, up = [0], down = [0]), Row(at = 0, up = [0], down = [0]), Row(at = 0, up = [0], down = [0,1,2,3]), Row(at = 0, up = [0], down = [0,4], through = [1,2,3]), Row(at = 0, up = [0], down = [0], through = [1,2,3,4]), Row(at = 4, up = [0,4], down = [0], through = [1,2,3]), Row(at = 3, up = [0,3], down = [0], through = [1,2]), Row(at = 2, up = [0,2], down = [0], through = [1]), Row(at = 1, up = [0,1], down = [0]), Row(at = 1, up = [0], down = [0]), Row(at = 0, up = [0]), Row(at = 0), ]
## Components of the Application from layout import layout from callbacks import callbacks ## Import data source from database import database from data_source import data_source from update_views import update_views ## Beginning Argument # The application ## Connect to the database data_source["db_connection"] = database() update_views(data_source) ## Create a dash application app = dash.Dash(__name__) ## Callback of the Application callbacks(app, data_source) ## Layout of the Application layout(app, data_source) # Run a program if __name__ == '__main__': app.run_server(debug = True, use_reloader = True)
def create_bitmap(path, max_width, max_height, edges): app = wx.App(None) nodes = layout.layout(edges) bitmap = render.render(max_width, max_height, edges, nodes) bitmap.SaveFile(path, wx.BITMAP_TYPE_PNG)
# Import helper functions from analytics import totGoalsLine from get_data import table from analytics import playerValue external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] app = dash.Dash( __name__, external_stylesheets=external_stylesheets, suppress_callback_exceptions=True, ) app.title = "Football Stats" app.layout = layout() @app.callback(Output('stats-data', 'children'), [Input('my-input', 'value'), Input('button1', 'n_clicks')]) def update_output_div(input_value, n_clicks): """Create statTable df and store as hidden div""" changed_id = [p['prop_id'] for p in dash.callback_context.triggered][0] if 'button1' in changed_id: df = table(input_value) return df.to_json() # if n_clicks > 0: # df = table(input_value)
from layout import layout from variavel import * layout, window = layout() var, front, back = variavel() # -----FUNÇÕES AUXILIARES def formatar_numero() -> float: """ Essa função retorna o valor formatado da operação """ numero_formatado = float(''.join(var['sinal']) + ''.join(front) + '.' + ''.join(back)) if var['apagar']: numero_formatado = numero_formatado // 10 return numero_formatado def atualizar_display(display_valor: str): """ Essa função é responsável por atualizar o display da calculadora """ window['_DISPLAY_'].update(value=display_valor) # -----EVENTOS def numberos(evento: str): """ Essa função serve para decidir se irá jogar o número na variável 'front' ou se irá jogar na 'back' """
def serve_layout(): session_cookie = flask.request.cookies.get("custom-auth-session") # landing login page if session_cookie not in user_names.keys(): topnav = html.Div( html.H1(""), className="login-title" ) return new_login(topnav) # show the app else: greeting_and_logout_button = dbc.Row( [ dbc.Col( html.Span( user_names[session_cookie], id="username-greeting", ) ), dbc.Col( dcc.LogoutButton( logout_url="/logout", className="btn btn-outline-dark" ), width="auto", ) ], no_gutters=True, className="ml-auto flex-nowrap mt-3 mt-md-0", align="center", ) topnav = dbc.Navbar([ dbc.NavbarBrand( NAVBAR_TITLE, className="ml-2 title-style", ), dbc.NavbarBrand( NAVBAR_SUBTITLE, className="ml-2 subtitle_style" ), greeting_and_logout_button, ], color="light", light=True, id="navbar", sticky=True, ) user_df = load_dataframe(session_cookie) transaction_category_array = list(user_df.Category.unique()) budget_df = load_budget_dataframe(session_cookie) my_table = table_from_dataframe(user_df) json_user_df = user_df.to_json(date_format='iso', orient='split') json_budget_df = budget_df.to_json(date_format='iso', orient='split') return html.Div([ html.Div( topnav, id="top-nav", ), html.Div( layout(user_df, transaction_category_array, {}, my_table), id="app-content", ), html.Div( json_user_df, id="hidden-dataframe", className="hiddenDiv", ), html.Div( transaction_category_array, id="hidden-transaction-category-array", className="hiddenDiv", ), html.Div( json_budget_df, id="hidden-budget-data", className="hiddenDiv", ), ])
#!/usr/bin/env python import os import time from ua import ua from layout import layout from system import system system = system() ua = ua() configuration = ua.getConfig(system.getMacAddress()) layout = layout(configuration) while True: records = [] import pprint for queue in configuration['queues']: records.append(ua.getQueue(queue)) layout.render(records) time.sleep(configuration['refresh_interval'])
def compute(self): edges = TESTS[self.index] nodes = layout.layout(edges, self.weights) self.set_model((edges, nodes))
def parseFromSource(self, source): filename = "(test)" rawTokens = lex(filename, source) layoutTokens = layout(rawTokens) ast = parse(filename, layoutTokens) return ast
def __init__(self, simulate=False, width=240, height=320): ## @var simulate # Stores simulate parameter from constructor call self.simulate = simulate ## @var l # Handle to system logger self.l = logging.getLogger('system') pygame.init() # pygame.display.init() if not self.simulate: pygame.event.set_grab(True) pygame.mouse.set_visible(0) self.l.debug( "[OCC] EV_UPDATE_VALUES to be generated every {} ms".format( REFRESH_TIME)) pygame.time.set_timer(EV_UPDATE_VALUES, REFRESH_TIME) self.l.debug("[OCC] EV_SAVE_CONFIG to be generated every {} s".format( CONFIG_SAVE_TIME / 1000)) pygame.time.set_timer(EV_SAVE_CONFIG, CONFIG_SAVE_TIME) ## @var width # Window/screen width self.width = width ## @var height # Window/screen height self.height = height self.l.debug("[OCC] Screen size is {} x {}".format( self.width, self.height)) ## @var screen # Handle to pygame screen self.screen = pygame.display.set_mode((self.width, self.height)) self.l.debug("[OCC] Calling sensors") ## @var sensors # Handle to sensors instance self.sensors = sensors(self) self.l.debug("[OCC] Calling ride_parameters") ## @var rp # Handle to ride_parameters instance self.rp = ride_parameters(self, simulate) ## @var layout_path # Path to layout file self.layout_path = '' self.l.debug("[OCC] Initialising config") ## @var config # Handle to config instance self.config = config(self, "config/config.yaml", "config/config_base.yaml") self.l.debug("[OCC] Reading config") self.config.read_config() ## @var ble_scanner # Handle to ble_scanner instance self.ble_scanner = ble_scanner(self) ## @var layout # Handle to layout instance self.layout = layout(self, self.layout_path) self.l.debug("[OCC] Starting RP sensors") self.rp.start_sensors() self.l.debug("[OCC] Setting up rendering") ## @var rendering # Handle to rendering instance self.rendering = rendering(self.layout) self.l.debug("[OCC] Starting rendering thread") self.rendering.start() ## @var released_t # Time stamp of pygame.MOUSEBUTTONUP event (end of finger contact with touchscreen) self.released_t = 0 ## @var rel_movement # Vector since MOUSEBUTTONDOWN event. Used to derermine swipe motion. self.rel_movement = (0, 0) ## @var pressed_t # Time stamp of pygame.MOUSEBUTTONDOWN event (start of finger contact with touchscreen) self.pressed_t = 0 ## @var pressed_pos # Position of pygame.MOUSEBUTTONDOWN event (start of finger contact with touchscreen) self.pressed_pos = (0, 0) ## @var released_pos # Position of pygame.MOUSEBUTTONUP event (end of finger contact with touchscreen) self.released_pos = 0 ## @var add_rel_motion # Used to control if finger/mouse vectors should be tracked to determine total relative motion self.add_rel_motion = False ## @var running # Variable controlling the main occ event loop. pygame.QUIT event triggers setting running to False self.running = True ## @var refresh # Variable controlling if the screen need to be refreshed self.refresh = False
import shorePowerProtocol as protocol from setConfigLayout import * from setStationId import * import time #配置文件读取 cf = configparser.ConfigParser() cf.read('conf.ini') if __name__ == "__main__": sf = setConfigLayout(cf) stationId = db.QueryStationId(cf) #查询所有站号 setStationIdLayout(cf, stationId) #设置模拟的站号 stake_port = db.QueryStakePort(cf) #查询桩号端口号 STATION = int(cf.get("STATION", "ID")) tk = layout.layout(stake_port, STATION, cf, db) #布局初始化 tcpClient = tcl.tcp_init(cf, tk.getScrolledText(), tk.getTop()) #tcp连接初始化 pl = protocol.shorePowerProtocol(tcpClient, lambda: tcl.tcpReConnect(cf), STATION, cf, tk) #协议初始化 tk.sendButton(pl.send_signals, pl.heatbeatrequest, pl.heatbeatrespone) #发送按键绑定 tk.sendCalcExceptionButton(pl.dealCalcException) tk.connect(pl.link_button) #连接线缆按钮绑定 tk.disconnect(pl.free_button) #断开线缆按钮绑定 tk.sendAllState(lambda: pl.send_all_status(stake_port)) #发送全状态按钮绑定 tk.distWarnButton(pl.warn_end, pl.warn_start) #配电告警按键绑定 tk.closeWindows(tcpClient) tk.mainloop()
def checkLayout(self, expectedTexts, text): rawTokens = lex("(test)", text) layoutTokens = layout(rawTokens) layoutTexts = [token.text for token in layoutTokens] self.assertEquals(expectedTexts, layoutTexts)
from layout import auto, axis, axisMain, axisCross, wrap, layout from build_tool import build_style, build_body, build_template outer = layout("outer") header = layout("header") content = layout("content") outer["width"] = "100%" outer["height"] = "100%" outer["axis"] = axis.column # basis is height, because of outer axis is column header["basis"] = "8%" header["width"] = "100%" header["axis"] = axis.column header["overflow"] = "visible" content["basis"] = "92%" content["width"] = "100%" content["overflow"] = auto.auto content["axis"] = axis.column content["axisMain"] = axisMain.center content["axisCross"] = axisCross.center # outer: width 500px # div1: basis 100px shrink 1 # div2: basis 200px shrink 2 # div3: basis 300px shrink 3 # this is shrink calc method # weight = 100px * 1 + 200px * 2 + 300px * 3 = 1400px # offset = sum div - parent = 100px + 200px + 300px - 500px = 100px # div1 real size: