Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request fract4d#24 from cjmayo/objects
Browse files Browse the repository at this point in the history
Dialog Objects
  • Loading branch information
edyoung committed Feb 26, 2018
2 parents ab46178 + da6cb7c commit 2d6d2d6
Show file tree
Hide file tree
Showing 25 changed files with 306 additions and 436 deletions.
6 changes: 2 additions & 4 deletions fract4d/browser_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ def __init__(self,compiler):
TypeInfo(self, compiler, fc.FormulaTypes.TRANSFORM),
TypeInfo(self, compiler, fc.FormulaTypes.GRADIENT)
]
self.current = None
self.current_type = -1
self.type_changed = event.T()
self.file_changed = event.T()
self.formula_changed = event.T()
self.set_type(FRACTAL)


def formula_type_to_browser_type(self,t):
if t == fc.FormulaTypes.FRACTAL:
return FRACTAL
Expand Down Expand Up @@ -157,5 +157,3 @@ def get_contents(self):

r = self.compiler.get_text(fname)
return r

instance = T(fc.instance)
1 change: 0 additions & 1 deletion fract4d/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def save(self):
self.createPickledFile(self._indexName(), self.files)

def clear(self):
if not os: return # get 'NoneType not callable' sometimes otherwise, which seems weird
for f in os.listdir(self.dir):
try:
os.remove(os.path.join(self.dir,f))
Expand Down
3 changes: 0 additions & 3 deletions fract4d/fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,6 @@ def __del__(self):
if not self.leave_dirty:
self.clear_cache()

instance = Compiler()
instance.update_from_prefs(fractconfig.instance)

def usage():
print("FC : a compiler from Fractint .frm files to C code")
print("fc.py -o [outfile] -f [formula] infile")
Expand Down
21 changes: 15 additions & 6 deletions fract4d/test_browser_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,21 @@ def testFuncMapping(self):

def testSetType(self):
bm = Wrapper()
self.assertEqual([], bm.type_changelist)
bm.set_type(browser_model.FRACTAL)
self.assertEqual([browser_model.FRACTAL], bm.type_changelist)
self.assertEqual(browser_model.FRACTAL, bm.current_type)
self.assertEqual(
bm.typeinfo[bm.current_type], bm.current)

bm.set_type(browser_model.INNER)
self.assertEqual(browser_model.INNER, bm.current_type)
self.assertEqual(
[browser_model.INNER],
[browser_model.FRACTAL, browser_model.INNER],
bm.type_changelist)

def testFileList(self):
bm = browser_model.T(g_comp)
bm.set_type(browser_model.FRACTAL)
self.assertNotEqual(bm.current.files, [])
self.assertListSorted(bm.current.files)

Expand All @@ -91,6 +93,7 @@ def testSetTypeTwice(self):

def testSetTypeUpdatesFnames(self):
bm = browser_model.T(g_comp)
bm.set_type(browser_model.FRACTAL)

bm.current.fname = "fish"
bm.current.formula = "haddock"
Expand All @@ -107,6 +110,7 @@ def testSetTypeUpdatesFnames(self):

