def gradarea_mousedown(self, widget, event): if self.mousedown == False and event.button == 1: x = event.x / self.grad.num x -= 1 - self.grad.offset if x < 0: x += 1 seg = self.grad.getSegAt(x) relx = x - seg.left.pos if relx < (seg.right.pos - seg.left.pos) / 2: self.grad.cur = self.grad.segments.index(seg) * 2 else: self.grad.cur = self.grad.segments.index(seg) * 2 + 1 hData = self.grad.getDataFromHandle(self.grad.cur) if self.colourbutton == True: self.csel.set_color( utils.create_color(hData.col[0], hData.col[1], hData.col[2])) else: self.csel_dialog.colorsel.set_current_color( utils.create_color(hData.col[0], hData.col[1], hData.col[2])) self.pos.set_value(hData.pos) self.gradarea.queue_draw() if event.button == 1: self.mousedown = True self.origmpos = self.startmpos = event.x elif event.button == 3: self.mousepos = event.x #We can't pass this as callback data, because things're screwed. If this isn't true, please tell! #self.item_factory.popup(int(event.x), int(event.y), event.button) self.menu.popup(None, None, None, event.button, event.time) return False
def gradarea_mousedown(self, widget, event): if self.mousedown == False and event.button == 1: x=event.x/self.grad.num x-=1-self.grad.offset if x < 0: x+=1 seg = self.grad.getSegAt(x) relx = x - seg.left.pos if relx < (seg.right.pos-seg.left.pos)/2: self.grad.cur=self.grad.segments.index(seg)*2 else: self.grad.cur=self.grad.segments.index(seg)*2+1 hData = self.grad.getDataFromHandle(self.grad.cur) if self.colourbutton == True: self.csel.set_color( utils.create_color(hData.col[0],hData.col[1],hData.col[2])) else: self.csel_dialog.colorsel.set_current_color( utils.create_color(hData.col[0],hData.col[1],hData.col[2])) self.pos.set_value(hData.pos) self.gradarea.queue_draw() if event.button == 1: self.mousedown = True self.origmpos = self.startmpos = event.x elif event.button == 3: self.mousepos = event.x #We can't pass this as callback data, because things're screwed. If this isn't true, please tell! #self.item_factory.popup(int(event.x), int(event.y), event.button) self.menu.popup(None, None, None, event.button, event.time) return False
def testCreateColor(self): cyan = utils.create_color(0.0, 1.0, 1.0) self.assertEqual(cyan.red, 0) self.assertEqual(cyan.green, 65535) self.assertEqual(cyan.blue, 65535)
def testCreateColor(self): cyan = utils.create_color(0.0,1.0,1.0) self.assertEqual(cyan.red,0) self.assertEqual(cyan.green,65535) self.assertEqual(cyan.blue,65535)
def create_gradient_dialog(self): hData = self.grad.getDataFromHandle(self.grad.cur) HSVCo = gradient.RGBtoHSV(hData.col) ###GRADIENT PREVIEW### self.gradarea = gtk.DrawingArea() self.gradarea.set_size_request(256, 64) self.gradarea.connect('realize', self.gradarea_realized) self.gradarea.connect('expose_event', self.gradarea_expose) self.gradarea.add_events(gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.POINTER_MOTION_MASK) self.gradarea.connect('button-press-event', self.gradarea_mousedown) self.gradarea.connect('button-release-event', self.gradarea_clicked) self.gradarea.connect('motion-notify-event', self.gradarea_mousemoved) gradareaBox = gtk.HBox(False, 0) ###CONTEXT MENU### menu_items = (("/_Insert", "<control>I", self.add_handle, 0), ("/_Delete", "<control>D", self.rem_handle, 0), ("/_Coloring Mode", None, None, 0, "<Branch>"), ("/Coloring Mode/_RGB", "<control>R", self.cmode, 0), ("/Coloring Mode/_HSV", "<control>H", self.cmode, 1), ("/_Blending Mode", None, None, 0, "<Branch>"), ("/Blending Mode/_Linear", "<control>L", self.bmode, 0), ("/Blending Mode/_Sinusoidal", None, self.bmode, 1), ("/Blending Mode/Curved _Increasing", None, self.bmode, 2), ("/Blending Mode/Curved _Decreasing", None, self.bmode, 3), ("/Debug", None, self.printstuff, 0)) accel_group = gtk.AccelGroup() self.item_factory = gtk.ItemFactory(gtk.Menu, "<gradients>", accel_group) self.item_factory.create_items(menu_items) self.add_accel_group(accel_group) self.menu = self.item_factory.get_widget("<gradients>") ###COLOR SELECTION### if gtk.pygtk_version[0] >= 2 and gtk.pygtk_version[1] >= 4: lblCsel = gtk.Label("Color:") self.csel = gtk.ColorButton( utils.create_color(hData.col[0], hData.col[1], hData.col[2])) self.csel.connect('color-set', self.colorchanged) self.colorbutton = True else: self.csel = gtk.Button("Color...") self.csel.connect('clicked', self.cbutton_clicked) self.csel_dialog = gtk.ColorSelectionDialog("Select a Color") self.csel_dialog.colorsel.set_current_color( utils.create_color(hData.col[0], hData.col[1], hData.col[2])) self.csel_dialog.ok_button.connect('clicked', self.cdialog_response) self.colorbutton = False synccolsB = gtk.Button("Sync Colors") synccolsB.connect('clicked', self.sync_colors) CSelBox = gtk.HBox(False, 0) ###ALTERNATION CONTROL### lblAlternate = gtk.Label(_("Alternation:")) alternate = gtk.SpinButton( gtk.Adjustment(self.grad.getAlt(), 0, .5, 0.01, .5, 0.0)) alternate.set_digits(3) alternate.connect('value-changed', self.alternate_changed) AlternateBox = gtk.HBox(False, 0) ###POSITION CONTROL### lblPos = gtk.Label(_("Position:")) self.pos = gtk.SpinButton( gtk.Adjustment(hData.pos, 0, 1, 0.01, 0.1, 0.0)) self.pos.set_digits(2) self.pos.connect('value-changed', self.pos_changed) PosBox = gtk.HBox(False, 0) ###RANDOMIZE BUTTON### randomize = gtk.Button(_("Randomize")) randomize.connect('clicked', self.randomize) randBox = gtk.HBox(False, 0) ###OFFSET CONTROL### lblOffset = gtk.Label(_("Offset:")) lblOffsetBox = gtk.HBox(False, 0) offset = gtk.HScale( gtk.Adjustment(self.grad.getOffset(), 0, 1, 0.001, 0.01, 0.0)) offset.set_digits(3) offset.connect('value-changed', self.offset_changed) #################### ###WIDGET PACKING### #################### self.vbox.set_homogeneous(0) gradareaBox.pack_start(self.gradarea, 1, 0, 10) self.vbox.pack_start(gradareaBox, 0, 0, 5) if self.colorbutton: CSelBox.pack_start(lblCsel, 0, 0, 10) CSelBox.pack_start(self.csel, 0, 0, 10) CSelBox.pack_end(synccolsB, 0, 0, 10) self.vbox.pack_start(CSelBox, 0, 0, 5) PosBox.pack_start(lblPos, 0, 0, 10) PosBox.pack_start(self.pos, 0, 0, 10) self.vbox.pack_start(PosBox, 0, 0, 5) AlternateBox.pack_start(lblAlternate, 0, 0, 10) AlternateBox.pack_start(alternate, 0, 0, 10) self.vbox.pack_start(AlternateBox, 0, 0, 5) lblOffsetBox.pack_start(lblOffset, 0, 0, 5) self.vbox.pack_start(lblOffsetBox, 0, 0, 5) self.vbox.pack_start(offset, 0, 0, 5) randBox.pack_start(randomize, 1, 0, 10) self.vbox.pack_start(randBox, 0, 0, 5)
def create_gradient_dialog(self): hData = self.grad.getDataFromHandle(self.grad.cur) HSVCo = gradient.RGBtoHSV(hData.col) ###GRADIENT PREVIEW### self.gradarea=gtk.DrawingArea() self.gradarea.set_size_request(256, 64) self.gradarea.connect('realize', self.gradarea_realized) self.gradarea.connect('expose_event', self.gradarea_expose) self.gradarea.add_events( gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.POINTER_MOTION_MASK) self.gradarea.connect('button-press-event', self.gradarea_mousedown) self.gradarea.connect('button-release-event', self.gradarea_clicked) self.gradarea.connect('motion-notify-event', self.gradarea_mousemoved) gradareaBox = gtk.HBox(False, 0) ###CONTEXT MENU### menu_items = ( ( "/_Insert", "<control>I", self.add_handle, 0 ), ( "/_Delete", "<control>D", self.rem_handle, 0 ), ( "/_Coloring Mode", None, None, 0, "<Branch>" ), ( "/Coloring Mode/_RGB", "<control>R", self.cmode, 0 ), ( "/Coloring Mode/_HSV", "<control>H", self.cmode, 1 ), ( "/_Blending Mode", None, None, 0, "<Branch>" ), ( "/Blending Mode/_Linear", "<control>L", self.bmode, 0 ), ( "/Blending Mode/_Sinusoidal", None, self.bmode, 1 ), ( "/Blending Mode/Curved _Increasing",None, self.bmode, 2 ), ( "/Blending Mode/Curved _Decreasing",None, self.bmode, 3 ), ( "/Debug", None, self.printstuff, 0 ) ) accel_group = gtk.AccelGroup() self.item_factory= gtk.ItemFactory(gtk.Menu, "<gradients>", accel_group) self.item_factory.create_items(menu_items) self.add_accel_group(accel_group) self.menu=self.item_factory.get_widget("<gradients>") ###COLOR SELECTION### if gtk.pygtk_version[0] >= 2 and gtk.pygtk_version[1] >= 4: lblCsel = gtk.Label("Color:") self.csel = gtk.ColorButton( utils.create_color(hData.col[0], hData.col[1], hData.col[2])) self.csel.connect('color-set', self.colorchanged) self.colorbutton = True else: self.csel = gtk.Button("Color...") self.csel.connect('clicked', self.cbutton_clicked) self.csel_dialog = gtk.ColorSelectionDialog("Select a Color") self.csel_dialog.colorsel.set_current_color( utils.create_color(hData.col[0], hData.col[1], hData.col[2])) self.csel_dialog.ok_button.connect('clicked', self.cdialog_response) self.colorbutton = False synccolsB = gtk.Button("Sync Colors") synccolsB.connect('clicked', self.sync_colors) CSelBox = gtk.HBox(False, 0) ###ALTERNATION CONTROL### lblAlternate = gtk.Label(_("Alternation:")) alternate = gtk.SpinButton(gtk.Adjustment(self.grad.getAlt(), 0, .5, 0.01, .5, 0.0)) alternate.set_digits(3) alternate.connect('value-changed', self.alternate_changed) AlternateBox = gtk.HBox(False, 0) ###POSITION CONTROL### lblPos = gtk.Label(_("Position:")) self.pos = gtk.SpinButton(gtk.Adjustment(hData.pos, 0, 1, 0.01, 0.1, 0.0)) self.pos.set_digits(2) self.pos.connect('value-changed', self.pos_changed) PosBox = gtk.HBox(False, 0) ###RANDOMIZE BUTTON### randomize = gtk.Button(_("Randomize")) randomize.connect('clicked', self.randomize) randBox = gtk.HBox(False, 0) ###OFFSET CONTROL### lblOffset = gtk.Label(_("Offset:")) lblOffsetBox = gtk.HBox(False, 0) offset=gtk.HScale(gtk.Adjustment(self.grad.getOffset(), 0, 1, 0.001, 0.01, 0.0)) offset.set_digits(3) offset.connect('value-changed', self.offset_changed) #################### ###WIDGET PACKING### #################### self.vbox.set_homogeneous(0) gradareaBox.pack_start(self.gradarea, 1, 0, 10) self.vbox.pack_start(gradareaBox, 0, 0, 5) if self.colorbutton: CSelBox.pack_start(lblCsel, 0, 0, 10) CSelBox.pack_start(self.csel, 0, 0, 10) CSelBox.pack_end(synccolsB, 0, 0, 10) self.vbox.pack_start(CSelBox, 0, 0, 5) PosBox.pack_start(lblPos, 0, 0, 10) PosBox.pack_start(self.pos, 0, 0, 10) self.vbox.pack_start(PosBox, 0, 0, 5) AlternateBox.pack_start(lblAlternate, 0, 0, 10) AlternateBox.pack_start(alternate, 0, 0, 10) self.vbox.pack_start(AlternateBox, 0, 0, 5) lblOffsetBox.pack_start(lblOffset, 0, 0, 5) self.vbox.pack_start(lblOffsetBox, 0, 0, 5) self.vbox.pack_start(offset, 0, 0, 5) randBox.pack_start(randomize, 1, 0, 10) self.vbox.pack_start(randBox, 0, 0, 5)