def setUp(self): self.tmpdir = tempfile.TemporaryDirectory(prefix="fract4d_") self.userConfig = fractconfig.T("") self.userConfig.set("general", "cache_dir", os.path.join(self.tmpdir.name, "gnofract4d-cache")) self.userConfig["formula_path"].clear() self.userConfig["map_path"].clear() self.g_comp = fc.Compiler(self.userConfig) self.g_comp.add_func_path("formulas")
def __init__(self, config): super().__init__() self.userConfig = config self.userPrefs = preferences.Preferences(config) self.compiler = fc.Compiler(config) self.compiler.add_func_path('formulas') this_path = os.path.dirname(sys.modules[__name__].__file__) resource = Gio.resource_load( os.path.join(this_path, "../../gnofract4d.gresource")) Gio.Resource._register(resource) self.menu_builder = Gtk.Builder.new_from_resource( "/io/github/fract4d/gtk/menus.ui")
def setUp(self): self.tmpdir = tempfile.TemporaryDirectory(prefix="fract4d_") import sys if sys.platform[:6] == "darwin": self.userConfig = fractconfig.DarwinConfig("") else: self.userConfig = fractconfig.T("") self.userConfig.set("general", "cache_dir", os.path.join(self.tmpdir.name, "gnofract4d-cache")) self.userConfig["formula_path"] = {"formulas": None} self.g_comp = fc.Compiler(self.userConfig)
def testPrefs(self): compiler = fc.Compiler(Test.userConfig) prefs = fractconfig.T("testprefs") prefs.set("compiler", "name", "x") prefs.set("compiler", "options", "foo") prefs.set_list("formula_path", ["fish"]) prefs.set_list("map_path", ["wibble"]) compiler.update_from_prefs(prefs) self.assertEqual("x", compiler.compiler_name) self.assertEqual("foo", compiler.flags) self.assertEqual(["fish"], compiler.path_lists[0]) self.assertEqual(["wibble"], compiler.path_lists[3])
def setUpClass(cls): cls.tmpdir = tempfile.TemporaryDirectory(prefix="fract4d_") import sys if sys.platform[:6] == "darwin": cls.userConfig = fractconfig.DarwinConfig("") else: cls.userConfig = fractconfig.T("") cls.userConfig.set("general", "cache_dir", os.path.join(cls.tmpdir.name, "gnofract4d-cache")) cls.userConfig["formula_path"].clear() cls.userConfig["map_path"].clear() cls.g_comp = fc.Compiler(cls.userConfig) cls.g_comp.add_func_path("formulas") cls.g_comp.add_func_path("testdata/formulas")
def testFileTimeChecking(self): 'Check we notice when a file changes' f2 = fc.Compiler(Test.userConfig) formulas = ''' test_circle { loop: z = pixel bailout: |z| < @bailout default: float param bailout default = 4.0 endparam } test_square { loop: z = pixel bailout: abs(real(z)) > 2.0 || abs(imag(z)) > 2.0 } ''' fftest_file = os.path.join(Test.tmpdir.name, "fttest.frm") with open(fftest_file, "w") as f: f.write(formulas) f2.load_formula_file(fftest_file) frm = f2.get_formula(fftest_file, "test_circle") self.assertEqual(frm.symbols.default_params(), [0, 4.0]) formulas = formulas.replace('4.0', '6.0') time.sleep(1.0) # ensure filesystem will have a different time with open(fftest_file, "w") as f: f.write(formulas) frm2 = f2.get_formula(fftest_file, "test_circle") self.assertEqual(frm2.symbols.default_params(), [0, 6.0])
def __init__(self, userConfig): self.userConfig = userConfig self.compiler = fc.Compiler(userConfig) self.f = fractal.T(self.compiler)
def onResponse(self, widget, id): if id == Gtk.ResponseType.CLOSE or \ id == Gtk.ResponseType.NONE or \ id == Gtk.ResponseType.DELETE_EVENT: self.hide() elif id == DirectorDialog.RESPONSE_RENDER: self.animation.set_avi_file(self.txt_temp_avi.get_text()) try: self.generate(self.converterpath is not None) except (SanityCheckError, UserCancelledError): # prevent dialog closing if being run GObject.signal_stop_emission_by_name(self, "response") else: self.hide() def main(self): Gtk.main() if __name__ == "__main__": GObject.threads_init() Gtk.threads_init() main_window = Gtk.Window() userConfig = fractconfig.userConfig() compiler = fc.Compiler(userConfig) f = fractal.T(compiler) fracwin = DirectorDialog(main_window, f, userConfig) fracwin.main()
def __init__(self, userConfig, extra_paths=[]): self.quit_when_done = False self.save_filename = None self.compress_saves = True self.f = None self.use_preview = True self.normal_display_size = None self.normal_window_size = None self.userConfig = userConfig self.userPrefs = preferences.Preferences(userConfig) self.four_d_sensitives = [] # window widget self.window = Gtk.Window() self.window.set_default_size( self.userPrefs.getint("main_window", "width"), self.userPrefs.getint("main_window", "height")) self.window.connect('delete-event', self.quit) self.window.connect('window-state-event', self.on_window_state_event) self.window.set_name('main_window') theme_provider = Gtk.CssProvider() css_file = "gnofract4d.css" this_path = os.path.dirname(sys.modules[__name__].__file__) css_filepath = os.path.join(this_path, css_file) theme_provider.load_from_path(css_filepath) Gtk.StyleContext.add_provider_for_screen( Gdk.Screen.get_default(), theme_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) # custom icon images for toolbar buttons Gtk.IconTheme.prepend_search_path( Gtk.IconTheme.get_default(), os.path.dirname( fractconfig.T.find_resource('explorer_mode.png', 'pixmaps'))) # keyboard handling self.keymap = { Gdk.KEY_Left: self.on_key_left, Gdk.KEY_Right: self.on_key_right, Gdk.KEY_Up: self.on_key_up, Gdk.KEY_Down: self.on_key_down, Gdk.KEY_Escape: self.on_key_escape } self.window.connect('key-press-event', self.on_key_press) self.window.connect('key-release-event', self.on_key_release) # create fractal compiler and load standard formula and # coloring algorithm files self.compiler = fc.Compiler(userConfig) for path in extra_paths: self.compiler.add_func_path(path) self.vbox = Gtk.VBox() self.window.add(self.vbox) self.f = gtkfractal.T(self.compiler, self) self.f.freeze( ) # create frozen - main prog queues first_draw() to thaw self.create_subfracts(self.f) self.set_filename(None) try: # try to make default image more interesting self.f.set_cmap(fractconfig.T.find_resource("basic.map", "maps")) except Exception as ex: # print(ex) pass self.model = model.Model(self.f) self.userPrefs.connect('image-preferences-changed', self.on_prefs_changed) self.create_ui() self.create_toolbar() self.panes = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL) self.vbox.add(self.panes) self.create_status_bar() self.create_fractal(self.f) self.panes.pack1(self.swindow, resize=True, shrink=True) # show everything apart from the settings pane self.window.show_all() self.settingsPane = settings.SettingsPane(self, self.f) self.panes.pack2(self.settingsPane, resize=False, shrink=False) # create these properly later to avoid 'end from FAM server connection' # messages self.saveas_fs = None self.saveimage_fs = None self.hires_image_fs = None self.open_fs = None self.renderQueue = renderqueue.T(self.userPrefs) self.update_subfract_visibility(False) self.populate_warpmenu(self.f) self.update_image_prefs(self.userPrefs) self.statuses = [ _("Done"), _("Calculating"), _("Deepening (%d iterations)"), _("Antialiasing"), _("Paused"), _("Reducing Periodicity Tolerance") ] self.f.set_saved(True) self.directorDialog = director.DirectorDialog(self.window, self.f, self.userConfig) self.painterDialog = painter.PainterDialog(self.window, self.f) self.renderqueueDialog = renderqueue.QueueDialog( self.window, self.f, self.renderQueue)
# test cases for parfile.py import string import unittest import io import math import sys if sys.path[1] != "..": sys.path.insert(1, "..") from fract4d_compiler import fc, preprocessor from fract4d import testbase, fractal, fractconfig, gradient from fractutils import parfile g_comp = fc.Compiler(fractconfig.T("")) g_comp.add_func_path("../formulas") g_comp.add_func_path("../fract4d") g_comp.load_formula_file("gf4d.frm") g_comp.load_formula_file("test.frm") g_comp.load_formula_file("gf4d.cfrm") fotd = """FOTD_for_04-05-06 { ; time=2:38:57.82--SF5 on a P200 reset=2004 type=mandel passes=1 center-mag=-0.74999655467724592903865/0.0171269216\\ 3034049041486/5.51789e+018 params=0/0 float=y maxiter=72000 inside=0 periodicity=10 colors=0000qJ0mP0iX0eb0di0`o0Xu0Tz2Pz2NzRTzoZqzbRz\\ dTzdTzeTzeTzeTzgVzgVzgVziVziVzkXzkXzkXzmXzmXzmXzgV\\ zdTu`RkXP`TNRNNGJL6GJ0CH08K04U0GcAWdPdkehvpmuxrzzx\\ zzzuzzqzzmzzizzezzbzzZzzVzzTzzRzzRxzPozPexNZvNPsLG\\
col = [ int(x_y[0] * nratio + x_y[1] * ratio) for x_y in pairs ] colors.append(col) colors.append(rgb) i += 3 runlength = 0 return colors if __name__ == "__main__": import sys from fract4d import fractal from fract4d_compiler import fc g_comp = fc.Compiler(fractconfig.userConfig()) g_comp.add_func_path("../formulas") g_comp.add_func_path("../testdata/formulas") g_comp.load_formula_file("gf4d.frm") g_comp.load_formula_file("test.frm") g_comp.load_formula_file("gf4d.cfrm") f = fractal.T(g_comp) file = open(sys.argv[1]) parse(file, f) f.save(open("parfile.fct", "w"))
def do_startup(self): Gtk.Application.do_startup(self) self.userPrefs = preferences.Preferences(self.userConfig) self.compiler = fc.Compiler(self.userConfig) for path in self.options.extra_paths: self.compiler.add_func_path(path)
def testInstance(self): compiler = fc.Compiler(Test.userConfig) self.assertNotEqual(None, compiler) self.assertEqual(compiler.flags, Test.userConfig.get("compiler", "options"))