def testSetFile(self):
bm = Wrapper()
bm.set_type(browser_model.FRACTAL)
bm.set_file("gf4d.frm")
self.assertEqual("gf4d.frm",bm.current.fname)
self.assertEqual(
Expand All @@ -116,6 +120,7 @@ def testSetFile(self):

def testSetBadFile(self):
bm = browser_model.T(g_comp)
bm.set_type(browser_model.FRACTAL)
self.assertRaises(IOError,bm.set_file,"nonexistent.frm")

def assertListSorted(self,l):
Expand All @@ -126,6 +131,7 @@ def assertListSorted(self,l):

def testFormulasSorted(self):
bm = browser_model.T(g_comp)
bm.set_type(browser_model.FRACTAL)
bm.set_file("gf4d.frm")
self.assertListSorted(bm.current.formulas)

Expand All @@ -141,6 +147,7 @@ def testExcludeList(self):

def testSetFormula(self):
bm = Wrapper()
bm.set_type(browser_model.FRACTAL)
bm.set_file("gf4d.frm")
bm.set_formula("Mandelbrot")
self.assertEqual("Mandelbrot",bm.current.formula)
Expand All @@ -149,6 +156,7 @@ def testSetFormula(self):

def testSetFileResetsFormula(self):
bm = Wrapper()
bm.set_type(browser_model.FRACTAL)
bm.set_file("gf4d.frm")
bm.set_formula("Mandelbrot")
bm.set_file("fractint-g4.frm")
Expand All @@ -158,7 +166,9 @@ def testSetFileResetsFormula(self):

def testUpdate(self):
bm = Wrapper()
bm.update("gf4d.frm","Mandelbrot")
bm.set_type(browser_model.FRACTAL)
bm.set_file("gf4d.frm")
bm.set_formula("Mandelbrot")
self.assertEqual("gf4d.frm",bm.current.fname)
self.assertEqual("Mandelbrot", bm.current.formula)

Expand All @@ -172,6 +182,7 @@ def testUpdate(self):

def testApplyStatus(self):
bm = browser_model.T(g_comp)
bm.set_type(browser_model.FRACTAL)
self.assertEqual(False, bm.current.can_apply)

bm.set_file("gf4d.frm")
Expand All @@ -198,9 +209,7 @@ def testUgrPresent(self):
files = bm.current.files
self.assertEqual(1,files.count("blatte1.ugr"))

def testInstance(self):
x = browser_model.instance


def suite():
return unittest.makeSuite(Test,'test')

Expand Down
3 changes: 2 additions & 1 deletion fract4d/test_fc.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ def testPrefs(self):
self.assertEqual(["wibble"], compiler.path_lists[3])

def testInstance(self):
compiler = fc.instance
compiler = fc.Compiler()
compiler.update_from_prefs(fractconfig.instance)
self.assertNotEqual(None, compiler)
self.assertEqual(
compiler.flags, fractconfig.instance.get("compiler", "options"))
Expand Down
52 changes: 17 additions & 35 deletions fract4dgui/angle.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# Sort of a widget which controls an angle of the fractal
# I say sort of, because this doesn't actually inherit from Gtk.Widget,
# so it's not really a widget. This is because if I attempt to do that
# pygtk crashes. Hence I delegate to a member which actually is a widget
# with some stuff drawn on it - basically an ungodly hack.
# A widget which controls an angle of the fractal

import math

from gi.repository import Gtk, Gdk, GObject, Pango

class T(GObject.GObject):
class T(Gtk.DrawingArea):
__gsignals__ = {
'value-changed' : (
(GObject.SignalFlags.RUN_FIRST | GObject.SignalFlags.NO_RECURSE),
Expand All @@ -30,34 +26,33 @@ def __init__(self,text):

self.adjustment.connect('value-changed', self.onAdjustmentValueChanged)

GObject.GObject.__init__(self)
Gtk.DrawingArea.__init__(self)

self.widget = Gtk.DrawingArea()
self.widget.set_size_request(40,40)
self.set_size_request(40,40)

self.widget.set_events(
self.set_events(
Gdk.EventMask.BUTTON_RELEASE_MASK |
Gdk.EventMask.BUTTON1_MOTION_MASK |
Gdk.EventMask.POINTER_MOTION_HINT_MASK |
Gdk.EventMask.ENTER_NOTIFY_MASK |
Gdk.EventMask.LEAVE_NOTIFY_MASK |
Gdk.EventMask.LEAVE_NOTIFY_MASK |
Gdk.EventMask.BUTTON_PRESS_MASK |
Gdk.EventMask.EXPOSURE_MASK
)

self.notice_mouse = False
self.widget.connect('motion_notify_event', self.onMotionNotify)
self.widget.connect('button_release_event', self.onButtonRelease)
self.widget.connect('button_press_event', self.onButtonPress)
self.widget.connect('draw',self.onDraw)
self.connect('motion_notify_event', self.onMotionNotify)
self.connect('button_release_event', self.onButtonRelease)
self.connect('button_press_event', self.onButtonPress)
self.connect('draw',self.onDraw)

def set_value(self,val):
val = math.fmod(val + math.pi, 2.0 * math.pi) - math.pi
self.adjustment.set_value(val)
self.widget.queue_draw()
self.queue_draw()

def update_from_mouse(self,x,y):
(w,h) = (self.widget.get_allocated_width(), self.widget.get_allocated_height())
def update_from_mouse(self,x,y):
(w,h) = (self.get_allocated_width(), self.get_allocated_height())

xc = w//2
yc = h//2
Expand All @@ -73,39 +68,29 @@ def angle_from_xy(self,x,y):
def onAdjustmentValueChanged(self,adjustment):
val = adjustment.get_value()
if val != self.old_value:
self.widget.queue_draw()
self.queue_draw()
self.emit('value-slightly-changed', val)

def onMotionNotify(self,widget,event):
if not self.notice_mouse:
return
dummy = widget.get_pointer()
self.update_from_mouse(event.x, event.y)

def onButtonRelease(self,widget,event):
if event.button==1:
if event.button == 1:
self.notice_mouse = False
(xc,yc) = (widget.get_allocated_width()//2, widget.get_allocated_height()//2)
current_value = self.adjustment.get_value()
if self.old_value != current_value:
self.old_value = current_value
self.emit('value-changed',current_value)

self.widget.set_state(Gtk.StateType.NORMAL)
self.set_state(Gtk.StateType.NORMAL)


def onButtonPress(self,widget,event):
if event.button == 1:
self.notice_mouse = True
self.update_from_mouse(event.x, event.y)
self.widget.set_state(Gtk.StateType.ACTIVE)


def __del__(self):
#This is truly weird. If I don't have this method, when you use
# one fourway widget, it fucks up the other. Having this fixes it.
# *even though it doesn't do anything*. Disturbing.
pass
self.set_state(Gtk.StateType.ACTIVE)

def get_current_angle(self):
value = self.adjustment.get_value()
Expand Down Expand Up @@ -164,6 +149,3 @@ def redraw_rect(self, widget, cairo_ctx):
self.two_pi)
cairo_ctx.fill()
cairo_ctx.stroke()

# explain our existence to GTK's object system
GObject.type_register(T)
13 changes: 3 additions & 10 deletions fract4dgui/autozoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@

from . import dialog

def show_autozoom(parent,f):
AutozoomDialog.show(parent,f)

class AutozoomDialog(dialog.T):
def __init__(self,main_window,f):
dialog.T.__init__(
self,
_("Autozoom"),
main_window,
(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE),
destroy_with_parent=True
(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
)

self.f = f
Expand Down Expand Up @@ -58,11 +54,8 @@ def change_entry(*args):
self.table.attach(self.minsize_entry,
1,2,1,2,
Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, 0, 2, 2)

def show(parent, f):
dialog.T.reveal(AutozoomDialog, True, parent, None, f)

show = staticmethod(show)

self.vbox.show_all()

def onResponse(self,widget,id):
self.zoombutton.set_active(False)
Expand Down
Loading

0 comments on commit 2d6d2d6

Please sign in to comment.